Edit report at http://bugs.php.net/bug.php?id=54171&edit=1

 ID:                 54171
 Comment by:         hellosexyprout at gmail dot com
 Reported by:        hellosexyprout at gmail dot com
 Summary:            is_callable() returns false on callable functions
                     when not specifying namespace
 Status:             Bogus
 Type:               Bug
 Package:            *General Issues
 Operating System:   Ubuntu 10.10
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

But then PHP's behavior is incoherent because:



<?php

namespace NS;



class HelloWorld {}

function hello_world() {}



// This will work

new HelloWorld;



// This will fail

hello_word();

?>



And anyway, being able to call bar() while 'bar' isn't 

considered callable by is_callable() (see report) is totally 

incoherent. Or I'm missing something big.


Previous Comments:
------------------------------------------------------------------------
[2011-03-05 22:05:28] fel...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected, see #51651

------------------------------------------------------------------------
[2011-03-05 21:04:27] hellosexyprout at gmail dot com

PLEASE NOTE: I inverted the actual and expected results, sorry.

------------------------------------------------------------------------
[2011-03-05 21:00:08] hellosexyprout at gmail dot com

Description:
------------
First sorry, I can only test this case with PHP 5.3.3 but I 

didn't find any bugs referring to is_callable() since then, so I 

think it's worth reporting.



The problem is that is_callable() will return false if you don't 

specify the eventual namespace you're using.

Test script:
---------------
<?php

namespace Foo;



function bar() {

        return 'bar!';

}



var_dump(is_callable('bar'));

var_dump(is_callable('\Foo\bar'));



var_dump(bar());

var_dump(\Foo\bar());

Expected result:
----------------
bool(false)

bool(true)

string(4) "bar!"

string(4) "bar!"



Actual result:
--------------
bool(true)

bool(true)

string(4) "bar!"

string(4) "bar!"




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



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

Reply via email to