Migrating legacy code - changing session name

Migrating legacy code - changing session name

am 26.01.2010 09:25:23 von Rory McKinley

Hello List

A client has asked me to migrate a few scripts that have been running
merrily under PHP4 to PHP5.2. Part of these scripts have integration
with PHPMyAdmin
using the single sign-on and so they make use of the following code :

session_write_close();
session_name("blah");
session_start();

Now, assuming that prior to session_write_close(), I have a session
that (amongst other elements) contains the following:

$_SESSION['a'] = (an instance of Object A)
$_SESSION['b'] = (an instance of Object B)
$_SESSION['c'] = (an instance of Object C)

After session_start(), I have the following :

$_SESSION['a'] = (an instance of Object C)
$_SESSION['b'] = (an instance of Object C)
$_SESSION['c'] = (an instance of Object C)

This does not consistently happen, only under particular circumstances
(it seems to be a certain set of elements in $_SESSION triggers it).
For instance, if I unset $_SESSION['b'] * prior* to doing
session_write_close() - the behaviour stops, and the elements are
retained. Has anybody seen this before?


Vital Stats:

PHP5.2
Apache1.3
FastCGI
Sessions are stored using PHP5's default session handling.

Thanks in advance

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Migrating legacy code - changing session name

am 26.01.2010 17:27:36 von Jochem Maas

Op 1/26/10 9:25 AM, Rory McKinley schreef:
> Hello List
>
> A client has asked me to migrate a few scripts that have been running
> merrily under PHP4 to PHP5.2. Part of these scripts have integration
> with PHPMyAdmin
> using the single sign-on and so they make use of the following code :
>
> session_write_close();
> session_name("blah");
> session_start();
>
> Now, assuming that prior to session_write_close(), I have a session
> that (amongst other elements) contains the following:
>
> $_SESSION['a'] = (an instance of Object A)
> $_SESSION['b'] = (an instance of Object B)
> $_SESSION['c'] = (an instance of Object C)
>
> After session_start(), I have the following :
>
> $_SESSION['a'] = (an instance of Object C)
> $_SESSION['b'] = (an instance of Object C)
> $_SESSION['c'] = (an instance of Object C)

sounds to me like the objects are a stored in a variable, each time
the same variable that the var in question is assigned by reference
(this is done in php4 code quite a bit so that objects that are
passed around are not copied - which makes them useless in many instances)

the following code mkight help you to understand what it is (that I think)
is happening:

// php4 compatible class
class Foo { var $s; function Foo($s) { $this->s = $s; } };

$store = array();
$var = new Foo("A");
$store["A"] =& $var;
$var = new Foo("B");
$store["B"] =& $var;
$var = new Foo("C");
$store["C"] =& $var;

var_dump($store);

>
> This does not consistently happen, only under particular circumstances
> (it seems to be a certain set of elements in $_SESSION triggers it).
> For instance, if I unset $_SESSION['b'] * prior* to doing
> session_write_close() - the behaviour stops, and the elements are
> retained. Has anybody seen this before?
>
>
> Vital Stats:
>
> PHP5.2
> Apache1.3
> FastCGI
> Sessions are stored using PHP5's default session handling.
>
> Thanks in advance
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php