Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86204 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 108 invoked from network); 13 May 2015 23:45:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2015 23:45:58 -0000 Authentication-Results: pb1.pair.com header.from=guiwoda@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=guiwoda@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.169 as permitted sender) X-PHP-List-Original-Sender: guiwoda@gmail.com X-Host-Fingerprint: 209.85.223.169 mail-ie0-f169.google.com Received: from [209.85.223.169] ([209.85.223.169:35407] helo=mail-ie0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/80-31470-532E3555 for ; Wed, 13 May 2015 19:45:58 -0400 Received: by iebpz10 with SMTP id pz10so46945671ieb.2 for ; Wed, 13 May 2015 16:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-type; bh=XQxHK0744ul95hAkYGz3dI+OYZemId1s6MXkRnFIgxY=; b=UkWcbchfm++R1F/crIpFZxL+yFSs4e1sElrlob2ya5GQ/ujCUGyqoijfUiszJxFXlQ tzIiszKQfrlzwknwTj6gUg05p4rH1FuzXXv+CgCxeeH+cGGcLgSHB7qs9DOfV5OUVPnj g/QNeAArhDXYI8AHRNup9HHd78wwjCNhfd3Vkac5eMh0DadnVKSMFgMMBTQnAhi4TMxJ AHO8yveEQL3G7PJqzQWDdIS0ruVa0HmJ4R3oEc1MjXD7eFSnRd53djLCNZmvH6HX7SRq brxPBClRpLfknN49r0KA4DvH0TotV/MMx6W8XLNYi9IXJ+jZ/MTRlQsVbakIBKekPfYN Gv3w== X-Received: by 10.42.226.8 with SMTP id iu8mr11482386icb.17.1431560755021; Wed, 13 May 2015 16:45:55 -0700 (PDT) MIME-Version: 1.0 References: <5553E139.8090805@gmx.de> In-Reply-To: <5553E139.8090805@gmx.de> Date: Wed, 13 May 2015 23:45:54 +0000 Message-ID: To: Christoph Becker , internals@lists.php.net Content-Type: multipart/alternative; boundary=001a11c30f9e470d700515ff3619 Subject: Re: Proposal: interfaces for object to scalar type casting From: guiwoda@gmail.com (Guido Contreras Woda) --001a11c30f9e470d700515ff3619 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I do agree that, if I'm the owner and responsible for the object in question, adding an explicit method would be better than casting it. The problem is that many times we are dealing with third party libraries, and modifying them is more complicated. But it is true, and it is true that the number types would collide if both could be used. That could issue an E_NOTICE if not force casted, and default to one of the types (as unquoted strings do). El mi=C3=A9., 13 de may. de 2015 a la(s) 8:41 p. m., Christoph Becker < cmbecker69@gmx.de> escribi=C3=B3: > Guido Contreras Woda wrote: > > > So, what do you think of a set of interfaces that allow userland object= s > 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 > > > --001a11c30f9e470d700515ff3619--