Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86203 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98412 invoked from network); 13 May 2015 23:41:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2015 23:41:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.18 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.18 mout.gmx.net Received: from [212.227.15.18] ([212.227.15.18:50038] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/20-31470-731E3555 for ; Wed, 13 May 2015 19:41:44 -0400 Received: from [192.168.0.101] ([88.134.68.210]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MV5hN-1YiQsj3RoD-00YSpF; Thu, 14 May 2015 01:41:40 +0200 Message-ID: <5553E139.8090805@gmx.de> Date: Thu, 14 May 2015 01:41:45 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Guido Contreras Woda , internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:+02tU6ba3ewNBED2/MPZiQFTZb0F7tQxixLGiwnKjHiEmLZZCOQ enuByRcc5e2fHLU1e8sZtgtKjTteXnzoDTQAMUPjN0/t8v/TF0CKc8j9X/ZNAVqiROvG71l M81IyUpY54mdk69I/9uyqJH3VRPVyiErbxP5ZE7s9dk0I8z5R85w3TGgKsiqEf4M9Sh1uPc gOfSjg9/aWPKc2Eex1A2g== X-UI-Out-Filterresults: notjunk:1; Subject: Re: Proposal: interfaces for object to scalar type casting From: cmbecker69@gmx.de (Christoph Becker) Guido Contreras Woda wrote: > So, what do you think of a set of interfaces that allow userland objects to > be used as scalar types? > > Some simple examples in PHP here: > https://gist.github.com/guiwoda/5d16c8fb97d29e476d20 One of the biggest problems is that it's not always clear which conversion should be used; consider, for instance, $obj1 + $obj2 where __toInt() as well as __toFloat() might make sense. A possible solution would be to force the conversion with type casts, but I don't see a real advantage in using (int) $obj1 over $obj1->toInt() where the latter is a normal user defined method. Another problem is that such automatic casting from objects to scalars might obscure the code. -- Christoph M. Becker