Storing classes in a PHP Session with AMFPHP
On October 6, 2008, PHP / HTML - 1 CommentI’m working on a small project with a AMF / PHP backend. The project has different roles and users, and I’m storing the user object in the session of PHP.
Now, according to the PHP manual, it should be possible to store complex objects (and classes) in the session. So when I put the user in the session and then dumped the session to the browser, I was pleased to see everything was in it. So far so good…
But then, strange things started to happen. Whilst the data was in the session, I wasn’t able to get it out easily. To understand what I mean, look at the following examples:
The user has a property ‘projects’, which is an array of projectObjects, which look like this:
class ProjectObject { var $_explicitType = "ProjectObject"; public $name; public $id; public $lastModified; } |
Pretty straightforward.
Now, when i output the projects array using print_r, I get this:
Array ( [0] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => ProjectObject [name] => Test1 [id] => 1 [lastModified] => 1218479521000 ) [1] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => ProjectObject [name] => Test [id] => 2 [lastModified] => 1218479559000 ) ) |
Which is ok (I think).
But when I want to access any of the properties of the project, it will return an error, null or an empty string:
echo $user -> projects[0] -> id; // returns ""; echo $user -> projects[0][id]; //Fatal error: Cannot use object of type _PHP_Incomplete_Class as array echo $user -> projects[0]["id"];//Fatal error: Cannot use object of type _PHP_Incomplete_Class as array |
Weird huh? more…