dtgr3392 2014-03-04 17:45
浏览 48
已采纳

直接从PHP数组调用函数

I am trying to call a PHP function via an array like so:

$x = (object) array(
    "one" => "value",
    "two" => "value2",
    "three" => function() {
        return "return_value";
    }
);

echo($x->three());

From this I receive the error:

<b>Fatal error</b>:  Call to undefined method stdClass::three()

I've searched a bit and cannot find any documentation on this, however I ran this through

php -l filename.php

which found no syntax errors.

I would like to know if what I'm trying to do is possible (end goal is to call a function with parameters from an array). Is anybody able to shed some light on this?

Thanks

Note, I have also tried:

function foo() {
    return "bar";
}
$x = (object) array(
    "foo" => foo
);
...

which leads to the same result.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 类的继承,综合输出学生信息并析构
      • ¥15 js 使用contenteditable属性模拟富文本框的时候如何定位光标到指定位置
      • ¥15 怎么激活组态王的Touchvew菜单和Touchmak 菜单
      • ¥15 Meta分析中,如何在只有样本量的情况下用cma处理效应量r值。
      • ¥15 关于#OpenCV#的问题,如何解决?(语言-qt|开发工具-visual studio)
      • ¥15 centos环境中引入jsoncpp后,编译工程报错,找不到基本库。
      • ¥15 vue3为什么请求在这边获取不到数据呢(关键词-select)
      • ¥20 Multisim仿真设计三路智力抢答装置
      • ¥15 用UML制作简单的语音计算机
      • ¥15 综合的类,这个类里面里面又有构造方法,重载方法,有继承,有重写,有接口