forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The following code poses a problem in the JIT: ```php class A { public $prop = 1; } class B extends A { public $prop = 1 { get => parent::$prop::get() * 2; } } function test(A $a) { var_dump($a->prop); } test(new B); ``` The JIT would assume A::$prop in test() could be accessed directly through OBJ_PROP_NUM(). However, since child classes can add new hooks to existing properties, this assumption no longer holds. To avoid introducing more JIT checks, a hooked property that overrides a unhooked property now results in a separate zval slot that is used instead of the parent slot. This causes the JIT to pick the slow path due to an IS_UNDEF value in the parent slot. zend_class_entry.properties_info_table poses a problem in that zend_get_property_info_for_slot() and friends will be called using the child slot, which does not store its property info, since the parent slot already does. In this case, zend_get_property_info_for_slot() now provides a fallback that will iterate all property infos to find the correct one. This also uncovered a bug (see Zend/tests/property_hooks/dump.phpt) where the default value of a parent property would accidentally be inherited by the child property. Fixes phpGH-17376
- Loading branch information
Showing
10 changed files
with
195 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
--TEST-- | ||
GH-17376: Child classes may add hooks to plain properties | ||
--INI-- | ||
# Avoid triggering for main, trigger for test so we get a side-trace for property hooks | ||
opcache.jit_hot_func=2 | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
public $prop = 1; | ||
} | ||
|
||
class B extends A { | ||
public $prop = 1 { | ||
get { | ||
echo __METHOD__, "\n"; | ||
return $this->prop; | ||
} | ||
set { | ||
echo __METHOD__, "\n"; | ||
$this->prop = $value; | ||
} | ||
} | ||
} | ||
|
||
function test(A $a) { | ||
echo "read\n"; | ||
var_dump($a->prop); | ||
echo "write\n"; | ||
$a->prop = 42; | ||
echo "read-write\n"; | ||
$a->prop += 43; | ||
echo "pre-inc\n"; | ||
++$a->prop; | ||
echo "pre-dec\n"; | ||
--$a->prop; | ||
echo "post-inc\n"; | ||
$a->prop++; | ||
echo "post-dec\n"; | ||
$a->prop--; | ||
} | ||
|
||
echo "A\n"; | ||
test(new A); | ||
|
||
echo "\nA\n"; | ||
test(new A); | ||
|
||
echo "\nB\n"; | ||
test(new B); | ||
|
||
echo "\nB\n"; | ||
test(new B); | ||
|
||
?> | ||
--EXPECT-- | ||
A | ||
read | ||
int(1) | ||
write | ||
read-write | ||
pre-inc | ||
pre-dec | ||
post-inc | ||
post-dec | ||
|
||
A | ||
read | ||
int(1) | ||
write | ||
read-write | ||
pre-inc | ||
pre-dec | ||
post-inc | ||
post-dec | ||
|
||
B | ||
read | ||
B::$prop::get | ||
int(1) | ||
write | ||
B::$prop::set | ||
read-write | ||
B::$prop::get | ||
B::$prop::set | ||
pre-inc | ||
B::$prop::get | ||
B::$prop::set | ||
pre-dec | ||
B::$prop::get | ||
B::$prop::set | ||
post-inc | ||
B::$prop::get | ||
B::$prop::set | ||
post-dec | ||
B::$prop::get | ||
B::$prop::set | ||
|
||
B | ||
read | ||
B::$prop::get | ||
int(1) | ||
write | ||
B::$prop::set | ||
read-write | ||
B::$prop::get | ||
B::$prop::set | ||
pre-inc | ||
B::$prop::get | ||
B::$prop::set | ||
pre-dec | ||
B::$prop::get | ||
B::$prop::set | ||
post-inc | ||
B::$prop::get | ||
B::$prop::set | ||
post-dec | ||
B::$prop::get | ||
B::$prop::set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ class P { | |
} | ||
|
||
class C extends P { | ||
public $prop { | ||
public $prop = 42 { | ||
get => parent::$prop::get(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters