Skip to content

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

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

Merged
merged 2 commits into from
Aug 12, 2012

Conversation

lt
Copy link
Contributor

@lt lt commented Aug 10, 2012

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
Copy link
Contributor

reeze commented Aug 10, 2012

Maybe one more test case for this :)

@lt
Copy link
Contributor Author

lt commented Aug 10, 2012

@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
Copy link
Contributor

reeze commented Aug 10, 2012

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
Member

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

@lt
Copy link
Contributor Author

lt commented Aug 12, 2012

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
Member

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

@laruence
Copy link
Member

test script merged e51acee thanks

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