Re: Return type hints

From: Date: Wed, 13 Sep 2006 11:41:42 +0000
Subject: Re: Return type hints
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-25658@lists.php.net to get a copy of this message
""Richard Quadling"" <rquadling@googlemail.com> schreef in bericht news:10845a340609130401q20127db0yf8e30f781622c63@mail.gmail.com... > On 13/09/06, Terje Slettebø <tslettebo@broadpark.no> wrote: .......... > The issue then becomes what would happen to a value of the wrong type? > > You either have the option of using PHP's own internal casting > mechanism, so f(int $i_int_expected) would internally cast the > supplied parameter as an int or you have to produce a WARNING with a > "parameter of the wrong type" message. But then what is passed to the > function? This would have to be determined somehow. I think it would make sense to turn the value into NULL when the casting fails. And honestly, I would love this kind of type hinting. It has to be smart in the sense that if I say "double", and it's a string containing "0.123", it will either be casted to a double (which may be unfortunate, since floats and doubles are inaccurate), or simply let through as a string, because it follows double formatting (that being /-?[0-9]+(\.[0-9]+)?/). But this way type hinting for core types is only optional for people and it's not as strict as in the vast majority of other languages out there. This kind of smart type hinting would be simply perfect. Ron

« previous php.internals (#25658) next »