RE: [PHP-DEV] Overloaded property access
| From: | Rick Fletcher | Date: | Tue, 01 Jun 2004 20:45:39 +0000 |
| Subject: | RE: [PHP-DEV] Overloaded property access | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10233@lists.php.net to get a copy of this message | ||
After sending this mail I went and searched the bugs database more
thoroughly and found this very problem here:
http://bugs.php.net/bug.php?id=28444.
My apologies.
Rick
> -----Original Message-----
> From: Rick Fletcher [mailto:rick@snocap.com]
> Sent: Tuesday, June 01, 2004 11:41a
> To: internals@lists.php.net
> Subject: [PHP-DEV] Overloaded property access
>
> I've just made use of overloaded property access for the
> first time and
> experienced some unexpected behavior. I just wanted to
> verify that it was
> the correct behavior with those who'd know best.
>
> <?php
>
> class One {
> public function __construct() {
> $this->two = new Two();
> }
>
> public function __set( $n, $v ) {
> $GLOBALS[$n] = $v;
> }
>
> public function __get( $n ) {
> return $GLOBALS[$n];
> }
> }
>
> class Two {
> public $property = "default value";
> }
>
> $one = new One();
>
> print( "\"" . $one->two->property . "\"n" );
>
> $one->two->property = "new value";
>
> ?>
>
> This produces:
> =================
> $ php -f test.php
> "default value"
> PHP Fatal error: Cannot access undefined property for object with
> overloaded property access in /home/fletch/test.php on line 24
> =================
>
> Is it correct that $one->two->property should be read only?
>
> Thanks.
>
> Rick Fletcher
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>