php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bruno at lustosa dot net
New email:
PHP Version: OS:

 

 [2007-07-25 16:13 UTC] bruno at lustosa dot net
Description:
------------
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-23 15:52 UTC] pollita@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

https://github.com/php/pecl-php-
runkit/commit/c3fe2b1a981109ca1d4b95c6931d768dafc475de
 [2013-02-23 15:52 UTC] pollita@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC