Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86271 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83313 invoked from network); 16 May 2015 21:14:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 May 2015 21:14:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.52 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.52 mail-pa0-f52.google.com Received: from [209.85.220.52] ([209.85.220.52:34606] helo=mail-pa0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/6F-14891-633B7555 for ; Sat, 16 May 2015 17:14:30 -0400 Received: by pabru16 with SMTP id ru16so81678646pab.1 for ; Sat, 16 May 2015 14:14:27 -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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=qNEwQwmeB2/itqfmVe2eTiMXuhWimmJaDIdAJZMHpak=; b=JdZDvnT6v4tleAD1bQ1bvhvWUDJP73WZ7GA96+6ET01ElC7MbCjgvUWooiZxY+/NrZ 7epfZV+ycxfHvO3u/s8obSeYOaB6jkAFbIQNizUXQUONwsNgp9WdU0YIWn/mlpQdbb+5 tCn2MkFjutpwtKbKncXyOY+qlljbGXKPdeBnDayGj1sPXkQ2l0mfELCD9vcnGCsmPm8Z /apLoQQJYWlSlxdmgtqPShymxnnqoVjLMi3GaOqMTa6DQF/1VrEYU43a6dGdAZBcmodQ CR4QLaYMgm558IbbI37+RJssV5p0HPmeYnFeFtdLoFo+GOpiy47cm3InEQ1ubKFQnc9t 2tNQ== X-Received: by 10.70.88.170 with SMTP id bh10mr30657712pdb.62.1431810867657; Sat, 16 May 2015 14:14:27 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id sc1sm5617304pac.36.2015.05.16.14.14.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 May 2015 14:14:27 -0700 (PDT) Message-ID: <5557B32E.70804@gmail.com> Date: Sat, 16 May 2015 14:14:22 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Christoph Becker , Guido Contreras Woda , internals@lists.php.net References: <5553E139.8090805@gmx.de> In-Reply-To: <5553E139.8090805@gmx.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Proposal: interfaces for object to scalar type casting From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > 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. If both are object, I would rather not use either conversion, I'd use operator support instead, if operator is not supported by the objects (or the objects do not have same operator handler) then all bets are off. I guess we could keep them converted to int as they are now, but it'd be something of "we must return something so we choose arbitrarily and hope it's what you meant" than something with a robust semantics. Primarily because for arbitrary objects there's really no semantics that is natural here. > 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() One advantage is that the former also accepts $obj1 being actual int. Whether it's useful or not depends on the surrounding code of course. > Another problem is that such automatic casting from objects to scalars > might obscure the code. True. I think this is one of the main reasons why it wasn't implemented. -- Stas Malyshev smalyshev@gmail.com