Right, that's what "l" parameter spec is doing, doesn't it? Why convert
it manually?
Because it doesn't know the difference between NULL and 0 if it's a long.
And why this difference is important in array_slice()? I don't see
anything in manual that says anything about NULLs. Could you explain?
There's an IS_NULL check...
if (ZEND_NUM_ARGS() >= 3 && Z_TYPE_P(length_param) != IS_NULL) { ....
If Z_TYPE_P(length_param) is 0, it's not NULL because it has something in
it. If length_param were of type long and had a value of 0, it would be
NULL.
The manual kind of skirts around it: "If length is given and is positive,
then the sequence will have that many elements in it. If length is given and
is negative then the sequence will stop that many elements from the end of
the array. If it is omitted, then the sequence will have everything from
offset up until the end of the array ."
One that doesn't break every script that didn't strictly stay with int
over the last 8 years or so.
Actually that check hasn't been there forever, behaviour's different again
in 5.1* - I didn't realize that. It used to always mean 0 (!) and was
changed in 5.2.3 in response to a bug report:
http://bugs.php.net/bug.php?id=41686.
Errm... I still don't understand. Could you give code example?
C:\Documents and Settings\Steph\Desktop\PHP versions\5_1_2>php -a
Interactive mode enabled
<?php
$arr = array(1,2,3);
var_dump(array_slice($arr, 0, 0));
array(0) {
}
var_dump(array_slice($arr, 0, null));
array(0) {
}
C:\Documents and Settings\Steph\Desktop\PHP versions\5_2_4>php -a
Interactive mode enabled
<?php
$arr = array(1,2,3);
var_dump(array_slice($arr, 0, 0));
array(0) {
}
var_dump(array_slice($arr, 0, null));
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
I think 0 and NULL should both always have acted like NULL does in 5_2_4
(which would happen if the third parameter was a long), but since 0 has
always acted wrongly it's possible that people are relying on that
behaviour. There's also the side-issue that every type has always been
allowed in that argument, whether it makes sense or not.
- Steph
ps the patch on my bug report is now out of date (again).
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED] http://www.zend.com/
(408)253-8829 MSN: [EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php