cvs: /php4/ext/standard basic_functions.c
| From: | Andrey Zmievski | Date: | Fri, 16 Jul 1999 16:47:21 +0000 |
| Subject: | cvs: /php4/ext/standard basic_functions.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-2136@lists.php.net to get a copy of this message | ||
andrey Fri Jul 16 16:47:21 1999 EDT
Modified files:
/php4/ext/standard basic_functions.c
Log:
A little change in how array_splice/array_slice handle length parameter.
Makes it compatible with Perl.
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.44 php4/ext/standard/basic_functions.c:1.45
--- php4/ext/standard/basic_functions.c:1.44 Fri Jul 16 16:08:06 1999
+++ php4/ext/standard/basic_functions.c Fri Jul 16 16:47:20 1999
@@ -2454,7 +2454,9 @@
offset = 0;
/* ..and the length */
- if (length < 0 || offset+length > num_in)
+ if (length < 0)
+ length = num_in-offset+length;
+ else if(offset+length > num_in)
length = num_in-offset;
/* Create and initialize output hash */
@@ -2702,14 +2704,14 @@
}
/* Get the next two arguments. If length is omitted,
- it's assumed to be -1 */
+ it's assumed to be until the end of the array */
convert_to_long(args[1]);
offset = args[1]->value.lval;
if (argc > 2) {
convert_to_long(args[2]);
length = args[2]->value.lval;
} else
- length = -1;
+ length = zend_hash_num_elements(array->value.ht);
if (argc == 4) {
/* Make sure the last argument, if passed, is an array */
@@ -2782,7 +2784,7 @@
convert_to_long(length);
length_val = length->value.lval;
} else
- length_val = -1;
+ length_val = zend_hash_num_elements(input->value.ht);
/* Initialize returned array */
array_init(return_value);
@@ -2797,7 +2799,9 @@
offset_val = 0;
/* ..and the length */
- if (length_val < 0 || offset_val+length_val > num_in)
+ if (length_val < 0)
+ length_val = num_in-offset_val+length_val;
+ else if(offset_val+length_val > num_in)
length_val = num_in-offset_val;
if (length_val == 0)