-
Notifications
You must be signed in to change notification settings - Fork 7.9k
uri: Throw when trying to modify URI objects after creation #19768
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
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.
Classic reinitialization problem that pops up every now and then.
The "uri" property does not actually exist, i.e. the error message leads users to believe there is such a property. They may try accessing it. Even if it were private and a user tries accessing it a user would get Cannot access private property
. However, they'd get a different error which seems inconsistent to me.
I believe a little bit of a leaky abstraction is fine in this case, since this is only triggerable by specially crafted code that a regular user won't come across. |
For other extensions I've seen a wording used something along the lines of "cannot call constructor twice" or "cannot reconstruct object". |
That would not really be applicable to the Exception during unserialization, though. Treating the internal URI as a “super private property” sounds least confusing to me. But let's see what Mate thinks. |
Well, I find the "super private property" confusing ;) I still prefer a (simple) custom exception messag. |
ext/uri/tests/065.phpt
Outdated
|
||
?> | ||
--EXPECTF-- | ||
Error: Cannot modify readonly property Uri\WhatWg\Url::$uri |
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.
FWIW I agree with the change, but I'd also prefer to somehow eliminate the property term from URIs (even the existing ones). People would rightfully scratch their head if they were trying to find these properties.
This will also fix a memory leak, since the constructor did not free any pre-existing `->uri`.
268ae6f
to
2168b54
Compare
I've adjusted the message to:
The URI classes are actual |
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.
I'm fine with the message
This will also fix a memory leak, since the constructor did not free any pre-existing
->uri
.