php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65381 Example #1 is_callable() with a mistake
Submitted: 2013-08-03 11:48 UTC Modified: 2013-08-08 08:54 UTC
From: jortsc at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
 [2013-08-03 11:48 UTC] jortsc at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.is-callable#refsect1-function.is-
callable-examples
---
I'm studying for the ZCE and I found what it seems a mistake. This code does not 
return true, returns false. I think the second parameter has to set to true.

I hope it will be useful.
Greetings.

Test script:
---------------
function someFunction() 
{
}

$functionVariable = 'someFunction';

var_dump(is_callable($functionVariable, false, $callable_name));  // bool(true)

echo $callable_name, "\n";  // someFunction

It shows:
bool(false) someFunction

function someFunction2() 
{
}

$functionVariable = 'someFunction2';

var_dump(is_callable($functionVariable, true, $callable_name));  // bool(true)

echo $callable_name, "\n";  // someFunction



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-07 23:44 UTC] mfonda@php.net
-Status: Open +Status: Not a bug
 [2013-08-07 23:44 UTC] mfonda@php.net
The example code on the manual page and the code below both produce the correct 
result, bools(true).

Double-check your test script to make sure there are no typos. If you copy/pasted 
the example from the manual, perhaps your editor messed things up when pasting. A 
misspelling of 'someFunction' in your test script would result in is_callable 
returning false.
 [2013-08-08 08:54 UTC] jortsc at gmail dot com
It was due at the fact that is_callable() don't handle namespaces, my script in 
header looks like:
<?php 
namespace Cert;

function algunaFuncion() 
{
      echo "Desde alguna funcion. . .";
}

$variableFuncion = __NAMESPACE__.'\algunaFuncion';//Now I added the namespace 
constant

var_dump(is_callable($variableFuncion, false, $nombre_a_llamar));  // bool(true)

echo $nombre_a_llamar, "\n";
?>

Prepending namespace constant all works fine.
I didn't think that namespace would affect to is_callable() function.
I know one more thing...

Thank you very much.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 05:00:01 2026 UTC