Voting

: two minus two?
(Example: nine)

The Note You're Voting On

deminy at deminy dot net
16 years ago
Generally variable $this can't be used as an array within an object context. For example, following code piece would cause a fatal error:

<?php
class TestThis {
public function
__set($name, $val) {
$this[$name] = $val;
}

public function
__get($name) {
return
$this[$name];
}
}

$obj = new TestThis();
$obj->a = 'aaa';
echo
$obj->a . "\n";
?>

But things are different when $this is used in an ArrayObject object. e.g., following code piece are valid:

<?php
class TestArrayObject extends ArrayObject {
public function
__set($name, $val) {
$this[$name] = $val;
}

public function
__get($name) {
return
$this[$name];
}
}

$obj = new TestArrayObject();
$obj->a = 'aaa';
echo
$obj->a . "\n";
?>

<< Back to user notes page

To Top