gwelsby Posted March 6, 2008 Share Posted March 6, 2008 I'm unserializing an array (1 member) of objects from a textfile. print_r of the object looks normal but when I try to access the members of it I'm always returned the last member. Can anyone help? <?php // class definition for hitcount & visitor tracing class hitrecord { var $pagename; var $ip; var $referer; var $date; var $time; var $hitcount = 0; } $temp=implode("",@file("Data\hitcount.txt")); $hitarray=unserialize($temp); $hitrec=$hitarray["testload.html"]; // array is of the form $pagename => hitrecord print_r($hitrec); echo($hitrec->$pagename); // returns 1 echo($hitrec->$ip); // returns 1 echo($hitrec->$date); // returns 1 echo($hitrec->$hitcount); // returns 1 (correct) ?> print_r output: hitrecord Object ( [pagename] => [ip] => [referer] => [date] => [time] => [hitcount] => 0 [testload.html] => testload.html [165.98.126.72] => 165.98.126.72 [NULL] => NULL [06/03/08] => 06/03/08 [14:43:29] => 14:43:29 [] => 1 ) Link to comment https://forums.phpfreaks.com/topic/94781-unserialized-object-exhibits-weird-behaviour/ Share on other sites More sharing options...
gwelsby Posted March 6, 2008 Author Share Posted March 6, 2008 SOLVED Sorry about this - I'm new to PHP & didn't realise one accesses object members WITHOUT the leading $. Link to comment https://forums.phpfreaks.com/topic/94781-unserialized-object-exhibits-weird-behaviour/#findComment-485513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.