note 61801 added to function.is-callable
| From: | jphp at dsf dot org dot uk | Date: | Sun, 12 Feb 2006 11:38:31 +0000 |
| Subject: | note 61801 added to function.is-callable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103561@lists.php.net to get a copy of this message | ||
bob at theshirdshift:
"function_exists" doesn't do this, no, but "method_exists" works fine, and
is still faster than is_callable:
<?php
function doTimes($start, $end)
{
$start_time = explode (" ", $start);
$start_time = $start_time[1] + $start_time[0];
$end_time = explode (" ", $end);
$end_time = $end_time[1] + $end_time[0];
$time = $end_time - $start_time;
return $time;
}
class test
{
function test()
{
return true;
}
}
$test = new test;
$callableIsTrue = false;
$startIsCallable = microtime();
for($i = 0; $i < 10000; $i++)
{
if(is_callable(array('test', 'test'))) { $callableIsTrue = true; }
}
$endIsCallable = microtime();
$existsIsTrue = false;
$startExists = microtime();
for($i = 0; $i < 10000; $i++)
{
if(method_exists('test', 'test')) { $existsIsTrue = true; }
}
$endExists = microtime();
$timeIsCallable = doTimes($startIsCallable, $endIsCallable);
$timeExists = doTimes($startExists, $endExists);
echo "<b>is_callable = ".($callableIsTrue ? "TRUE" :
"FALSE")."</b>, \n";
echo "<b>method_exists = ".($existsIsTrue ? "TRUE" :
"FALSE")."</b><br>\n";
echo "<br>Did 10000 is_callables in ".$timeIsCallable." seconds";
echo "<br>Did 10000 method_exists in ".$timeExists." seconds";
?>
is_callable = TRUE, method_exists = TRUE
Did 10000 is_callables in 0.410346984863 seconds
Did 10000 method_exists in 0.175447940826 seconds
----
Server IP: 84.18.202.180
Probable Submitter: 80.177.208.41
----
Manual Page -- http://www.php.net/manual/en/function.is-callable.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61801
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61801&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61801&report=yes
Search -- http://master.php.net/manage/user-notes.php