Re: Object Casting - An Alternative to Type Hinting

From: Date: Sun, 26 Feb 2012 16:03:19 +0000
Subject: Re: Object Casting - An Alternative to Type Hinting
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-58086@lists.php.net to get a copy of this message
On Sun, 26 Feb 2012 16:39:10 +0100, Laruence <laruence@php.net> wrote:
On Sun, Feb 26, 2012 at 10:57 PM, Anthony Ferrara <ircmaxell@gmail.com> 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: <?php $xml = <<<XML <a>6.5</a> 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

« previous php.internals (#58086) next »