ID: 45875
Updated by: [email protected]
Reported By: philipp dot gerard at zeitdenken dot de
-Status: Open
+Status: Feedback
Bug Type: Session related
Operating System: Linux
PHP Version: 5.2.6
New Comment:
Check your phpinfo() output for register_globals. Is it on or off?
Previous Comments:
------------------------------------------------------------------------
[2008-08-20 20:54:49] 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-20 20:19:13] 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"
}
}
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45875&edit=1
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.