php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36364 Setting a class variable as a reference to a session variable breaks
Submitted: 2006-02-11 01:26 UTC Modified: 2006-02-11 01:34 UTC
From: andrew at andrewshell dot org Assigned:
Status: Not a bug Package: Session related
PHP Version: 4CVS-2006-02-11 (snap) OS: Windows and Linux
Private report: No CVE-ID: None
 [2006-02-11 01:26 UTC] andrew at andrewshell dot org
Description:
------------
I'm trying to use a session variable in a class as a singleton.  If the session var doesn't exist I create it as an empty array.  Once it exists I assign it by reference to a class variable.  The functions of the class reference the class variable.  Since the class variable is a reference to the session variable the class variable should exist between page refreshes.  This works sometimes.  On some server/php configurations it always works on others it always breaks.  If the session variable key is named the same as the class name it breaks.  If it's a random string it works.

Might be related to Bug #28144 but that was fixed in 4.3.6 and this is broken seemingly with 4.4.0 and later.

Here are configurations that work and ones that break:

Breaks on:
Microsoft-IIS/6.0 as ASAPI with PHP 4.4.0
Microsoft-IIS/5.1 as CGI/FastCGI with PHP 4.4.1 and 4.4.2
Apache/1.3.33 as CGI with PHP 4.4.2
Microsoft-IIS/5.1 as CGI/FastCGI with 4.4.x-dev snapshot 2/10/2006

Works correctly on
Microsoft-IIS/6.0 as CGI/FastCGI with PHP 4.3.6
Apache/1.3.34 as Module with PHP 4.4.2

Reproduce code:
---------------
http://andrewshell.org/test.php <-- Shows the error
http://andrewshell.org/test.phps <-- source code

First time you hit the page it works with 1 value set to each instance of the code.  If you hit refresh the first two break and the third one works.

Expected result:
----------------
All three instances should behave in the same way with results after several refreshes looking like:

Array
(
    [0.20239000 1139615291] => 5
    [0.46027100 1139615292] => 7
    [0.50540700 1139616583] => 0
    [0.31605700 1139616584] => 2
    [0.59282400 1139616649] => 6
)

Actual result:
--------------
The first two instances (blah and blah2) return with:

Warning: Cannot use a scalar value as an array in /home/.untouchables/shellab/andrewshell.org/test.php on line x

blah Object
(
    [data] => blah Object
        (
            [data] =>  *RECURSION*
        )

)

after the first refresh.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-11 01:34 UTC] andrew at andrewshell dot org
Seems the servers it breaks on are with register_globals on it works with register_globals off.  So it makes sense now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 11 05:01:32 2024 UTC