]> granicus.if.org Git - php/commitdiff
Fixed bug #71275 (Bad method called on cloning an object having a trait)
authorBob Weinand <bobwei9@hotmail.com>
Tue, 5 Jan 2016 15:27:18 +0000 (16:27 +0100)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 5 Jan 2016 15:27:24 +0000 (16:27 +0100)
NEWS
Zend/tests/bug71275.phpt [new file with mode: 0644]
Zend/zend_inheritance.c

diff --git a/NEWS b/NEWS
index cc43981a5027e326b7d517855a5826e8bae67595..9ab53baf858c7e9bf906d240b49d037e2e0ef09c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
     ob_start). (hugh at allthethings dot co dot nz)
   . Fixed bug #71201 (round() segfault on 64-bit builds). (Anatol)
   . Added support for new HTTP 451 code. (Julien)
+  . Fixed Bug #71275 (Bad method called on cloning an object having a trait).
+    (Bob)
 
 - CURL:
   . Fixed bug #71225 (curl_setopt() fails to set CURLOPT_POSTFIELDS with
diff --git a/Zend/tests/bug71275.phpt b/Zend/tests/bug71275.phpt
new file mode 100644 (file)
index 0000000..5244373
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Bug #71275 (Bad method called on cloning an object having a trait)
+--FILE--
+<?php
+
+trait MyTrait {
+       public function _() {
+               throw new RuntimeException('Should not be called');
+       }
+}
+
+
+class MyClass {
+       use MyTrait;
+
+       public function __clone() {
+               echo "I'm working hard to clone";
+       }
+}
+
+
+$instance = new MyClass();
+clone $instance;
+
+?>
+--EXPECT--
+I'm working hard to clone
index 69473b75158d29ea686329e8c4f01aac75412dba..ac98627b10ba652572bd5d2950f4d839ed43d8e2 100644 (file)
@@ -1026,34 +1026,34 @@ static zend_bool zend_traits_method_compatibility_check(zend_function *fn, zend_
 
 static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zend_function* fe) /* {{{ */
 {
-       if (!strncmp(ZSTR_VAL(mname), ZEND_CLONE_FUNC_NAME, ZSTR_LEN(mname))) {
+       if (zend_string_equals_literal(mname, ZEND_CLONE_FUNC_NAME)) {
                ce->clone = fe; fe->common.fn_flags |= ZEND_ACC_CLONE;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_CONSTRUCTOR_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
                if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
                        zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ZSTR_VAL(ce->name));
                }
                ce->constructor = fe; fe->common.fn_flags |= ZEND_ACC_CTOR;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_DESTRUCTOR_FUNC_NAME,  ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_DESTRUCTOR_FUNC_NAME)) {
                ce->destructor = fe; fe->common.fn_flags |= ZEND_ACC_DTOR;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_GET_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_GET_FUNC_NAME)) {
                ce->__get = fe;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_SET_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_SET_FUNC_NAME)) {
                ce->__set = fe;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_CALL_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_CALL_FUNC_NAME)) {
                ce->__call = fe;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_UNSET_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_UNSET_FUNC_NAME)) {
                ce->__unset = fe;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_ISSET_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_ISSET_FUNC_NAME)) {
                ce->__isset = fe;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_CALLSTATIC_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_CALLSTATIC_FUNC_NAME)) {
                ce->__callstatic = fe;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_TOSTRING_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_TOSTRING_FUNC_NAME)) {
                ce->__tostring = fe;
-       } else if (!strncmp(ZSTR_VAL(mname), ZEND_DEBUGINFO_FUNC_NAME, ZSTR_LEN(mname))) {
+       } else if (zend_string_equals_literal(mname, ZEND_DEBUGINFO_FUNC_NAME)) {
                ce->__debugInfo = fe;
        } else if (ZSTR_LEN(ce->name) == ZSTR_LEN(mname)) {
                zend_string *lowercase_name = zend_string_tolower(ce->name);