References to objects surviving being session_register()'ed

From: Date: Fri, 07 Jul 2000 17:26:44 +0000
Subject: References to objects surviving being session_register()'ed
Groups: php.general 
Request: Send a blank email to php-general+get-5414@lists.php.net to get a copy of this message
Please help. It seems that if you make two variables that are _references_ to the same object and then call session_register() with the variables, then on the next php-page the two variables are distinct _copies_ of the object. Here is an example: ---------- [gizmo1.php] ---------- class Gizmo { var $strGizmo = "Foo"; } $myGizmo1 = new Gizmo(); $myGizmo2 = &$myGizmo1; session_start(); session_register("myGizmo1"); session_register("myGizmo2"); echo $myGizmo1->strGizmo . $myGizmo2->strGizmo; ---------- [gizmo2.php] ---------- class Gizmo { var $strGizmo; } session_start(); $myGizmo2->strGizmo = "Bar"; echo $myGizmo2->strGizmo; // Should write "Bar" echo $myGizmo1->strGizmo; // Should write "Bar" because the // two objects are (or rather:should be :) // identical. ---------- [end of example] ---------- (The examples was tested on PHP Version 4.0.1pl1 running on Linux 2.2.5-15.) gizmo1.php outputs: "FooFoo" gizmo2.php outputs: "BarFoo" <-- AAAARGH!!!! Is this because of the limitation in PHP's serializer?? If so, is there a way around it? Best regards Peter Hansen and Martin Nielsen Deus ex Machina

« previous php.general (#5414) next »