Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61535 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47420 invoked from network); 20 Jul 2012 00:50:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2012 00:50:43 -0000 Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:38943] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/62-18983-26BA8005 for ; Thu, 19 Jul 2012 20:50:43 -0400 Received: by yenl12 with SMTP id l12so4003515yen.29 for ; Thu, 19 Jul 2012 17:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=WKoaEs/V948rm+qGE0bRG8XOWZhTXoLydJhVwC5Q42Y=; b=K7MTNu37Jo59EmqubeVKVF271+tELCtGvbKwFf5P1swCvxOb+nWkKIyTE3MKvdUxpz 1mcF9CYJkdIefLTKvq+KmOMvjTCZZuFfU56knsJqU1luSYmjA2oRdEoHj8v3Smm9h5Wz OprcXbkSXGIRGiZcbsZcLUDdxhw2F57YJUS4DBxJs0JmSTjM4qN7JXBkqF9pAWwoY3XU aHPKFjbpIv+eQ9EjYeHKMzRQys+4HwnsBzVABbUN/LIvbMEK/+Vwm6DH/QDLWOZFTXr8 XPH8dnylDBdu3MYIxLpdS9cNOAttJJpWq2dE0no+n5ZL6l+ooBMfvifel2ow+nAdO7vK 4BSQ== Received: by 10.66.83.161 with SMTP id r1mr7340717pay.69.1342745439531; Thu, 19 Jul 2012 17:50:39 -0700 (PDT) Received: from [192.168.0.5] (dsl-202-173-152-56.vic.westnet.com.au. [202.173.152.56]) by mx.google.com with ESMTPS id nv10sm2770985pbb.49.2012.07.19.17.50.36 (version=SSLv3 cipher=OTHER); Thu, 19 Jul 2012 17:50:38 -0700 (PDT) Message-ID: <5008AB75.1050002@gmail.com> Date: Fri, 20 Jul 2012 10:51:01 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Andrew Faulds CC: Sara Golemon , internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: davidkmuir@gmail.com (David Muir) 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" 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