note 68372 added to function.proc-open

From: Date: Tue, 25 Jul 2006 00:12:31 +0000
Subject: note 68372 added to function.proc-open
Groups: php.notes 
Request: Send a blank email to php-notes+get-115109@lists.php.net to get a copy of this message
if your writing a function that processes a resource from another function its a good idea not only to check whether a resource has been passed to your function but also if its of the good type like so: <?php function workingonit($resource){ if(is_resource($resource)){ if(get_resource_type($resource) == "resource_type"){ // resource is a resource and of the good type. continue }else{ print("resource is of the wrong type."); return false; } }else{ print("resource passed is not a resource at all."); return false; } // do your stuff with the resource here and return } ?> this is extra true for working with files and process pipes. so always check whats being passed to your functions. here's a small snipppet of a few resource types: files are of type 'file' in php4 and 'stream' in php5 'prossess' are resources opened by proc_open. 'pipe' are resource opened by popen. btw the 'prossess' resource type was not mentioned in the documentation. i make a bug-report for this. ---- Server IP: 83.137.20.120 Probable Submitter: 62.216.10.14 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.proc-open.php Edit -- http://master.php.net/note/edit/68372 Del: integrated -- http://master.php.net/note/delete/68372/integrated Del: useless -- http://master.php.net/note/delete/68372/useless Del: bad code -- http://master.php.net/note/delete/68372/bad+code Del: spam -- http://master.php.net/note/delete/68372/spam Del: non-english -- http://master.php.net/note/delete/68372/non-english Del: in docs -- http://master.php.net/note/delete/68372/in+docs Del: other reasons-- http://master.php.net/note/delete/68372 Reject -- http://master.php.net/note/reject/68372 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115109) next »