|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-08-20 20:54 UTC] philipp dot gerard at zeitdenken dot de
[2008-08-21 20:50 UTC] jani@php.net
[2008-08-21 21:06 UTC] philipp dot gerard at zeitdenken dot de
[2008-08-29 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
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" } } } }