# Overloaded property access

- Thread: https://externals.io/message/10229
- Original archive: https://news-web.php.net/php.internals/10229
- Started by Rick Fletcher on 2004-06-01T18:41:14+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10229 — Rick Fletcher — 2004-06-01T18:41:14+00:00

URL: https://externals.io/message/10229#10229

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

---

## #10233 — Rick Fletcher — 2004-06-01T20:45:39+00:00

URL: https://externals.io/message/10229#10233 · In reply to: #10229

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
