note 60632 deleted from function.feof by didou

From: Date: Wed, 03 Jan 2007 01:44:30 +0000
Subject: note 60632 deleted from function.feof by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121215@lists.php.net to get a copy of this message
Note Submitter: docey ---- because using an invalid handle can couse seriuos trouble, here is some very simple code that can prevent any piece of code to runaway using an invalid handle. function is_valid(&$fp, $type){ if(is_resource($fp)){ if(get_resource_type($fp) == $type){ return true; }else{ return false; } }else{ return false; } } now all you need to do to check if you got a valid handle, if(is_valid($fp, "file")){ // your code }else{ // your error code } its that simple to prevent any of your code from using an invalid handle. ofcourse you can change the "file" line to any resource you want to check for invalidies. please use good coding habits, and don't assume any varialbles, resource or objects are good. check them!!

« previous php.notes (#121215) next »