this works in java because you are running your own webserver/application and you can store persistent objects at the app level.
with php, apache is the webserver and your php script will only run for a second or so. because the scripts aren't running within your own application and you can't use apache to store data, data cannot persist beyond the end of each script.
as said above, you will want to serialize the object, but if using text files, you should use file-locking as well, so your objects don't get corrupted. storing them in a db would be simpler.