-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix #74922 - Try to resolve constants when importing trait properties #2779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| if (UNEXPECTED(Z_TYPE_P(op2) == IS_CONSTANT)) { | ||
| op2 = zend_get_constant_ex(Z_STR_P(op2), ce, ZEND_FETCH_CLASS_SILENT); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use zend_update_constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Thanks for the feedback
|
Edge-case: trait T {
public $x = self::X;
}
trait T2 {
public $x = self::X;
}
class C {
use T, T2;
const X = 42;
}
var_dump((new C)->x);Gives: |
|
@nikic, nice find. I've updated the usage of |
|
Slight extension: <?php
trait T {
public $x = self::X;
}
trait T2 {
public $x = self::X;
}
class C {
use T, T2;
const X = 42;
}
class D {
use T2;
const X = 24;
}
var_dump((new C)->x);
var_dump((new D)->x);This gives 42 42 instead of 42 24. The zend_update_constants_ex shouldn't be performed in-place, but rather on a copy of the zvals. |
|
Updated so that the constant resolution happens on copies. |
|
Merged as 897bdb4 with a few tweaks (using COPY_OR_DUP and adding dtor calls). Thanks! |
Link for bugsnet: https://bugs.php.net/bug.php?id=74922
It fixes the reported issue:
And it also allows for values that are identical to the constant like: