note 105861 added to function.function-exists

From: Date: Tue, 20 Sep 2011 17:07:00 +0000
Subject: note 105861 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-183309@lists.php.net to get a copy of this message
a more complete function_exists that checks for the following: functions (php and user defined) class methods * as strings in the sense of "class::method" or "class->method" * passing a class name or object, as well as the method language constructs (echo, print, etc ..) <?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 if (in_array($param1,$langConstructs)) { return(TRUE); } return(FALSE); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 157.182.147.242 ---- Manual Page -- http://www.php.net/manual/en/function.function-exists.php Edit -- https://master.php.net/note/edit/105861 Del: integrated -- https://master.php.net/note/delete/105861/integrated Del: useless -- https://master.php.net/note/delete/105861/useless Del: bad code -- https://master.php.net/note/delete/105861/bad+code Del: spam -- https://master.php.net/note/delete/105861/spam Del: non-english -- https://master.php.net/note/delete/105861/non-english Del: in docs -- https://master.php.net/note/delete/105861/in+docs Del: other reasons-- https://master.php.net/note/delete/105861 Reject -- https://master.php.net/note/reject/105861 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183309) next »