|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57759 runkit doesn't add magic methods
Submitted: 2007-07-25 16:13 UTC Modified: 2013-02-23 15:52 UTC
From: bruno at lustosa dot net Assigned: pollita (profile)
Status: Closed Package: runkit (PECL)
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
20 + 31 = ?
Subscribe to this entry?

 [2007-07-25 16:13 UTC] bruno at lustosa dot net
Hello. I'm trying to use runkit_method_add() to add a __toString() method to my objects, because the new PHP 5.2 doesn't declare it by default.
I would make it return something like 'md5(serialize($this))', but I can't even do with a simple string.
Well, I call runkit_method_add(), it returns True. If I check with method_exists() on the object in question, it also returns True. If I try to add the method again, it complains and returns False (I guess that's correct, because the method already exists).
However, when trying a simple "print $obj;", PHP barks about being unable to convert the object to string. If I go explicit and try a "print $obj->__toString();", PHP doesn't give the error, but I get no output.
My guess is that those magic methods are somehow different than standard methods.

My problem is that I have 2 arrays of objects that I'm trying to compute the difference with array_diff(). I think the implementation of array_diff() tries to cast the array items as strings and then compare them against each other.
Before PHP 5.2, it would work correctly, because the cast to string would return something like 'Object #32', but PHP 5.2 doesn't do this anymore. I don't know of a simpler way to solve this. I have something like 200 classes extended from a PEAR class (DB_DataObject), and I don't feel like modifying the DB_DataObject source, so I thought about adding the method dynamically.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-23 15:52 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.
 [2013-02-23 15:52 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 05 15:01:31 2024 UTC