You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?phpclass A {
publicfunction__construct(
readonly string $a
) {
var_dump('A: ' . $this->a);
}
}
class B {
publicfunction__construct(
publicreadonlystring$a
) {
var_dump('B: ' . $this->a);
}
}
Result:
php index.php
PHP Warning: Undefined property: A::$a in /…/test-bypassfinals/include.php on line 7
Warning: Undefined property: A::$a in /…/test-bypassfinals/include.php on line 7
string(3) "A: "
string(4) "B: B"
The problem stems from the fact that readonly is just removed from the code thus changing the promoted property to a simple constructor argument and thus changing behavior.
Context: We use a third-party library that does uses this kind of code.
I am unsure whether this package can really fix this issue because at the moment, a "simple" replace logic without considering the context is used. Here, the context of being a promoted property would have to be known and readonly replaced with public.
The text was updated successfully, but these errors were encountered:
Resolving this issue is not easy because the parser must now distinguish when readonly is used with a class, when with a property with visibility, and when with a property without it. I will probably stick with the fact that it will be incompatible with code written this way.
Reproduction example:
composer require dg/bypass-finals --dev
index.php
:include.php
:Result:
The problem stems from the fact that
readonly
is just removed from the code thus changing the promoted property to a simple constructor argument and thus changing behavior.Context: We use a third-party library that does uses this kind of code.
I am unsure whether this package can really fix this issue because at the moment, a "simple" replace logic without considering the context is used. Here, the context of being a promoted property would have to be known and
readonly
replaced withpublic
.The text was updated successfully, but these errors were encountered: