From:             jsnell at e-normous dot com
Operating system: OSX 10.4.10
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  __sleep documentation is incorrect

Description:
------------
Referencing, http://us2.php.net/manual/en/language.oop5.magic.php, 

Two statements conflict with each other:
"serialize() checks if your class has a function with the magic name
__sleep. If so, that function is executed prior to any serialization. It
can clean up the object and is supposed to return an array with the names
of all variables of that object that should be serialized. If the method
doesn't return anything then NULL is serialized and E_NOTICE is issued."

and:

"The __sleep method should return the value to serialize (usually $this),
otherwise NULL is serialized."



Reproduce code:
---------------
As per the second statement:

class foo {
        public $stuff =1;
function __sleep() {      return $this;  }
}
error_reporting(E_ALL);
$bar = new foo();
serialize($bar);

causes the notice:
"serialize() [function.serialize]: __sleep should return an array only
containing the names of instance-variables to serialize."

Further, the notice does not appear if the class has no attributes:

class foo {
function __sleep() {      return $this;  }
}
error_reporting(E_ALL);
$bar = new foo();
serialize($bar);


Expected result:
----------------
If returning an object used to be the proper way to do this, a notice
which states that returning an object is deprecated.  If not, then the
documentation should not state that returning $this is valid.  Here is
patch for the latter:

 cvs diff -u en/language/oop5/magic.xml
Index: en/language/oop5/magic.xml
===================================================================
RCS file: /repository/phpdoc/en/language/oop5/magic.xml,v
retrieving revision 1.15
diff -u -u -r1.15 magic.xml
--- en/language/oop5/magic.xml  20 Jun 2007 22:24:13 -0000      1.15
+++ en/language/oop5/magic.xml  13 Jul 2007 17:43:06 -0000
@@ -51,10 +51,6 @@
     saved completely.
    </para>
    <para>
-    The <literal>__sleep</literal> method should return the value to
serialize
-    (usually <literal>$this</literal>), otherwise &null; is serialized.
-   </para>
-   <para>
     Conversely, <function>unserialize</function> checks for the
     presence of a function with the magic name 
     <literal>__wakeup</literal>. If present, this function can

Actual result:
--------------
None, since this code based on incorrect documentation should not be run
in the first place.

-- 
Edit bug report at http://bugs.php.net/?id=41992&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41992&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41992&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41992&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41992&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41992&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41992&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41992&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41992&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41992&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41992&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41992&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41992&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41992&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41992&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41992&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41992&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41992&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41992&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41992&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41992&r=mysqlcfg

Reply via email to