2009/1/19 Nathan Rixham <nrixham@xxxxxxxxx> > 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. if a cast is made, and $obj is in fact an array, the outcome may not be what you wanted. This one is even trickier, since you may expect an error here, given that you have type hinting for specific object types. > > > 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 agree, but that would make static types behave differently than they currently are. With some wrapper classes, you might end up with the same trouble, you can type hint Integer, and send a scalar string that contains an integer, then you are back to the good old casting rules. > > > thanks for the input! > i think that this functionality is worth talking about, but the point is to integrate this with the way PHP does things right now, you can't take the Java model as is, and apply it to PHP, there is a devil in the details. -- Torok, Alpar Istvan