Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58112 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 915 invoked from network); 27 Feb 2012 02:45:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 02:45:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:56344] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/7A-40985-B5EEA4F4 for ; Sun, 26 Feb 2012 21:45:48 -0500 Received: by qcmt36 with SMTP id t36so552488qcm.29 for ; Sun, 26 Feb 2012 18:45:45 -0800 (PST) Received-SPF: pass (google.com: domain of ircmaxell@gmail.com designates 10.224.72.138 as permitted sender) client-ip=10.224.72.138; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ircmaxell@gmail.com designates 10.224.72.138 as permitted sender) smtp.mail=ircmaxell@gmail.com; dkim=pass header.i=ircmaxell@gmail.com Received: from mr.google.com ([10.224.72.138]) by 10.224.72.138 with SMTP id m10mr9441164qaj.95.1330310745180 (num_hops = 1); Sun, 26 Feb 2012 18:45:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Ape6nk9WuJLuvDhF5BUZGMZXGYUIFkwrsTNQ4iD6ZDc=; b=Bo9Upvyer4vJw0V4LoqjvklOhS/g5PSWpmnjZcV6eXEOgQHcezCDo3/CfIjLyYcHdM 1odIQyrg32YfVrG4hHs6esTKuNrr0wuE1kHXDarmhdUMR7pmwBEtdsKI1b4yGH7POJh2 92veMWt4818m/d5cDfnbAX04ARFk/SNiS4Ukg= MIME-Version: 1.0 Received: by 10.224.72.138 with SMTP id m10mr8016753qaj.95.1330310745058; Sun, 26 Feb 2012 18:45:45 -0800 (PST) Received: by 10.229.166.202 with HTTP; Sun, 26 Feb 2012 18:45:45 -0800 (PST) In-Reply-To: <4F4A5A03.1010103@php.net> References: <4F4A5A03.1010103@php.net> Date: Sun, 26 Feb 2012 21:45:45 -0500 Message-ID: To: Stefan Neufeind Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: ircmaxell@gmail.com (Anthony Ferrara) > Or operator-overlading to the rescue? :-) Not quite. Especially because with operator overloading done at this level (how it would be implemented in PHP) it's almost impossible to make it consistent: class string { public function overload+($mixed) { return $this->value + $mixed; } } class Integer { public function overload+($mixed) { return $this->value + $mixed; } } $int =3D new Integer(5); $string =3D new String("5"); echo $int + $string; // 10 echo $string + $int; // 55 While I like the concept of overloading, I don't really think it's solvable in a consistent enough manner that it would work here. On Sun, Feb 26, 2012 at 11:12 AM, Stefan Neufeind wrote: > On 02/26/2012 04:48 PM, Anthony Ferrara wrote: >>> I have to say, it doesn't get work, thinking this: >>> >>> $mixed1 =3D new Interger(2); >>> $mixed2 =3D new Interge(3); >>> $guess_what_type_is =3D $mixed1 + $mixed2; >>> >>> thanks >> >> That one is actually pretty straight forward. =A0Since `+` is a numeric >> operation (with the one exception of array + array), it would call >> castTo('numeric') on both. =A0Then, the normal type rules would take >> over. =A0So if it returned an int, the result would be int(5). =A0If 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=3D9331 > http://pecl.php.net/package/operator > ) > > > Regards, > =A0Stefan > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >