Doc #65381 [Nab]: Example #1 is_callable() with a mistake

From: Date: Thu, 08 Aug 2013 08:54:12 +0000
Subject: Doc #65381 [Nab]: Example #1 is_callable() with a mistake
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10156@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65381&edit=1

 ID:                 65381
 User updated by:    jortsc at gmail dot com
 Reported by:        jortsc at gmail dot com
 Summary:            Example #1 is_callable() with a mistake
 Status:             Not a bug
 Type:               Documentation Problem
 Package:            *General Issues
 Operating System:   Windows 7
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2013-08-07 23:44:16] 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-03 11:48:38] 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




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65381&edit=1


Thread (3 messages)

« previous php.doc.bugs (#10156) next »