Re: question regarding type hinting parameters of php functions (array_slice)
| From: | Moritz Bechler | Date: | Wed, 28 Nov 2007 13:07:31 +0000 |
| Subject: | Re: question regarding type hinting parameters of php functions (array_slice) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33485@lists.php.net to get a copy of this message | ||
Hi,
>
>> 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.
>
> i think this should print a warning like other array functions.
> But i looked into the src and this looks more like a casting bug inside this
> function.
Actually most functions use implicit type conversions for this. So I
wouldn't say this should cause a warning.
>
>
> So i think the float value isnt correct casted as int value here. Maybe
> someone else
> can proof this.
Yes, you are right here I think....
the code is
if (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(length_param) != IS_NULL) {
length = Z_LVAL_P(length_param);
} else {
length = num_in;
}
and afaik should be
if (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(length_param) != IS_NULL) {
convert_to_long(length_param);
length = Z_LVAL_P(length_param);
} else {
length = num_in;
}
best regards
Moritz Bechler