Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58133 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65174 invoked from network); 27 Feb 2012 15:12:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 15:12:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain l-i-e.com designates 67.139.134.202 as permitted sender) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:1127] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/A6-40985-D6D9B4F4 for ; Mon, 27 Feb 2012 10:12:45 -0500 Received: (qmail 87581 invoked by uid 98); 27 Feb 2012 15:12:45 -0000 Received: from localhost by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-2.05 ( Clear:RC:1(127.0.0.1):. Processed in 0.128261 secs); 27 Feb 2012 15:12:45 -0000 Received: from localhost (HELO www.l-i-e.com) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 15:12:44 -0000 Received: from webmail (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Mon, 27 Feb 2012 09:12:44 -0600 Message-ID: <2ae719b49f99d058544f11c462ce9c8a.squirrel@www.l-i-e.com> In-Reply-To: References: <4F4A5A03.1010103@php.net> Date: Mon, 27 Feb 2012 09:12:44 -0600 To: "Anthony Ferrara" Cc: "Stefan Neufeind" , internals@lists.php.net User-Agent: SquirrelMail/1.4.21 [SVN] MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: ceo@l-i-e.com ("Richard Lynch") On Sun, February 26, 2012 8:45 pm, Anthony Ferrara wrote: >> 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; I think you meant '.' here instead of '+' Otherwise, PHP type juggling will make it be 10 as well. > } > } > class Integer { > public function overload+($mixed) { > return $this->value + $mixed; > } > } > > $int = new Integer(5); > $string = 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. That said, there is no inconsistency. If what you want to do is overload + on strings to do concatenation, then it's on you to typecast everything to (string) for it to make sense. Oh, and string is a reserved word, so this won't work as-is, though that's obviously picuyane. -- brain cancer update: http://richardlynch.blogspot.com/search/label/brain%20tumor Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE