【问题标题】:Anonymous functions does not work: Function name must be a string匿名函数不起作用:函数名必须是字符串
【发布时间】:2013-12-09 19:11:42
【问题描述】:

我有:

PHP Version 5.4.20
'./configure' '--disable-fileinfo' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' 

我测试了这段代码:

$greet = function($name) {
    printf("Hello %s\r\n", $name);
};

$greet('PHP');

我收到此错误:

Fatal error: Function name must be a string

在 PHP 版本 5.3.10-1ubuntu3.8 上,它可以正常工作。有人知道这是怎么回事吗?

【问题讨论】:

  • 这可能与问题无关,但它到底是哪个版本的 PHP?在你帖子的第一部分,你说 5.4.20。最后一句,你说的是 5.3.10。
  • var_dump(phpversion()); 输出什么?
  • ..var_dump($greet) 输出什么?
  • 你是从源代码安装php还是使用包管理器作为YUM或apt-get

标签: php


【解决方案1】:

【讨论】:

  • 谢谢,这很难找到!
【解决方案2】:

因为 eAccelerator 而你应该禁用它

要关闭 eAccelerator,请在您的 php.ini 配置中进行以下更改:

eaccelerator.enable 0
eaccelerator.optimizer 0

或在 .htaccess 文件中

php_flag eaccelerator.enable 0
php_flag eaccelerator.optimizer 0

【讨论】:

    【解决方案3】:

    顺便说一句,当我上传 symfony 应用程序时,我注意到这个服务器(它是客户端的 VPN 服务器)有问题,我收到了这个错误

    ContextErrorException: Warning: preg_replace_callback(): Requires argument 2, '', to be a valid callback in /home/client/vendor/symfony/symfony/src/Symfony/Component/Yaml/Unescaper.php line 56
    

    【讨论】:

      猜你喜欢
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      相关资源
      最近更新 更多