Jump to content

Unserialized object exhibits weird behaviour


gwelsby

Recommended Posts

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

)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.