Re: type hinting

From: Date: Fri, 04 Jan 2008 19:06:09 +0000
Subject: Re: type hinting
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-34452@lists.php.net to get a copy of this message
On Fri, 2008-01-04 at 10:59 -0800, Stanislav Malyshev wrote: > > Not necessarily, if you have a function that performs a generic > > operation on any object. As for resources you are right, it might be > > Like what? I don't know many operations that are good for any object and > only object and need special function to perform them. Actually, > excluding scenarios like serialization and RPC (which should take care > of other types too so irrelevant here) I can't think of any right now. > > ideal to have "mysql resource" rather than just "resource", but just > > having the "resource" type hint is better than having no type hint. > > No, it's not better. Having GD image instead of mysql connection is not > better than having integer in any way. It would just produce different > error message, so what? That's actually very true. > > This is one that I find very useful, much more than it may seem. I use > > scalar for any type of post/get input, printed output, or DB > > interaction, as objects/arrays/resources cannot be printed or stored in > > a database in a standardized way. > > If you need serialization/printing, you have serialize() and > __toString() with respective handlers. If you reimplementing them and > using scalar restrictions, you most probably do it wrong. Ok but if someone inputs an array in the query string i have a problem with that. And I said standardized way, ie bool true outputs as "1", float 5.20 outputs as "5.2". For objects, toString is a standardized output but serialization is not, and for arrays no standardized output exists.

« previous php.internals (#34452) next »