PHP致命错误:无法重新分配$ this [英] PHP Fatal error: Cannot re-assign $this
本文介绍了PHP致命错误:无法重新分配$ this的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从脚本中收到此错误:
I get this error from my script:
[Fri Apr 23 10:57:42 2010] [error] [client 10.0.0.1] PHP Fatal error: Cannot re-assign $this in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\abp\\fol\\test.php on line 27, referer: http://abp.bhc.com/fol/
以下是产生错误的代码:
Here is the code which produces the error:
<?php
$voiceboxes = array(
'141133' => array(
'title' => 'Title',
'1' => array(
'Title' => 'Title2',
'Link' => 'http://...',
),
'12' => array(
'Title' => 'Title3',
'Link' => 'http://...',
)
),
'1070453' => array(
'title' => 'Title4',
'1' => array(
'Title' => 'Title5',
'Link' => 'http://...',
)
)
);
$last = 0;
//$this = 0;
echo "<ol>\n";
foreach ($voiceboxes as $key => $value) {
$last = 0;
$this = null; //Error is thrown here, Line 27
//$voiceboxes[$key]['title']
echo "<ol>\n";
foreach ($value as $key2 => $value2) {
if ($key2 == 'title') {
echo "<li>$value2</li>\n";
} else {
$this = (int) $key2;
if ($this == $last + 1) {
echo '<li>';
} else { '<li value="' . $key2 . '">';}
$last = $key2;
echo $voiceboxes[$key][$key2]['Title'] . "<br/>" . $voiceboxes[$key][$key2]['Link'] . '</li>' . "\n";
}
}
echo "</ol>\n";
}
推荐答案
$this
是PHP中的预定义变量.
$this
is a predefined variable in PHP.
以下是PHP手册中的参考:类和对象:基础一个>.它描述了方法内部$ this如何指向要对其进行操作的此对象".不过,它仍然保留在方法之外.
Here's the reference in the PHP manual: Classes and Objects: The Basics. It describes how, inside a method, $this points to "this object" that is being operated upon. It is still reserved outside a method, though.
将标识符更改为另一个单词.
Change the identifier to another word.
这篇关于PHP致命错误:无法重新分配$ this的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文