php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45875 Saving an array under a key that equals a local class can fail
Submitted: 2008-08-20 20:19 UTC Modified: 2008-08-29 01:00 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: philipp dot gerard at zeitdenken dot de Assigned:
Status: No Feedback Package: Session related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: philipp dot gerard at zeitdenken dot de
New email:
PHP Version: OS:

 

 [2008-08-20 20:19 UTC] philipp dot gerard at zeitdenken dot de
Description:
------------
Saving an array under a key that equals a local class can result in the 
array becoming an object.






Reproduce code:
---------------
# Parts of Zelos_Session.php:
class Zelos_Session {

	/**
	 * Stores data in the session storage
	 *
	 * @param string $module 
	 * @param string $key 
	 * @param array $arrayData 
	 * @return void
	 * @author Philipp G?rard
	 */
	public function save($module, $key, $arrayData){
		$_SESSION[$module][$key] = $arrayData;
	}
	
	/**
	 * Returns a specific part of the storage
	 *
	 * @param string $module 
	 * @param string $key 
	 * @return void
	 * @author Philipp G?rard
	 */
	public function read($module, $key){
		if(isset($_SESSION[$module][$key])){
			return $_SESSION[$module][$key];
		} else {
			return false;
		}
	}
}

# Parts of Zelos_Auth.php:
class Zelos_Auth {

	public function authenticate($authArray){
		# (...)
		$results	= $qObj->fetchAll(PDO::FETCH_ASSOC);
		if(count($results)>0){
			// Valid user, log em' in
			$results[0]["status"] = true;
			$GLOBALS["Zelos_Session"]->save("Zelos_Auth","userdata",$results[0]);
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Returns true if the user is logged in
	 *
	 * @return void
	 * @author Philipp G?rard
	 */
	public function isActive(){
		$userdata = $GLOBALS["Zelos_Session"]->read("Zelos_Auth","userdata");
		return ($userdata["status"] == true) ? true : false;
	}

}

Expected result:
----------------
save() works, but after changing the page (refreshing or such) read() 
returns instead of

array(1) {
  ["Zelos_Auth"]=>
  array(1) {
    ["userdata"]=>
    array(4) {
      ["id"]=>
      string(1) "1"
      ["username"]=>
      string(13) "username"
      ["usergroup"]=>
      string(1) "1"
      ["status"]=>
      bool(true)
    }
  }
}






Actual result:
--------------
array(1) {
  ["Zelos_Auth"]=>
  &object(Zelos_Auth)#7 (2) {
    ["adapter:private"]=>
    array(1) {
      ["table"]=>
      string(5) "users"
    }
    ["credentials:private"]=>
    array(5) {
      ["identifier"]=>
      string(2) "id"
      (...)
    }
  }
}

Sometimes also an "incomplete class" is returned

array(1) {
  ["Zelos_Auth"]=>
  &object(__PHP_Incomplete_Class)#3 (3) {
    ["__PHP_Incomplete_Class_Name"]=>
    string(10) "Zelos_Auth"
    ["adapter:private"]=>
    array(1) {
      ["table"]=>
      string(5) "users"
    }
    ["credentials:private"]=>
    array(5) {
      ["identifier"]=>
      string(2) "id"
      ["username"]=>
      string(8) "username"
      ["password"]=>
      string(8) "password"
      ["encryption"]=>
      string(4) "sha1"
      ["optionals"]=>
      array(1) {
        [0]=>
        string(9) "usergroup"
      }
    }
  }
}






Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-20 20:54 UTC] philipp dot gerard at zeitdenken dot de
Another note: This does not happen in PHP 5.2.5 but only in 5.2.6!
 [2008-08-21 20:50 UTC] jani@php.net
Check your phpinfo() output for register_globals. Is it on or off?
 [2008-08-21 21:06 UTC] philipp dot gerard at zeitdenken dot de
5.2.5: Off
5.2.6: On

When disabling register_globals via 'php_flag register_globals off' the 
malfunction is gone.
 [2008-08-29 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC