unexpected reference behavior in class context
| From: | Leo | Date: | Wed, 18 Oct 2000 14:19:53 +0000 |
| Subject: | unexpected reference behavior in class context | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-35426@lists.php.net to get a copy of this message | ||
Here is a strange behavior concerning variable referencing in a class
Below is a simple-case code snipplet that demonstrate the problem
Description of the snipplet:
"Container" is a class that contains an instance of "Item" class.
Container provides a callFoo() method that invokes Item::Foo()
After invoking $this->item->Foo(), item has become a *reference* ,
according to var_dump()
One consequence is that when a container is sessionized ,
Container->item is omitted, as it's a reference.
PHP Version: 4.0.3pr2
PHP Sapi: apache / apxs
Server : Apache 1.3.9
OS : Linux/Debian 2.2
Related php.ini directives:
allow_call_time_pass_reference = Off ; as recommended
Leo WEST
-----------------SNIPPLET-----------
<?
class Item
{
function Foo()
{
echo "calling Item::Foo\n";
}
}
class Container
{
var $item;
function Container()
{
$this->item = new Item();
}
function callFoo()
{
$this->item->Foo();
}
}
$c = new Container();
echo "<xmp>\nBEFORE:";
var_dump($c);
$c->callFoo();
echo "\nAFTER:";
var_dump($c);
echo "</xmp>";
?>
-----------------OUTPUT-----------
BEFORE:object(container)(1) {
["item"]=>
object(item)(0) {
}
}
calling Item::Foo
AFTER:object(container)(1) {
["item"]=>
&object(item)(0) {
}
}