Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58087 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46112 invoked from network); 26 Feb 2012 16:13:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2012 16:13:50 -0000 Authentication-Results: pb1.pair.com header.from=neufeind@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=neufeind@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 91.184.32.3 as permitted sender) X-PHP-List-Original-Sender: neufeind@php.net X-Host-Fingerprint: 91.184.32.3 mail.speedpartner.de Linux 2.5 (sometimes 2.4) (4) Received: from [91.184.32.3] ([91.184.32.3:54213] helo=mail.speedpartner.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/E0-40985-D3A5A4F4 for ; Sun, 26 Feb 2012 11:13:50 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.speedpartner.de (Postfix) with ESMTP id 522FFB3CCF for ; Sun, 26 Feb 2012 17:13:46 +0100 (CET) Received: from mail.speedpartner.de ([127.0.0.1]) by localhost (mail.speedpartner.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ktcDagRw5ciR for ; Sun, 26 Feb 2012 17:13:46 +0100 (CET) Received: from collab.speedpartner.de (collab.speedpartner.de [91.184.32.10]) by mail.speedpartner.de (Postfix) with ESMTP id 3DF09B3ADD for ; Sun, 26 Feb 2012 17:13:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by collab.speedpartner.de (Postfix) with ESMTP id E7E97CA50E9 for ; Sun, 26 Feb 2012 17:13:44 +0100 (CET) X-Virus-Scanned: amavisd-new at collab.speedpartner.de Received: from collab.speedpartner.de ([127.0.0.1]) by localhost (collab.speedpartner.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Lgjl5o10UJ5W for ; Sun, 26 Feb 2012 17:13:44 +0100 (CET) Received: from [192.168.4.20] (ip-62-143-28-82.unitymediagroup.de [62.143.28.82]) by collab.speedpartner.de (Postfix) with ESMTPSA id E5F0DCA50DE for ; Sun, 26 Feb 2012 17:13:43 +0100 (CET) Message-ID: <4F4A5A03.1010103@php.net> Date: Sun, 26 Feb 2012 17:12:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: neufeind@php.net (Stefan Neufeind) On 02/26/2012 04:48 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; >> >> thanks > > That one is actually pretty straight forward. Since `+` is a numeric > operation (with the one exception of array + array), it would call > castTo('numeric') on both. Then, the normal type rules would take > over. So if it returned an int, the result would be int(5). If it > returned a float, it would be float(5)... Or operator-overlading to the rescue? :-) (Okay, I know that idea has been burried a long time ago - but might come in hand here as well. http://bugs.php.net/bug.php?id=9331 http://pecl.php.net/package/operator ) Regards, Stefan