Re: Object Casting - An Alternative to Type Hinting

From: Date: Sun, 26 Feb 2012 16:12:51 +0000
Subject: Re: Object Casting - An Alternative to Type Hinting
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-58087@lists.php.net to get a copy of this message
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

« previous php.internals (#58087) next »