Skip to content

Bug #62328 (implementing __toString and a cast to string fails) - #157

Merged
php-pulls merged 2 commits into
php:masterfrom
lt:Bug-62328
Aug 12, 2012
Merged

php-pulls merged 2 commits into
php:masterfrom
lt:Bug-62328

Conversation

@lt

@lt lt commented Aug 10, 2012

Copy link
Copy Markdown
Contributor

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.

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.
@reeze

reeze commented Aug 10, 2012

Copy link
Copy Markdown
Contributor

Maybe one more test case for this :)

@lt

lt commented Aug 10, 2012

Copy link
Copy Markdown
Contributor Author

@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.

@reeze

reeze commented Aug 10, 2012

Copy link
Copy Markdown
Contributor

maybe you could find a class from spl classes :)

@php-pulls
php-pulls merged commit 222ab9d into php:master Aug 12, 2012
@laruence

Copy link
Copy Markdown
Member

sorry, I merged this for reviewing, but push to master by accident, anyway, I got a different fix here: 7b307fb thanks .

@lt

lt commented Aug 12, 2012

Copy link
Copy Markdown
Contributor Author

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 SplFileInfo instead of SimpleXmlElement in the test for this. XML libraries may be disabled, but SPL will not.

@laruence

Copy link
Copy Markdown
Member

leight, hmm, okey, I think this test can be merged into ext/spl folder too , will do it . thanks

@laruence

Copy link
Copy Markdown
Member

test script merged e51acee thanks

@lt
lt deleted the Bug-62328 branch December 4, 2013 10:45
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
…ializer

feat: call the base class's constructor with `: super(…)`
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
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
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
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)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants