php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30791 magic methods (__sleep/__wakeup/__toString) call __call if object is overloaded.
Submitted: 2004-11-15 09:57 UTC Modified: 2005-06-01 13:04 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: alan at akbkhome dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-11-15 (dev) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alan at akbkhome dot com
New email:
PHP Version: OS:

 

 [2004-11-15 09:57 UTC] alan at akbkhome dot com
Description:
------------
If an object is overloaded (with __call()), then serializ'ing the object will fail unless __sleep() is defined.

It would be far clearer to either
a) - force __sleep to defined on overloaded objects (E_WARN?)
b) - dont call __call() with the __sleep() request.



Reproduce code:
---------------
class a {
   public $a = 4;
   function __call($a,$b) {
       return "unknown method";
   }
}
$b = new a;
echo serialize($b);


Expected result:
----------------
Warning: __sleep is not defined on an overloaded object with __call()

Actual result:
--------------
Warning about unexpected return value to __sleep() and an empty string output from serialize()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-13 00:02 UTC] tony2001@php.net
>If an object is overloaded (with __call()), then >serializ'ing the object will fail unless __sleep() is defined.
.. or unless __call() returns Array of instance names.

I'd say there is no bug, 'cos your overloaded __sleep() method indeed returns wrong data.
 [2005-01-13 02:10 UTC] alan at akbkhome dot com
Marcus already confirmed this needs fixing - the serialize code should not end up calling __call() on overloaded objects.
 [2005-01-13 02:13 UTC] alan_k@php.net
Changing to verified - although it's not critical (as overload was experimental in 4.x) it is a BC break - and is a relatively unexpected behaviour..
 [2005-03-07 21:55 UTC] sniper@php.net
This is what I get with latest CVS HEAD:

# php5 t.php 
Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in /home/jani/t.php on line 10


 [2005-03-15 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-04-14 09:42 UTC] alan_k@php.net
This bug needs either fixing or verifying as wont-fix. (or documenting....) so leaving it as verified until one of those occur...
 [2005-04-14 09:47 UTC] alan_k@php.net
changing title to reflect issue...
 [2005-06-01 13:04 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC