Hi:
It is still possible to re-asign $this in a number of ways
examples
<?php
$this .= '123';
var_dump($this);
//Notice: Undefined variable: this in this.php on line 3
//string(3) "123"
<?php
$this{1} = '123';
var_dump($this);
/* array(1) {
[1]=>
string(3) "123"
}
*/
or ..
$this['foo'] = '123';
var_dump($this);
In all those cases, I expect a fatal error : cannot re-asign $this.
right ? or Im missing something ?
Thanks..
--
"If debugging is the process of removing bugs, then programming must
be the process of putting them in." – Edsger Dijkstra
Cristian Rodriguez wrote:
In all those cases, I expect a fatal error : cannot re-asign $this.
right ? or Im missing something ?
These examples don't cause any problems because they're not in the
object context, so $this is just another, ordinary variable. If you
include'd the files inside something like:
class Foo {
public function bar() {
include 'this-test.php';
}
}
there should be an error
--
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier http://htmlpurifier.org Anti-XSS Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
On Thursday 06 March 2008 23:51:47 Edward Z. Yang wrote:
These examples don't cause any problems because they're not in the
object context, so $this is just another, ordinary variable. If you
include'd the files inside something like:class Foo {
public function bar() {
include 'this-test.php';
}
}there should be an error
php -r 'class A { function __construct() { $this+=41; var_dump($this); }} new
A;'
int(42)
"should" is the right word here ;)
Regards,
Stefan
so $this is just another, ordinary variable.
is it ?
try:
php -r '$this = "123";'
Fatal error: Cannot re-assign $this ;
)
Edward Z. Yang wrote:
These examples don't cause any problems because they're not in the
object context, so $this is just another, ordinary variable. If you
include'd the files inside something like:
The above is completely wrong, please disregard my ignorance. :-)
--
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier http://htmlpurifier.org Anti-XSS Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
Hi,
$this .= '123';
Should be
$this = '123';
or
$this = '';
$this .= '123';
must init the variable. Not only the $this but also any one.
Regards
Cristian Rodriguez 写道:
Hi:
It is still possible to re-asign $this in a number of ways
examples
<?php
$this .= '123';
var_dump($this);
//Notice: Undefined variable: this in this.php on line 3
//string(3) "123"<?php
$this{1} = '123';
var_dump($this);
/* array(1) {
[1]=>
string(3) "123"
}*/
or ..
$this['foo'] = '123';
var_dump($this);In all those cases, I expect a fatal error : cannot re-asign $this.
right ? or Im missing something ?Thanks..