Bug #35895 [Com]: __sleep and private property
| From: | info at strictcoding dot co dot uk | Date: | Thu, 19 May 2011 13:41:40 +0000 |
| Subject: | Bug #35895 [Com]: __sleep and private property | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-160836@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=35895&edit=1
ID: 35895
Comment by: info at strictcoding dot co dot uk
Reported by: f dot hardy at origami-systems dot com
Summary: __sleep and private property
Status: No Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Freebsd 6
PHP Version: 5.1.2
Block user comment: N
Private report: N
New Comment:
Same problem, 5 years later. Could anyone re-open this bug?
PHP 5.3.5, Windows.
Previous Comments:
------------------------------------------------------------------------
[2011-02-20 16:35:47] 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...
------------------------------------------------------------------------
[2006-09-01 01:00:00] 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-08-24 10:11:37] 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-08-24 09:47:27] f dot hardy at origami-systems dot com
Bug is always alive in php 5.1.5 under freebsd 6.0.
------------------------------------------------------------------------
[2006-06-18 17:43:46] 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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=35895
--
Edit this bug report at http://bugs.php.net/bug.php?id=35895&edit=1