note 16844 rejected from function.fopen by zak

From: Date: Thu, 15 Nov 2001 23:03:23 +0000
Subject: note 16844 rejected from function.fopen by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20889@lists.php.net to get a copy of this message
i allways thought variables (also a filepointer is just a variable) needs to be global to access them in a function. but: function foo($filepointer) { while ($oneline != 'end') { $oneline=fgets($filepointer, '1024'); print $oneline; } } $filepointer=fopen("onefile.txt", "r"); $oneline=""; while (!feof($filepointer)) { $oneline=fgets($filepointer, "1024"); if ($oneline == "begin") { foo($filepointer); } print $oneline; } onefile.txt: row1 row2 begin row4 row5 ende row7 row8 prints all lines 1 time!! i thought that the filepointer when calling the function is at line 3 than, in the function, the filepointer will go to line 6 but after the function the filepointer in the global script got to be at line 3 again but he is at line 6 too!!! there is no global in the function, no "&" in function-call any answers because i don't understand

« previous php.notes (#20889) next »