Fatal error: Call-time pass-by-reference has been removed

下面的代码报错:Fatal error: Call-time pass-by-reference has been removed

function myFunc($arg) { do something... }

myFunc(&$arg);//Call myFunc

function myFunc(&$arg) { do something... }

myFunc(&$arg);//Call myFunc

错误分析:    
 allow_call_time_pass_reference boolean
    在函数调用时参数被按照引用传递时是否发出警告。此方法已不被赞成并在 PHP/Zend 未来的版本中很可能不再支持。鼓励使用的方法是在函数定义中指定哪些参数应该用引用传递。鼓励大家尝试关闭此选项并确保脚本能够正常运行,以确保该脚本也能在未来的版本中运行(每次使用此特性都会收到一条警告)。

在函数调用时通过引用传递参数是不推荐的,因为它影响到了代码的整洁。如果函数的参数没有声明作为引用传递,函数可以通过未写入文档的方法修改其参数。要避免其副作用,最好仅在函数声明时指定那个参数需要通过引用传递。

Changelog for allow_call_time_pass_reference 版本     说明
    5.4.0     从 PHP 中移除。
    5.3.0     Emits an E_DEPRECATED level error.
    5.0.0     Deprecated, and generates an E_COMPILE_WARNING level error.

函数调用时引用传参已经被移除了,就是不能通过function(&$a)这种方式传参调用函数.
解决方案:
查看你的php.ini配置文件,把其中的 allow_call_time_pass_reference参数调整为true,并重启服务器试试。

此外,以前的php代码在升级到5.4版本的php可能会出现这种错误:

当我们这样使用函数(或者类)的话,会产生一个error:

myFunc(&$arg);//Call myFunc

实际上,这样用本来就是错的,只是之前的错误级别仅仅是Deprecated而已。

而正确的使用方法应该是在函数定义时:

function myFunc(&$arg) { do something... }

而在调用时直接传参就行了:

myFunc($var);//Call myFunc

时间: 2024-08-01 22:46:19

Fatal error: Call-time pass-by-reference has been removed的相关文章

PHP Fatal error: Cannot pass parameter 2 by reference

PHP Fatal error:  Cannot pass parameter 2 by reference in 这个错误的意思是:不能按引用传递第2个参数 我的理解是: 方法的第2个参数 需要传递的一个变量 本地的PHP为 5.4.35 我出现的情况是如下: 1 <?php 2 3 function test($param1,&$param2){ 4 $param2++; 5 } 6 7 //这样的方式调用,会显示 Fatal error: Only variables can be p

FATAL ERROR: Could not find ./bin/my_print_default

网上很多方法都是:/usr/local/mysql/scripts/mysql_install_db --user=mysql 但是很有可能报错,找不到bin目录中的my_print_defaults 错误信息: FATALERROR:Couldnotfind./bin/my_print_defaults If you are using a binary release, you must run this script from within the directory the archiv

ubuntu下安装mysql出现FATAL ERROR: Could not find mysqld的处理

ubuntu下安装mysql出现FATAL ERROR: Could not find mysqld的处理 错误信息: #./bin/mysql_install_db –user=mysql FATAL ERROR: Could not find mysqld The following directories were searched: /usr/libexec /usr/sbin /usr/bin If you compiled from source, you need to run '

FATAL ERROR: Could not find ./bin/my_print_defaults

我勒个去,上午刚搞好MySQL的编译安装,玛德一重启计算机然后重启服务又报错: [[email protected] mysql-5.5.13]# /usr/local/mysql/scripts/mysql_install_db --user=mysql If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for oper

FATAL ERROR: Could not find ./share/fill_help_tables.sql

[[email protected] mysql-5.6.33]# /apps/mysql-5.6.33/scripts/mysql_install_db --datadir=/data/my_db --user=mysql FATAL ERROR: Could not find ./share/fill_help_tables.sql If you compiled from source, you need to run 'make install' to copy the software

FATAL ERROR: Could not find ./bin/my_print_defaults 解决方法

FATAL ERROR: Could not find ./bin/my_print_defaults If you compiled from source, you need to run 'make install' tocopy the software into the correct location ready for operation. If you are using a binary release, you must either be at the toplevel o

PHP配置问题:AppServ安装discuz出错 Fatal error:

 Fatal error: Call to undefined function set_magic_quotes_runtime() in  D:\AppServ\www\wp-settings.php on line 27 打开C:\WINDOWS\php.ini 大约在 428 行位置,将magic_quotes_runtime 改为 Off.也就是 magic_quotes_runtime = Off 如果前面有注释的分号,也将它删掉.然后重启 Apache 服务. 打开你的 wp 目录

python pip fatal error in launcher unable to create process using

用pip安装一个包,不知道为啥,就报了这个错误:python pip fatal error in launcher unable to create process using “” 百度了一下,用下面的命令可以解决,搞定 python2 -m pip install XXX  另外,Python3 的pip我用python3 -m pip install --upgrade pip 搞定

【MySQL】Got fatal error 1236原因和解决方法

一 前言  MySQL 的主从复制作为一项高可用特性,用于将主库的数据同步到从库,在维护主从复制数据库集群的时候,作为专职的MySQL DBA,笔者相信大多数人都会遇到"Got fatal error 1236 from master when reading data from binary log" 这类的报错/报警.本文整理了常见的几种 error 1236 报错,并给出相应的解决方法,有所不足之处,当然也希望各位读者朋友指正. 二 常见的error 1236 报错2.1 log

PHP-问题处理Fatal error: Uncaught Error: Call to undefined function simplexml_load_file()

1.问题 今天重新安装了ubuntu,PHP,MySQL,Apache,到测试CMS项目时发生一个错误: Fatal error: Uncaught Error: Call to undefined function simplexml_load_file() 2.解决: 2.1 安装php-xml: sudo apt-get install php-xml 2.2重启apache服务: sudo service apache2 restart