Repository navigation
Bug #62328 (implementing __toString and a cast to string fails) - #157
Conversation
https://bugs.php.net/bug.php?id=62328 Added a check to see if the object implements a __toString magic method. This should be called instead of the cast_object method of built-in classes when defined.
|
Maybe one more test case for this :) |
|
@reeze The specific test case used SimpleXmlElement. Is it OK to create a test using this and skip it if the module is disabled? Or should I look for a better example class that handles it's own casting? Edit SplFileInfo looks like a good candidate. |
|
maybe you could find a class from spl classes :) |
|
sorry, I merged this for reviewing, but push to master by accident, anyway, I got a different fix here: 7b307fb thanks . |
|
Hi Laruence. I didn't fully understand the impact of removing the lower block of code. I did the same as you originally, but in the end I left it in simply because I didn't understand what other cases it might cater for. Please consider using |
|
leight, hmm, okey, I think this test can be merged into ext/spl folder too , will do it . thanks |
|
test script merged e51acee thanks |
…ializer feat: call the base class's constructor with `: super(…)`
Problem php#164 made analyze_constructor_initializer stop with unreachable! when no class is in scope. Master returns Ok there. php#157 did not fold an unreachable! into that guard, so this was no restore. The claim that only a method passes an initializer was read, not run, and a wrong unreachable! there would crash a user's whole compile. Solution The function is master's code again. crates/analyzer/src/statement/class_like/method.rs <- analyze_constructor_initializer as on master
Problem: Master gained php#157 (`: super(…)` constructor initializers) and php#159 (structure rules), and a PR must be up to date with master to merge. Solution: Merge master. Two files conflicted only where both sides added imports or a method beside each other, and both are kept. The constructor initializer's static call passes no type arguments to the generics slice's `analyze_static_method_call`. One generics test's `OrderBox` constructor now calls `: super(item)`, which php#157 requires, and drops an `out` marker that the slice refuses. crates/analyzer/src/statement/function_like/mod.rs <- both import sets crates/sharp-bridge/src/lower/types.rs <- method_metadata and parent_constructor both kept crates/analyzer/src/statement/class_like/method.rs <- `: super(…)` passes no type arguments crates/analyzer/tests/sharp.rs <- OrderBox calls `: super(item)`
https://bugs.php.net/bug.php?id=62328
When extending a built-in class that has a cast_object function, and specifying a __toString method, the __toString method is ignored.
I have added a check to see if the object implements a __toString magic method, and call it when it does, leaving the check for cast_object as the next thing to check.
No new tests are failing with this change.