Skip to content

Commit 9216f5b

Browse files
committed
Merge branch 'PHP-7.3'
* PHP-7.3: Fix #77291: magic methods inherited from a trait may be ignored
2 parents 82af24f + 0061db5 commit 9216f5b

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

Zend/tests/bug77291.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #77291 (magic methods inherited from a trait may be ignored)
3+
--FILE--
4+
<?php
5+
6+
trait AccessibleProperties
7+
{
8+
public function __isset($property)
9+
{
10+
return property_exists($this, $property);
11+
}
12+
13+
public function __get($property)
14+
{
15+
if (property_exists($this, $property)) {
16+
return $this->$property;
17+
}
18+
}
19+
}
20+
21+
class Foo4567 {
22+
use AccessibleProperties;
23+
24+
protected $a = 'Some value';
25+
}
26+
27+
class Foo45 {
28+
use AccessibleProperties;
29+
30+
protected $a = 'Some value';
31+
}
32+
33+
$foo = new Foo4567;
34+
var_dump(isset($foo->a));
35+
$foo = new Foo45;
36+
var_dump($foo->a);
37+
?>
38+
===DONE===
39+
--EXPECT--
40+
bool(true)
41+
string(10) "Some value"
42+
===DONE===

Zend/zend_inheritance.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,17 +1178,7 @@ static void zend_do_implement_interfaces(zend_class_entry *ce) /* {{{ */
11781178

11791179
static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zend_function* fe) /* {{{ */
11801180
{
1181-
if (ZSTR_LEN(ce->name) == ZSTR_LEN(mname)) {
1182-
zend_string *lowercase_name = zend_string_tolower(ce->name);
1183-
lowercase_name = zend_new_interned_string(lowercase_name);
1184-
if (!memcmp(ZSTR_VAL(mname), ZSTR_VAL(lowercase_name), ZSTR_LEN(mname))) {
1185-
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
1186-
zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ZSTR_VAL(ce->name));
1187-
}
1188-
ce->constructor = fe;
1189-
}
1190-
zend_string_release_ex(lowercase_name, 0);
1191-
} else if (ZSTR_VAL(mname)[0] != '_' || ZSTR_VAL(mname)[1] != '_') {
1181+
if (ZSTR_LEN(ce->name) != ZSTR_LEN(mname) && (ZSTR_VAL(mname)[0] != '_' || ZSTR_VAL(mname)[1] != '_')) {
11921182
/* pass */
11931183
} else if (zend_string_equals_literal(mname, ZEND_CLONE_FUNC_NAME)) {
11941184
ce->clone = fe;
@@ -1219,6 +1209,16 @@ static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zen
12191209
ce->__tostring = fe;
12201210
} else if (zend_string_equals_literal(mname, ZEND_DEBUGINFO_FUNC_NAME)) {
12211211
ce->__debugInfo = fe;
1212+
} else if (ZSTR_LEN(ce->name) == ZSTR_LEN(mname)) {
1213+
zend_string *lowercase_name = zend_string_tolower(ce->name);
1214+
lowercase_name = zend_new_interned_string(lowercase_name);
1215+
if (!memcmp(ZSTR_VAL(mname), ZSTR_VAL(lowercase_name), ZSTR_LEN(mname))) {
1216+
if (ce->constructor && (!ce->parent || ce->constructor != ce->parent->constructor)) {
1217+
zend_error_noreturn(E_COMPILE_ERROR, "%s has colliding constructor definitions coming from traits", ZSTR_VAL(ce->name));
1218+
}
1219+
ce->constructor = fe;
1220+
}
1221+
zend_string_release_ex(lowercase_name, 0);
12221222
}
12231223
}
12241224
/* }}} */

0 commit comments

Comments
 (0)