技术饭
call_user_func 函数在命名空间下调用函数的问题
在有命名空间的条件下会报这样一个错 Warning: call_user_func() expects parameter 1 to be a valid callback, function 'barber' not found or invalid function name in 提示找不到这个函数
<?php
namespace MySpaces;
function myprint($s){
var_dump($s);
echo "\n";
}
call_user_func('myprint','string');
在有命名空间的条件下会报这样一个错
Warning: call_user_func() expects parameter 1 to be a valid callback, function '
barber' not found or invalid function name in
提示找不到这个函数
修改成
namespace MySpaces;
function myprint($s){
var_dump($s);
echo "\n";
}
call_user_func('MySpaces\myprint','string');
在命名空间下 call_user_func 函数会使用当前的命名空间么 应该是
官方的手册是这个样子的
<?php
namespace Foobar;
class Foo {
static public function test() {
print "Hello world!\n";
}
}
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
call_user_func(array(__NAMESPACE__ .'\Foo', 'test')); // As of PHP 5.3.0
?>
命名空间就是在函数 方法前面拼接了命名空间的字符串 在函数的 hashtable里名字已经变成 命名空间拼接上 函数名


文明上网理性发言!