Hello,

OKay, when i replace the last rows with:

$fp=fopen("test.txt","r");
flock($fp,1);
$array=array_merge($array,unserialize(fread($fp,filesize("test.txt"))));
flock($fp,3);
fclose($fp);

it works.

But now i want to place this in a class, and it goes wrong again.

Hope you can help, thanks,

Bas
 
--
<?
class test
{

function test(){;}      
        
function read()
{
$array=array();
$fp=fopen("test.txt","r");
flock($fp,1);
$array=unserialize(fread($fp,filesize("test.txt")));
flock($fp,3);
fclose($fp);
return $array;
}

function save($array)
{
$fp=fopen("test.txt","w+");
flock($fp,2);
fwrite($fp,serialize($array));
flock($fp,3);
fclose($fp);
}

function push($array,$value)
{
array_push($array,$value);
$this->save($array);
}

}
$test= new test;

$array=$test->read();

echo $array[0].$array[1].$array[2];

$test->push($array,"three");
//$test->save($array);

$array=$test->read();

echo $array[0].$array[1].$array[2];

?>
--



Op dinsdag 05 februari 2002 12:24, schreef u:
> Hi,
>
> At start test.txt contains a serialized array with value "one" and "two".
> a:2:{i:0;s:3:"one";i:1;s:3:"two";}
> after one run this is:
> a:3:{i:0;s:3:"one";i:1;s:3:"two";i:2;s:4:"tree";}
>
> But the last row prints nothing. Why?
>
> Tnx,
>
> Bas
>
> <?
> $array=array();
> $fp=fopen("test.txt","r");
> flock($fp,1);
> $array=unserialize(fread($fp,filesize("test.txt")));
> flock($fp,3);
> fclose($fp);
>
> array_push($array,"tree");
>
> $fp=fopen("test.txt","w+");
> flock($fp,2);
> fwrite($fp,serialize($array));
> flock($fp,3);
> fclose($fp);
>
> $fp=fopen("test.txt","r");
> flock($fp,1);
> $array=unserialize(fread($fp,filesize("test.txt")));
> flock($fp,3);
> fclose($fp);
>
> echo $array[0].$array[1].$array[2];
> ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to