Fix #74922 - Try to resolve constants when importing trait properties#2779
Closed
pmmaga wants to merge 1 commit intophp:masterfrom
Closed
Fix #74922 - Try to resolve constants when importing trait properties#2779pmmaga wants to merge 1 commit intophp:masterfrom
pmmaga wants to merge 1 commit intophp:masterfrom
Conversation
nikic
reviewed
Sep 27, 2017
| } | ||
| if (UNEXPECTED(Z_TYPE_P(op2) == IS_CONSTANT)) { | ||
| op2 = zend_get_constant_ex(Z_STR_P(op2), ce, ZEND_FETCH_CLASS_SILENT); | ||
| } |
Member
There was a problem hiding this comment.
This should use zend_update_constant.
Contributor
Author
There was a problem hiding this comment.
Changed. Thanks for the feedback
Member
|
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: |
Contributor
Author
|
@nikic, nice find. I've updated the usage of |
Member
|
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. |
Contributor
Author
|
Updated so that the constant resolution happens on copies. |
Member
|
Merged as 897bdb4 with a few tweaks (using COPY_OR_DUP and adding dtor calls). Thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: