#45875 [NEW]: Saving an array under a key that equals a local class can fail

[email protected] ("philipp dot gerard at zeitdenken dot de")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             philipp dot gerard at zeitdenken dot de
Operating system: Linux
PHP version:      5.2.6
PHP Bug Type:     Session related
Bug description:  Saving an array under a key that equals a local class can fail

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"
      }
    }
  }
}






-- 
Edit bug report at http://bugs.php.net/?id=45875&edit=1
-- 
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45875&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45875&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45875&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45875&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=45875&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45875&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45875&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45875&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45875&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45875&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=45875&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=45875&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45875&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45875&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45875&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45875&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45875&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45875&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45875&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45875&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.