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  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 32 + 26 = ?

 
 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!