|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-05 21:00 UTC] 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!"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
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.Great, I'm okay with that. But how do explain this? <?php namespace Foo; function bar() {} function hello_world() {} bar(); // works hello_word(); // fails