Re: [PHP-DEV] PHP 4.0 Bug #7646: Objects inside session variables get lost From: Onn (onn <email protected>)
Date: 11/05/00

martijnklingens <email protected> wrote:

> From: martijnklingens <email protected>
> Operating system: Linux 2.2 / Apache 1.3
> PHP version: 4.0.3pl1
> PHP Bug Type: Scripting Engine problem
> Bug description: Objects inside session variables get lost
>
> Hi,
>
> I encountered a strange bug in PHP when a session variable (an object in my case) holds instances of other classes. As soon as I call a method on such an embedded instance, the instance is lost the next time a page is loaded.
>
> I guess the garbage collector is a little bit too good and cleans up objects that are still in use, but I'm not completely sure about that.
>
> _READING_ a variable (as opposed to calling methods) does not trigger the bug, so a workaround is copying the object and calling the method on the copy, but I guess it should be fixed nevertheless.
>
> Below is a script that reliably reproduces the bug on my system. It's rather large, but with all the echo statements it should be immediately clear what it does. If you still have questions about the script or about my configuration, feel free to drop me an email at martijnklingens <email protected>
>
> Thanks in advance for your help,
>
> Martijn Klingens
>
> Script Below ------>
> <?PHP
>
> // Class A is the session var that holds instances of class B
> class A
> {
> var $Items = array ();
>
> function A ()
> {
> $this->Items [] = new B ("B1");
> $this->Items [] = new B ("B2");
> }
> }
>
> class B
> {
> var $Value;
>
> function B ($Value)
> {
> $this->Value = $Value;
> }
>
> function SomeFunction ()
> {
> // Just do nothing, calling the method is enough to trigger the bug
> }
> }
>
> session_register ("MyA");
> session_register ("Count");
>
> echo ("<html><body><pre>");
>
> // Create A if it doesn't exist:
> if (!isset ($MyA))
> {
> echo ("Creating session and instance of MyA...\n\n");
> $MyA = new A;
> $Count = 1; // Current Step
> echo ("Dump of MyA:\n");
> print_r ($MyA);
> echo ("\n<a href=$PHP_SELF>Go to step 2</a>\n");
> }
> else
> {
> // Session is registered already, call method on class B:
> $Count++;
> echo ("Session is already registered\n");
> echo ("You are now in step $Count. MyA holds:\n");
> print_r ($MyA);
> if ($Count == 2) // Step 2, i.e. trigger the bug?
> {
> echo ("\nCalling method on MyA->Items [0].\n");
> $MyA->Items [0]->SomeFunction ();
> echo ("Done. MyA now still holds the same data:\n");
> print_r ($MyA);
> echo ("\nIf you go to the next step, you'll notice that the Item\n");
> echo ("on which we just called our method got lost when the session\n");
> echo ("variable was stored by PHP!\n");
> echo ("<a href=$PHP_SELF>Go to the last step</a>");
> }
> else
> echo ("Notice that MyA->Items [0] no longer exists!");
> }
>
> echo ("</pre></body></html>");
> ?>
>
> --
> Edit Bug report at: http://bugs.php.net/?id=7646&edit=1
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
> For additional commands, e-mail: php-dev-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>

tried it out,
works fine....
what php version r u running?

ONn

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>