note 107559 added to function.function-exists

From: Date: Fri, 17 Feb 2012 12:30:47 +0000
Subject: note 107559 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-186189@lists.php.net to get a copy of this message
"Michael dot Bond at mail dot wvu dot edu" posted a pretty good function, but he forgot something, the language constructs like exit and eval are case insensitive. EXIT, ExIt and exiT all work exactly the same. <?php function functionExists($param1,$param2=null) { $langConstructs = array("die", "echo", "empty", "exit", "eval", "include", "include_once", "isset", "list", "print", "require", "require_once", "unset" ); // 2 params provided, assume class if (!is_null($param2)) { return(method_exists($param1,$param2)); } // Ignore everything that isn't a string, from this point on if (!is_string($param1)) { return(FALSE); } // check if function exists if (function_exists($param1) === TRUE) { return(TRUE); } // Check to see if it is an object being passed as a string. // if so, assume object $items = explode("::",$param1); if (count($items) == 2) { return(method_exists($items[0],$items[1])); } $items = explode("->",$param1); if (count($items) == 2) { return(method_exists($items[0],$items[1])); } // check to see if it is a language construct return (in_array(strToLower($param1),$langConstructs)); } ?> Should avoid this little problem. Other than that it's a very cool little function. ---- Server IP: 69.147.83.197 Probable Submitter: 213.40.50.51 ---- Manual Page -- http://www.php.net/manual/en/function.function-exists.php Edit -- https://master.php.net/note/edit/107559 Del: integrated -- https://master.php.net/note/delete/107559/integrated Del: useless -- https://master.php.net/note/delete/107559/useless Del: bad code -- https://master.php.net/note/delete/107559/bad+code Del: spam -- https://master.php.net/note/delete/107559/spam Del: non-english -- https://master.php.net/note/delete/107559/non-english Del: in docs -- https://master.php.net/note/delete/107559/in+docs Del: other reasons-- https://master.php.net/note/delete/107559 Reject -- https://master.php.net/note/reject/107559 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186189) next »