note 38362 added to function.fopen

From: Date: Thu, 18 Dec 2003 05:04:22 +0000
Subject: note 38362 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-62151@lists.php.net to get a copy of this message
when attempting to reuse the same filename (eg: $txtfile = /home/username/public_html/php/textfile; ) such as a textfile in my case ; haven't tested for a binary, fclose fails despite fopen was successful.. scenario: reuse of $filename on two consecutive fopen/fclose sequences will bring up php crying about a file-handling error on the last fclose despite the second fopen being successful.. eg: The First time string filename used - $mbrFileNm = "/home/usernm/public_html/php/textfile"; $MBRFIL = fopen($mbrFileNm, "r"); if( $MBRFIL != false ){ while ( !feof($MBRFIL) ) { list( $username, $pw ) = split( " ", fgets($MBRFIL ,100)); $memlist_array[$username] = $pw; } fclose($MBRFIL); } - the second time its being used.. $FILEMF=fopen($mbrFileNm, "w"); if( $FILEMF != false ){ //this block enters successfully fputs($FILEMF, "test"); //test gets written, surprise! //blah blah procedures.. fclose($FILEMF); //php shoots out a 'warning' error, block still runs writting to file, but strangely it cries there's an invalid file handler to this variable.. } //// *** warning error given: --> it would say either a "3" or "4" on this error line jotted out... fclose(): 3 is not a valid stream resource in /phppath/file.php on line #<numberline of fclose> //// *** Php cries on the last fclose don't know why..the fix around is to use another name other than $mbrFileNm for the seond handle....Php needs much more work to become as competitve as Perl and Python..sorry but the PHP team should work harder...quite a shame, i'm going back to perl. Php, too many bugs..it sucks! -System tested on Apache 2.x + Php version 4.3.2 If you want filesystem functions, go perl..forget php its too "unstable".. orc ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38362 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38362&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38362&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62151) next »