Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58086 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44347 invoked from network); 26 Feb 2012 16:03:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2012 16:03:23 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:39485] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/80-40985-7C75A4F4 for ; Sun, 26 Feb 2012 11:03:21 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id AFA9270003D2; Sun, 26 Feb 2012 16:03:16 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id B7fpRzSc5BRP; Sun, 26 Feb 2012 16:03:16 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 39DE0700044F; Sun, 26 Feb 2012 16:03:16 +0000 (WET) Received: from damnation.mshome.net (damnation-air.nl.lo.geleia.net [IPv6:2001:470:94a2:4:7d06:1af1:ea64:2d52]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id A25F4200882A; Sun, 26 Feb 2012 16:03:14 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Anthony Ferrara" , Laruence Cc: internals@lists.php.net References: Date: Sun, 26 Feb 2012 17:03:19 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/11.61 (Win32) Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sun, 26 Feb 2012 16:39:10 +0100, Laruence wrote: > On Sun, Feb 26, 2012 at 10:57 PM, Anthony Ferrara > wrote: > > I have to say, it doesn't get work, thinking this: > > $mixed1 = new Interger(2); > $mixed2 = new Interge(3); > $guess_what_type_is = $mixed1 + $mixed2; > Actually, this part of the problem can be pretty much be implemented today for internal classes with the cast_object[1] or get[2] handlers. There are of course some difficulties, like the nonexistence of a numeric cast, which, by the way, has caused some trouble because the Zend Engine defaults to cast to an integer in a numerical situation instead of a float. This has causes a known bug in SimpleXML: 6.5 XML; $sxml = new simplexmlelement($xml); $r = 4 + $sxml; echo $r; //10, not 10.5 The other side (cast from) is more problematic, not entirely satisfactory to the people that have proposed autoboxing in the past, which would like to be able to do $a = 1; $a->blah(). [1] https://wiki.php.net/internals/engine/objects#cast_object [2] https://wiki.php.net/internals/engine/objects#get -- Gustavo Lopes