Skip to content

Commit 654c8ae

Browse files
committed
Fixed bug #71275 (Bad method called on cloning an object having a trait)
1 parent d4da32d commit 654c8ae

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
ob_start). (hugh at allthethings dot co dot nz)
88
. Fixed bug #71201 (round() segfault on 64-bit builds). (Anatol)
99
. Added support for new HTTP 451 code. (Julien)
10+
. Fixed Bug #71275 (Bad method called on cloning an object having a trait).
11+
(Bob)
1012

1113
- CURL:
1214
. Fixed bug #71225 (curl_setopt() fails to set CURLOPT_POSTFIELDS with

Zend/tests/bug71275.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #71275 (Bad method called on cloning an object having a trait)
3+
--FILE--
4+
<?php
5+
6+
trait MyTrait {
7+
public function _() {
8+
throw new RuntimeException('Should not be called');
9+
}
10+
}
11+
12+
13+
class MyClass {
14+
use MyTrait;
15+
16+
public function __clone() {
17+
echo "I'm working hard to clone";
18+
}
19+
}
20+
21+
22+
$instance = new MyClass();
23+
clone $instance;
24+
25+
?>
26+
--EXPECT--
27+
I'm working hard to clone

Zend/zend_inheritance.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,34 +1026,34 @@ static zend_bool zend_traits_method_compatibility_check(zend_function *fn, zend_
10261026

10271027
static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zend_function* fe) /* {{{ */
10281028
{
1029-
if (!strncmp(ZSTR_VAL(mname), ZEND_CLONE_FUNC_NAME, ZSTR_LEN(mname))) {
1029+
if (zend_string_equals_literal(mname, ZEND_CLONE_FUNC_NAME)) {
10301030
ce->clone = fe; fe->common.fn_flags |= ZEND_ACC_CLONE;
1031-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_CONSTRUCTOR_FUNC_NAME, ZSTR_LEN(mname))) {
1031+
} else if (zend_string_equals_literal(mname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
10321032
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
10331033
zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ZSTR_VAL(ce->name));
10341034
}
10351035
ce->constructor = fe; fe->common.fn_flags |= ZEND_ACC_CTOR;
1036-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_DESTRUCTOR_FUNC_NAME, ZSTR_LEN(mname))) {
1036+
} else if (zend_string_equals_literal(mname, ZEND_DESTRUCTOR_FUNC_NAME)) {
10371037
ce->destructor = fe; fe->common.fn_flags |= ZEND_ACC_DTOR;
1038-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_GET_FUNC_NAME, ZSTR_LEN(mname))) {
1038+
} else if (zend_string_equals_literal(mname, ZEND_GET_FUNC_NAME)) {
10391039
ce->__get = fe;
10401040
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
1041-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_SET_FUNC_NAME, ZSTR_LEN(mname))) {
1041+
} else if (zend_string_equals_literal(mname, ZEND_SET_FUNC_NAME)) {
10421042
ce->__set = fe;
10431043
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
1044-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_CALL_FUNC_NAME, ZSTR_LEN(mname))) {
1044+
} else if (zend_string_equals_literal(mname, ZEND_CALL_FUNC_NAME)) {
10451045
ce->__call = fe;
1046-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_UNSET_FUNC_NAME, ZSTR_LEN(mname))) {
1046+
} else if (zend_string_equals_literal(mname, ZEND_UNSET_FUNC_NAME)) {
10471047
ce->__unset = fe;
10481048
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
1049-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_ISSET_FUNC_NAME, ZSTR_LEN(mname))) {
1049+
} else if (zend_string_equals_literal(mname, ZEND_ISSET_FUNC_NAME)) {
10501050
ce->__isset = fe;
10511051
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
1052-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_CALLSTATIC_FUNC_NAME, ZSTR_LEN(mname))) {
1052+
} else if (zend_string_equals_literal(mname, ZEND_CALLSTATIC_FUNC_NAME)) {
10531053
ce->__callstatic = fe;
1054-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_TOSTRING_FUNC_NAME, ZSTR_LEN(mname))) {
1054+
} else if (zend_string_equals_literal(mname, ZEND_TOSTRING_FUNC_NAME)) {
10551055
ce->__tostring = fe;
1056-
} else if (!strncmp(ZSTR_VAL(mname), ZEND_DEBUGINFO_FUNC_NAME, ZSTR_LEN(mname))) {
1056+
} else if (zend_string_equals_literal(mname, ZEND_DEBUGINFO_FUNC_NAME)) {
10571057
ce->__debugInfo = fe;
10581058
} else if (ZSTR_LEN(ce->name) == ZSTR_LEN(mname)) {
10591059
zend_string *lowercase_name = zend_string_tolower(ce->name);

0 commit comments

Comments
 (0)