- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Support bypass readonly in PHP 82 #39
Comments
This would also help mocking final readonly classes, because you get the following error when you try to mock it:
|
@dg! I found a library that solves this problem: https://github.com/zoltanka/bypass-readonly . Now you can use it, but in the future I would like to have support in the original library. Will you be able to implement it? |
+1 plz |
The question is, should it remove readonly in the class definition or also for all variables? |
I think it should be done for all properties as well. |
hard question .... do we even need this for all variables? |
One more thing: should readonly removal be enabled by default? I can't think of any reason it might be a problem, as in the case of final. |
YES .... thx |
thx for the quick work ... with the new tag I can mock again |
Oh nice :) Thx @dg! |
@jg-development please try this master, if it works I will tag a new version |
tested and works with master + prophecy BypassFinals::enable();
$deliveryFilter = $this->prophesize(DeliveryFilter::class);
$deliveryFilter->__toString()->willReturn('123123');
$deliveryFilter = $deliveryFilter->reveal();
$queryString = (string) $deliveryFilter; |
@dg One question, for versions like php 8.1, does this also remove readonly from properties? Example in PHP 8.1: final class Person {
public function __construct(
public readonly string $firstName,
public readonly string $lastName,
) {}
} |
Yeah, it removes readonly everywhere in the code. |
@dg Is it possible to configure whether or not I want to use this readonly bypass feature ?? First point is that this broke codes, we have libs that check if the properties are readonly based on reflection, and with this feature that you added, it broke these codes, I understand that this should be configurable or at least have entered as a "Major" . Another reason I see this feature being optional and configurable is that in some cases we want to ensure immutability. And the way it is enabled by default today, it is not possible to have that guarantee. |
Hello everyone, I opened this PR with a suggestion on how to solve this problem. If you can look into it, thank you. [PR] |
In PHP 82, it is now possible to mark classes "readonly". However, tests of such classes give an error: "Class "Password Hasher" is declared "readonly" and cannot be duplicated". I would like this library to be able to fix these errors as well.
Fixtures:
The text was updated successfully, but these errors were encountered: