PHP 错误:在 Codeigniter 中只能通过引用传递变量

问题描述 投票:0回答:2

我陷入了这个错误。有人可以帮我吗?我正在使用

Codeigniter 3.1.10

这是我的代码片段

system/core/Common.php

function &load_class($class, $directory = 'libraries', $param = NULL)
{
    static $_classes = array();

    // Does the class exist? If so, we're done...
    if (isset($_classes[$class]))   
    {
        return $_classes[$class];
    }

    $name = FALSE;

    // Look for the class first in the local application/libraries folder
    // then in the native system/libraries folder
    foreach (array(APPPATH, BASEPATH) as $path)
    {
        if (file_exists($path.$directory.'/'.$class.'.php'))
        {
            $name = 'CI_'.$class;

            if (class_exists($name, FALSE) === FALSE)
            {
                require_once($path.$directory.'/'.$class.'.php');
            }

            break;
        }
    }

我不断收到此错误消息:

注意:只有变量应该通过引用传递 /customers/5/d/b/tsoft.se/httpd.www/kanban/system/codeigniter/Common.php 148号线

遇到 PHP 错误 严重性:通知

留言:

Only variables should be passed by reference

文件名:

codeigniter/Common.php

线路号码:148

**注意:第148行是这个

return $_classes[$class];

php codeigniter
2个回答
0
投票

正如这个github问题的评论中所述,由于您使用的是CodeIgniter版本

3.1.10
,因此您需要替换系统文件夹。
文件
system/codeigniter/Common.php
已移至您版本上的
system/core/Common.php


0
投票

请勿将其作为参考。

所以改为这个=> $objects[$class] =& instantiate_class(new $name());

使用这个=> $objects[$class] = new $name();

仅供参考,我正在使用 PHP 8.1

© www.soinside.com 2019 - 2024. All rights reserved.