Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
恼人的PHP错误:";严格的标准:只有变量才能通过引用传递到";_Php - Fatal编程技术网

恼人的PHP错误:";严格的标准:只有变量才能通过引用传递到";

恼人的PHP错误:";严格的标准:只有变量才能通过引用传递到";,php,Php,我制作了这个小脚本,但我无法获得此错误: 严格标准:在C:\xampp\htdocs\includes\class.IncludeFile.php的第34行“off!”中,只能通过引用传递变量。 以下是网页: namespace CustoMS; if (!defined('BASE')) { exit; } class IncludeFile { private $file; private $rule; function __Construct($fil

我制作了这个小脚本,但我无法获得此错误:

严格标准:在C:\xampp\htdocs\includes\class.IncludeFile.php的第34行“off!”中,只能通过引用传递变量。

以下是网页:

namespace CustoMS;

if (!defined('BASE'))
{
    exit;
}

class IncludeFile
{
    private $file;
    private $rule;

    function __Construct($file)
    {
        $this->file = $file;

        $ext = $this->Extention();
        switch ($ext)
        {
            case 'js':
                $this->rule = '<script type="text/javascript" src="'.$this->file.'"></script>';
                break;

            case 'css':
                $this->rule = '<link type="text/css" rel="stylesheet" href="'.$this->file.'">';
                break;
        }
    }

    private function Extention()
    {
        return end(explode('.', $this->file));
    }

    function __Tostring()
    {
        return $this->rule;
    }
}
名称空间;
如果(!defined('BASE'))
{
出口
}
阶级包括污秽
{
私人$file;
私人美元规则;
函数构造($file)
{
$this->file=$file;
$ext=$this->Extention();
交换机($ext)
{
案例“js”:
$this->rule='';
打破
案例“css”:
$this->rule='';
打破
}
}
私有函数扩展()
{
返回结束(分解('.',$this->file));
}
函数u_Tostring()
{
返回$this->rule;
}
}

请帮助我。

函数
end
有以下原型
end(&$array)

通过创建变量并将其传递给函数,可以避免此警告

private function Extention()
{
    $arr = explode('.', $this->file);
    return end($arr);
}
从文件中:

以下内容可以通过引用传递:

  • 变量,即foo($a)
  • 新语句,即foo(newfoobar())
  • 从函数返回的引用,即:
explode
返回一个数组,而不是对数组的引用

例如:

function foo(&$array){
}

function &bar(){
    $myArray = array();
    return $myArray;
}

function test(){
    return array();
}

foo(bar()); //will produce no warning because bar() returns reference to $myArray.
foo(test()); //will arise the same warning as your example.
end()将指针数组设置为最后一个元素。这里提供的是函数的结果,而不是变量

private function Extention()
{
    $array = explode('.', $this->file);
    return end($array);
}

您检查过第34行了吗?您检查过关于您在第34行所做的一切的文档了吗?您了解引用是如何工作的吗?解释为什么
end
抛出错误的+1可能是重复的。它希望操作引用(
&$array
)。
private function Extention()
{
    $array = explode('.', $this->file);
    return end($array);
}