note 97009 added to function.file-get-contents

From: Date: Sat, 27 Mar 2010 22:03:34 +0000
Subject: note 97009 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-167455@lists.php.net to get a copy of this message
If you want to check if the function returned error, in case of a HTTP request an, it's not sufficient to test it against false. It may happen the return for that HTTP request was empty. In this case it's better to check if the return value is a bool. <?php $result=file_get_contents("http://www.example.com"); if (is_bool($result) && $result == false) { // treat error } else { // handle good case } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 188.26.215.167 ---- Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php Edit -- https://master.php.net/note/edit/97009 Del: integrated -- https://master.php.net/note/delete/97009/integrated Del: useless -- https://master.php.net/note/delete/97009/useless Del: bad code -- https://master.php.net/note/delete/97009/bad+code Del: spam -- https://master.php.net/note/delete/97009/spam Del: non-english -- https://master.php.net/note/delete/97009/non-english Del: in docs -- https://master.php.net/note/delete/97009/in+docs Del: other reasons-- https://master.php.net/note/delete/97009 Reject -- https://master.php.net/note/reject/97009 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167455) next »