On 20/07/12 09:38, Andrew Faulds wrote: > I'm curious, how do I make my objects have scalar passing semantics, then? > On Jul 20, 2012 12:35 AM, "Sara Golemon" <poll...@php.net> wrote: >
How about this? class String { protected $string=''; public function __construct($string){ $this->string = $string; } public function toUpper(){ $string = clone $this; $string->string = strtoupper($this->string); return $string; } public function __toString(){ return $this->string; } } $foo = new String('foo'); $bar = $foo->toUpper(); echo $foo; //foo echo $bar; //FOO So far we only have the toString magic method. If we had the others, you could conceivably do this all in userland (at a fairly high performance cost I would assume). Cheers, David -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php