summaryrefslogtreecommitdiff
path: root/Zend/zend_inheritance.c
diff options
context:
space:
mode:
authorAndrea Faulds <ajf@ajf.me>2015-03-31 16:10:22 +0200
committerNikita Popov <nikic@php.net>2015-03-31 17:55:27 +0200
commitdb76b708cf14ed2794d26600c0e49df8aa36fbea (patch)
tree043fe016f4319fea36c3208af06c227ceb7bb459 /Zend/zend_inheritance.c
parentd252c9f8324a1fac35aac01b7de7cc800ea76865 (diff)
downloadphp-git-db76b708cf14ed2794d26600c0e49df8aa36fbea.tar.gz
Deprecate PHP 4 constructors
Diffstat (limited to 'Zend/zend_inheritance.c')
-rw-r--r--Zend/zend_inheritance.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 3e9083c8a4..fd40c8ed84 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -23,6 +23,7 @@
#include "zend_execute.h"
#include "zend_inheritance.h"
#include "zend_smart_str.h"
+#include "zend_inheritance.h"
static void ptr_dtor(zval *zv) /* {{{ */
{
@@ -1596,6 +1597,9 @@ ZEND_API void zend_do_bind_traits(zend_class_entry *ce) /* {{{ */
/* verify that all abstract methods from traits have been implemented */
zend_verify_abstract_class(ce);
+ /* Emit E_DEPRECATED for PHP 4 constructors */
+ zend_check_deprecated_constructor(ce);
+
/* now everything should be fine and an added ZEND_ACC_IMPLICIT_ABSTRACT_CLASS should be removed */
if (ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) {
ce->ce_flags -= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
@@ -1603,6 +1607,29 @@ ZEND_API void zend_do_bind_traits(zend_class_entry *ce) /* {{{ */
}
/* }}} */
+
+static zend_bool zend_has_deprecated_constructor(const zend_class_entry *ce) /* {{{ */
+{
+ const zend_string *constructor_name;
+ if (!ce->constructor) {
+ return 0;
+ }
+ constructor_name = ce->constructor->common.function_name;
+ return !zend_binary_strcasecmp(
+ ce->name->val, ce->name->len,
+ constructor_name->val, constructor_name->len
+ );
+}
+/* }}} */
+
+void zend_check_deprecated_constructor(const zend_class_entry *ce) /* {{{ */
+{
+ if (zend_has_deprecated_constructor(ce)) {
+ zend_error(E_DEPRECATED, "Methods with the same name as their class will not be constructors in a future version of PHP; %s has a deprecated constructor", ce->name->val);
+ }
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4