php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35895 __sleep and private property
Submitted: 2006-01-04 17:36 UTC Modified: 2012-10-01 15:21 UTC
Votes:19
Avg. Score:4.7 ± 0.7
Reproduced:16 of 17 (94.1%)
Same Version:4 (25.0%)
Same OS:4 (25.0%)
From: f dot hardy at origami-systems dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Freebsd 6
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: f dot hardy at origami-systems dot com
New email:
PHP Version: OS:

 

 [2006-01-04 17:36 UTC] f dot hardy at origami-systems dot com
Description:
------------
if __sleep return a private property in its array, php say :
Unknown: "foo" returned as member variable from __sleep() but does not exist



Reproduce code:
---------------
<?php

class foo
{
   private $foo = array();

   public function __construct()
   {
      ;
   }

   public function __sleep()
   {
       return array('foo');
   }
}

?>

Expected result:
----------------
php must find a private property wich is return by __sleep.

Actual result:
--------------
Unknown: "foo" returned as member variable from __sleep() but does not exist

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-04 18:57 UTC] f dot hardy at origami-systems dot com
It is the same bug than #26737, which is closed !!
The workaround return array("a",
    //              "\0*\0b",
    //              "\0" . __CLASS__ . "\0c");
is ok !
 [2006-01-04 20:41 UTC] sniper@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 [2006-01-20 14:39 UTC] f dot hardy at origami-systems dot com
This bugs is always alive in php 5.1.2.
Please correct it !
 [2006-01-20 14:49 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2006-01-28 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".
 [2006-05-23 17:27 UTC] f dot hardy at origami-systems dot com
Bug is still alive in php 5.1.4 under freebsd.
Please correct it !
 [2006-05-23 17:54 UTC] amt@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

I cannot reproduce (on Linux) using latest 5.2 CVS. Can you please try a snapshot from the 5.2 series and let me know if it's fixed for you there?
 [2006-05-31 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".
 [2006-06-18 17:43 UTC] jona at oismail dot com
Reproduced on Windows 2000 when using __sleept() with aggregated objects as private memembers.
The bug has been reproduced in both PHP 5.2-dev (from link below) and PHP 5.1.4.

The following script can be used to reproduce the error:
<?php
class TestParent
{
	private $parentPrivateVar;
	protected $parentProtectedVar;
	public $parentPublicVar;
	
	public function __construct($private, $protected, $public)
	{
		$this->parentPrivateVar = $private;
		$this->parentProtectedVar = $protected;
		$this->parentPublicVar = $public;
	}
	
	function __sleep()
	{
		return array("parentPrivateVar", "parentProtectedVar", "parentPublicVar");
	}
}

class TestChild extends TestParent
{
	private $childPrivateVar;
	protected $childProtectedVar;
	public $childPublicVar;
	
	public function __construct($private, $protected, $public)
	{
		$this->childPrivateVar = "child_". $private;
		$this->childProtectedVar = "child_". $protected;
		$this->childPublicVar = "child_". $public;
		
		parent::__construct("parent_". $private, "parent_". $protected, "parent_". $public);
	}
	
	function __sleep()
	{
		return array_merge(array("childPrivateVar", "childProtectedVar", "childPublicVar"), parent::__sleep() );
	}
}

class WebSession
{
	private $privateVar;
	private $privateAggregatedObject;
	
	public function __construct($private, TestChild &$o)
	{
		$this->privateVar = $private;
		$this->privateAggregatedObject = $o;
	}
		
	public function __sleep() { return array("privateVar", "privateAggregatedObject"); }

	public function getPrivateVar() { return $this->privateVar; }
		
	public function getObject() { return $this->privateAggregatedObject; }
}

// Report simple running errors
error_reporting(E_ERROR | E_PARSE | E_WARNING | E_NOTICE | E_STRICT | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);

// Start user session
session_start();

if(isset($_SESSION['obj_Info']) === false)
{
	$_SESSION['obj_Info'] = new WebSession("private variable", new TestChild("private", "protected", "public") );
}

echo "<pre>";
var_dump($_SESSION['obj_Info']);
echo "</pre>";
echo "<hr />";
echo "TEST: ". $_SESSION['obj_Info']->getPrivateVar() ."<br />";
echo "OBJECT: ". $_SESSION['obj_Info']->getObject() ."<br />";
echo "OBJECT PUBLIC VAR: ". $_SESSION['obj_Info']->getObject()->childPublicVar ."<br />";
?>

GIVES THE FOLLOWING OUTPUT IN PHP 5.1.4:
object(WebSession)#1 (2) {
  ["privateVar:private"]=>
  string(16) "private variable"
  ["privateAggregatedObject:private"]=>
  object(TestChild)#2 (6) {
    ["childPrivateVar:private"]=>
    string(13) "child_private"
    ["childProtectedVar:protected"]=>
    string(15) "child_protected"
    ["childPublicVar"]=>
    string(12) "child_public"
    ["parentPrivateVar:private"]=>
    string(14) "parent_private"
    ["parentProtectedVar:protected"]=>
    string(16) "parent_protected"
    ["parentPublicVar"]=>
    string(13) "parent_public"
  }
}

TEST: private variable
OBJECT: Object id #2
OBJECT PUBLIC VAR: child_public

Notice: Unknown: "parentPrivateVar" returned as member variable from __sleep() but does not exist in Unknown on line 0

The notice is only thrown on the initial run with "parentPrivateVar" is actually set.
The notice is not thrown if "parentPrivateVar" is null.

In PHP 5.2-dev the scrip dies line 76: echo "OBJECT: ". $_SESSION['obj_Info']->getObject() ."<br />";
The notice is still thrown when "parentPrivateVar" is set though.
 [2006-08-24 09:47 UTC] f dot hardy at origami-systems dot com
Bug is always alive in php 5.1.5 under freebsd 6.0.
 [2006-08-24 10:11 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-09-01 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".
 [2011-02-20 16:35 UTC] somiara at hotmail dot com
No comment. Same problem. 2011...

Apache/Windows: php-version 5.2.4
Apache/RH: php-version 5.3.1

Notice: serialize() [function.serialize]: "module_instancename" returned as member variable from __sleep() but does not exist in...
 [2011-05-19 15:41 UTC] info at strictcoding dot co dot uk
Same problem, 5 years later. Could anyone re-open this bug?
PHP 5.3.5, Windows.
 [2012-10-01 13:51 UTC] hrecho at gmail dot com
i see this issue in 5.3.8
 [2012-10-01 15:21 UTC] laruence@php.net
according to the test script provided by jona at oismail dot com:

it's a expected behavior, you can not access parent's private property.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC