ID: 28106 User updated by: kupka at learninglab dot de Reported By: kupka at learninglab dot de Status: Open Bug Type: Zend Engine 2 problem Operating System: Mac OS X -PHP Version: 5.0.0RC1 +PHP Version: 5.0.0RC2 New Comment:
In PHP 5 Release Candidate 2 the problem still exists. The second script generates three different CStore objects, but there should only be one CStore objec and the two CHello objects should have a pointer to the same CStore object. Previous Comments: ------------------------------------------------------------------------ [2004-04-25 16:48:45] kupka at learninglab dot de The second script: session_start(); $store->value = 123; echo "store id: $store<br>"; $store->object1->hello(); $store->object2->hello(); ------------------------------------------------------------------------ [2004-04-22 13:34:09] kupka at learninglab dot de Description: ------------ You have a main object which includes some other objects. This object is stored in the session. The other objects have a reference to the main object. If you start a new session these references should point to the main object. If you pass the objects to the main object in the old style with "&" this works fine. If you use the new style without "&" it doesn't work as exspected. Reproduce code: --------------- The classes: class CHello { var $store; // this doesn't work as exspected public function CHello($store) { $this->store = $store; } /* // this works fine public function CHello(&$store) { $this->store =& $store; } */ public function hello( ) { $v = $this->store->value; echo "Hello World: value is $v. (store id: $this->store)<br>"; } } class CStore { var $object1; var $object2; var $value = 0; } --------------------------- The first script: session_start(); $store = new CStore; $hello1 = new CHello($store); $hello2 = new CHello($store); $store->value = 999; $store->object1 = $hello1; $store->object2 = $hello2; echo "store id: $store<br>"; $store->object1->hello(); $store->object2->hello(); session_register("store"); --------------------------- The second script: session_start(); $store->value = 123; echo "store id: $store<br>"; echo $store->object1->hello(); echo $store->object2->hello(); Expected result: ---------------- The first script where the objects are generated: store id: Object id #4 Hello World: value is 999. (store id: Object id #4) Hello World: value is 999. (store id: Object id #4) The second script: store id: Object id #1 Hello World: value is 123. (store id: Object id #1) Hello World: value is 123. (store id: Object id #1) Actual result: -------------- The first script where the objects are generated: store id: Object id #6 Hello World: value is 999. (store id: Object id #6) Hello World: value is 999. (store id: Object id #6) The second script: store id: Object id #1 Hello World: value is 999. (store id: Object id #3) Hello World: value is 999. (store id: Object id #5) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28106&edit=1