Re: question regarding type hinting parameters of php functions
| From: | T . Lensselink | Date: | Mon, 26 Nov 2007 10:45:02 +0000 |
| Subject: | Re: question regarding type hinting parameters of php functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265018@lists.php.net to get a copy of this message | ||
On Mon, 26 Nov 2007 10:29:40 +0100, Dirk Thomas / 4wd media
<dirk.thomas@4wdmedia.de> wrote:
> Hi,
>
> i have tried a current snapshot of PHP 5.3 and have a question regarding
> type hinting.
>
> For example when using the function
> "array_slice(array $array, int $offset, int $length)"
> with a non-integer length parameter, what is the desired behavior?
>
> When calling
> "array_slice($array, 0, (float)2);"
> the resulting array is EMPTY.
> When using the right type
> "array_slice($array, 0, (int)2);"
> it works as expected.
>
> Shouldn't there be a notice/warning than just a wrong return value?
> In my case there is neither a warning nor does it work as expected.
> (perhaps it do something wrong?)
>
> Of course i can use int's, but in my opinion either a warning should be
> given or the function should gracefully handle the wrong typed parameter.
>
> Thank you for any feedback,
> Dirk
>
I think there should at least be a notice. It's propably better to ask this
on the internals list.