Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.0a3

Request #8208 is_callable missing in php 4.0.4, 4.0.5
Submitted: 2006-07-13 14:19 UTC
From: giunta dot gaetano at sea-aeroportimilano dot it Assigned: arpad
Status: Closed Package: PHP_Compat (version 1.5.0)
PHP Version: 4.4.2 OS: irrelevant
Roadmaps: 1.6.0a1    
Subscription  


 [2006-07-13 14:19 UTC] giunta dot gaetano at sea-aeroportimilano dot it (Gaetano Giunta)
Description: ------------ Maybe not the most important function in the world, but I found a very old install of PHP 4.0.4 hanging around (in production!), so I whipped up a replacement. Here it is, complete w. unit test <?php /** * Replace function is_callable() * * @category PHP * @package PHP_Compat * @link http://php.net/function.is_callable * @author Gaetano Giunta <giunta.gaetano@sea-aeroportimilano.it> * @version $Revision: 0.1 $ * @since PHP 4.0.6 * @require PHP 4.0.0 (true, false, etc...) * @todo add the 3rd parameter syntax... */ if (!function_exists('is_callable')) { function is_callable($var, $syntax_only=false) { if ($syntax_olny) { /* from The Manual: * If the syntax_only argument is TRUE the function only verifies * that var might be a function or method. It will only reject simple * variables that are not strings, or an array that does not have a * valid structure to be used as a callback. The valid ones are * supposed to have only 2 entries, the first of which is an object * or a string, and the second a string */ return (is_string($var) || (is_array($var) && count($var) == 2 && is_string(end($var)) && (is_string(reset($var)) || is_object(reset($var))))); } else { if (is_string($var)) { return function_exists($var); } else if (is_array($var) && count($var) == 2 && is_string($method = end($var))) { $obj = reset($var); if (is_string($obj)) { $methods = get_class_methods($obj); return (bool)(is_array($methods) && in_array(strtolower($method), $methods)); } else if (is_object($obj)) { return method_exists($obj, $method); } } return false; } } } ?> Test script: --------------- include('is_callable.php'); include('xmlrpc.inc'); $a = new xmlrpcval('hello world'); var_dump(is_callable(1)); var_dump(is_callable(false)); var_dump(is_callable(array('xmlrpcval', 'serialize', 'me'))); var_dump(is_callable(array('xmlrpcvaz', 'serialize'))); var_dump(is_callable(array('xmlrpcval', 'serializez'))); var_dump(is_callable(array($a, 'serializez'))); var_dump(is_callable(array($a, 'serialize', 'me'))); var_dump(is_callable('is_callable')); var_dump(is_callable('is_cAllable')); var_dump(is_callable(array('xmlrpcval', 'serialize'))); var_dump(is_callable(array('Xmlrpcval', 'serialize'))); var_dump(is_callable(array('Xmlrpcval', 'Serialize'))); var_dump(is_callable(array($a, 'serialize'))); var_dump(is_callable(array($a, 'Serialize'))); Expected result: ---------------- (tested against php 4.4...) bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)

Comments

 [2006-09-11 15:46 UTC] arpad (Arpad Ray)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.