Re: optional type hinting enhancements

From: Date: Mon, 19 Jan 2009 14:31:47 +0000
Subject: Re: optional type hinting enhancements
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-286657@lists.php.net to get a copy of this message
On Sun, 2009-01-18 at 23:09 +0000, Nathan Rixham wrote: > Török Alpár wrote: > > I see a problem with this. Scalars are automatically casted by PHP based on > > a set of rules. In case of a scalar type hint, would jo issue an error, or > > make the automatic type cast? both approaches have there advantages, but > > the automatic cast, would go better with the actual features of the > > language, but in this case, object could also cast an array to stdClass, and > > i am not sure that's how you imagined it. Besides this i am not against it > > along as it doens't create implementaion nor performance problems, and this > > problem is solved. > > I see what you mean with the casts; and a very good point on why scalars > aren't already implemented.. > > On the one hand i see scope for a set of primative wrappers (class > String, Integer, Boolean etc) which those who wished could use (with an > auto cast). > > Whilst on the other hand it could be argued that the current is_xxx > functionality could be copied so an integer in a string is still a > string, likewise 1 is an integer not a boolean true etc etc. > > defintaly needs some thought and practical examples though.. rfc time > one thinks. > > with the specific array example, this is already implemented so no > problems there, what is not implemented though is the ability to > function(object $obj) which seems strange. > > as for the error, same as it is currently E_RECOVERABLE_ERROR and def > not automatic type casting; last thing you want when trying to be strict > is anything like that :p Some of you really need to go trawl the internals archives. This stuff was discussed in poignant detail about a year or so ago. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#286657) next »