![](/img/trans.png)
[英]Strict Standards: Only variables should be passed by reference - php error
[英]Annoying PHP error: “Strict Standards: Only variables should be passed by reference in”
我有这个小脚本,我不能得到这个错误:
Strict Standards: Only variables should be passed by reference in C:\\xampp\\htdocs\\includes\\class.IncludeFile.php on line 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;
}
}
请帮我。
函数end
有以下原型end(&$array)
。
您可以通过创建变量并将其传递给函数来避免此警告。
private function Extention()
{
$arr = explode('.', $this->file);
return end($arr);
}
从文档:
以下内容可以通过引用传递:
- 变量,即foo($ a)
- 新陈述,即foo(new foobar())
- 从函数返回的引用,即:
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.
private function Extention()
{
return end(explode('.', $this->file));
}
end()将指针数组设置为最后一个元素。 在这里,您提供end
函数的结果而不是变量。
private function Extention()
{
$array = explode('.', $this->file);
return end($array);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.