From ec2332be93272d202a2a5cef841c266f77f64b08 Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Mon, 14 May 2018 15:07:13 +0200 Subject: [PATCH 1/4] Add implementation and tests for new methods - array_key_first(array $a) Returns the key of the first element or null - array_key_last(array $a) Returns the key of the last element or null --- Zend/zend_hash.c | 5 + Zend/zend_hash.h | 1 + ext/standard/array.c | 33 +++ ext/standard/basic_functions.c | 10 + ext/standard/php_array.h | 2 + ext/standard/tests/array/array_key_first.phpt | 214 ++++++++++++++++++ .../tests/array/array_key_first_errors.phpt | 52 +++++ .../array/array_key_first_variation.phpt | 36 +++ ext/standard/tests/array/array_key_last.phpt | 214 ++++++++++++++++++ .../tests/array/array_key_last_errors.phpt | 52 +++++ .../tests/array/array_key_last_variation.phpt | 36 +++ 11 files changed, 655 insertions(+) create mode 100644 ext/standard/tests/array/array_key_first.phpt create mode 100644 ext/standard/tests/array/array_key_first_errors.phpt create mode 100644 ext/standard/tests/array/array_key_first_variation.phpt create mode 100644 ext/standard/tests/array/array_key_last.phpt create mode 100644 ext/standard/tests/array/array_key_last_errors.phpt create mode 100644 ext/standard/tests/array/array_key_last_variation.phpt diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 817254774ccc..361d963990f5 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -373,6 +373,11 @@ static zend_always_inline HashPosition _zend_hash_get_current_pos(const HashTabl return pos; } +ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_first_pos(const HashTable *ht) +{ + return _zend_hash_get_first_pos(ht); +} + ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht) { return _zend_hash_get_current_pos(ht); diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 220bccbb7621..8c1ea7073b4b 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -232,6 +232,7 @@ ZEND_API zend_bool ZEND_FASTCALL zend_hash_str_exists(const HashTable *ht, const ZEND_API zend_bool ZEND_FASTCALL zend_hash_index_exists(const HashTable *ht, zend_ulong h); /* traversing */ +ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_first_pos(const HashTable *ht); ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht); #define zend_hash_has_more_elements_ex(ht, pos) \ diff --git a/ext/standard/array.c b/ext/standard/array.c index 7621b0616a5b..2866e2a2e609 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4016,6 +4016,39 @@ PHP_FUNCTION(array_keys) } /* }}} */ +/* {{{ proto mixed array_key_first(array stack) + Get the key of the first element of the array */ +PHP_FUNCTION(array_key_first) +{ + zval *stack; /* Input stack */ + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(stack, 0, 1) + ZEND_PARSE_PARAMETERS_END(); + + HashTable *target_hash = HASH_OF(stack); + HashPosition pos = zend_hash_get_first_pos(target_hash); + zend_hash_get_current_key_zval_ex(target_hash, return_value, &pos); +} +/* }}} */ + +/* {{{ proto mixed array_key_last(array stack) + Get the key of the last element of the array */ +PHP_FUNCTION(array_key_last) +{ + zval *stack; /* Input stack */ + HashPosition pos; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(stack, 0, 1) + ZEND_PARSE_PARAMETERS_END(); + + HashTable *target_hash = HASH_OF(stack); + zend_hash_internal_pointer_end_ex(target_hash, &pos); + zend_hash_get_current_key_zval_ex(target_hash, return_value, &pos); +} +/* }}} */ + /* {{{ proto array array_values(array input) Return just the values from the input array */ PHP_FUNCTION(array_values) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 740e7333ed6b..494de40fce3e 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -422,6 +422,14 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_values, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_array_key_first, 0) + ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_array_key_last, 0) + ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_array_count_values, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() @@ -3362,6 +3370,8 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(array_replace, arginfo_array_replace) PHP_FE(array_replace_recursive, arginfo_array_replace_recursive) PHP_FE(array_keys, arginfo_array_keys) + PHP_FE(array_key_first, arginfo_array_key_first) + PHP_FE(array_key_last, arginfo_array_key_last) PHP_FE(array_values, arginfo_array_values) PHP_FE(array_count_values, arginfo_array_count_values) PHP_FE(array_column, arginfo_array_column) diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index b438dd64f1f1..f227365a1fe0 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -69,6 +69,8 @@ PHP_FUNCTION(array_merge_recursive); PHP_FUNCTION(array_replace); PHP_FUNCTION(array_replace_recursive); PHP_FUNCTION(array_keys); +PHP_FUNCTION(array_key_first); +PHP_FUNCTION(array_key_last); PHP_FUNCTION(array_values); PHP_FUNCTION(array_count_values); PHP_FUNCTION(array_column); diff --git a/ext/standard/tests/array/array_key_first.phpt b/ext/standard/tests/array/array_key_first.phpt new file mode 100644 index 000000000000..1433efae8a55 --- /dev/null +++ b/ext/standard/tests/array/array_key_first.phpt @@ -0,0 +1,214 @@ +--TEST-- +Test array_key_first() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + print_r( $sub_array ); + echo "\nFirst key is :\n"; + var_dump( array_key_first($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +First key is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +First key is : +int(0) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +First key is : +int(0) + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +First key is : +int(0) + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +First key is : +string(1) "a" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +First key is : +int(1) + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +First key is : +int(1) + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +First key is : +string(1) "f" + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +First key is : +int(0) + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +First key is : +int(0) + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +First key is : +string(3) "one" + +Done diff --git a/ext/standard/tests/array/array_key_first_errors.phpt b/ext/standard/tests/array/array_key_first_errors.phpt new file mode 100644 index 000000000000..ad2c52b6a0c6 --- /dev/null +++ b/ext/standard/tests/array/array_key_first_errors.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_key_first() function (errors) +--FILE-- + +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_key_first() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_key_first() expects parameter 1 to be array, int given in %s on line %d +NULL + +Warning: array_key_first() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_key_first() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +Done diff --git a/ext/standard/tests/array/array_key_first_variation.phpt b/ext/standard/tests/array/array_key_first_variation.phpt new file mode 100644 index 000000000000..d619ed012231 --- /dev/null +++ b/ext/standard/tests/array/array_key_first_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_first() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_key_first *** + +Current Element is : int(1) + +Next Element is : int(2) + +First key is : int(0) + +Current Element after array_key_first operation is: int(2) + +Done diff --git a/ext/standard/tests/array/array_key_last.phpt b/ext/standard/tests/array/array_key_last.phpt new file mode 100644 index 000000000000..66d3035be5b1 --- /dev/null +++ b/ext/standard/tests/array/array_key_last.phpt @@ -0,0 +1,214 @@ +--TEST-- +Test array_key_last() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + print_r( $sub_array ); + echo "\nLast key is :\n"; + var_dump( array_key_last($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +Last key is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +Last key is : +int(8) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +Last key is : +int(4) + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +Last key is : +int(7) + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +Last key is : +string(1) "e" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +Last key is : +int(5) + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +Last key is : +int(5) + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +Last key is : +string(1) "a" + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +Last key is : +int(3) + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +Last key is : +int(2) + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +Last key is : +string(3) "5.7" + +Done diff --git a/ext/standard/tests/array/array_key_last_errors.phpt b/ext/standard/tests/array/array_key_last_errors.phpt new file mode 100644 index 000000000000..88f8c9ffdd85 --- /dev/null +++ b/ext/standard/tests/array/array_key_last_errors.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_key_last() function (errors) +--FILE-- + +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_key_last() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_key_last() expects parameter 1 to be array, int given in %s on line %d +NULL + +Warning: array_key_last() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_key_last() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +Done diff --git a/ext/standard/tests/array/array_key_last_variation.phpt b/ext/standard/tests/array/array_key_last_variation.phpt new file mode 100644 index 000000000000..3b2a48673ebd --- /dev/null +++ b/ext/standard/tests/array/array_key_last_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_last() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_key_last *** + +Current Element is : int(1) + +Next Element is : int(2) + +Last key is : int(8) + +Current Element after array_key_last operation is: int(2) + +Done From 780b05e6478d3bfdb6cd3e3e575dcdff2dbf5848 Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Tue, 19 Jun 2018 11:28:01 +0200 Subject: [PATCH 2/4] Extend the implementation to also cover the functions * array_value_first($array) * array_value_last($array) to handle the values of the outer array elements --- Zend/zend_hash.c | 5 - ext/standard/array.c | 52 ++++- ext/standard/basic_functions.c | 15 +- ext/standard/php_array.h | 2 + .../tests/array/array_value_first.phpt | 221 ++++++++++++++++++ .../tests/array/array_value_first_errors.phpt | 52 +++++ .../array/array_value_first_variation.phpt | 36 +++ .../tests/array/array_value_last.phpt | 215 +++++++++++++++++ .../tests/array/array_value_last_errors.phpt | 52 +++++ .../array/array_value_last_variation.phpt | 36 +++ 10 files changed, 678 insertions(+), 8 deletions(-) create mode 100644 ext/standard/tests/array/array_value_first.phpt create mode 100644 ext/standard/tests/array/array_value_first_errors.phpt create mode 100644 ext/standard/tests/array/array_value_first_variation.phpt create mode 100644 ext/standard/tests/array/array_value_last.phpt create mode 100644 ext/standard/tests/array/array_value_last_errors.phpt create mode 100644 ext/standard/tests/array/array_value_last_variation.phpt diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 361d963990f5..817254774ccc 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -373,11 +373,6 @@ static zend_always_inline HashPosition _zend_hash_get_current_pos(const HashTabl return pos; } -ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_first_pos(const HashTable *ht) -{ - return _zend_hash_get_first_pos(ht); -} - ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht) { return _zend_hash_get_current_pos(ht); diff --git a/ext/standard/array.c b/ext/standard/array.c index 2866e2a2e609..bb984f72b60c 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4027,7 +4027,7 @@ PHP_FUNCTION(array_key_first) ZEND_PARSE_PARAMETERS_END(); HashTable *target_hash = HASH_OF(stack); - HashPosition pos = zend_hash_get_first_pos(target_hash); + HashPosition pos = 0; zend_hash_get_current_key_zval_ex(target_hash, return_value, &pos); } /* }}} */ @@ -4094,6 +4094,56 @@ PHP_FUNCTION(array_values) } /* }}} */ +/* {{{ array_value_result_helper + * Get a value out of a HashTable at the given position and copy the value into return_value. + */ +static inline +void array_value_result_helper(HashTable *ht, HashPosition *pos, zval *return_value) +{ + zval* array_value = zend_hash_get_current_data_ex(ht, pos); + + if (array_value == NULL) { + ZVAL_NULL(return_value); + return; + } + + ZVAL_COPY(return_value, array_value); +} +/* }}} */ + +/* {{{ proto mixed array_value_first(array stack) + Get the value of the first element of the array */ +PHP_FUNCTION(array_value_first) +{ + zval *stack; /* Input stack */ + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(stack, 0, 1) + ZEND_PARSE_PARAMETERS_END(); + + HashTable *target_hash = HASH_OF(stack); + HashPosition pos = 0; + array_value_result_helper(target_hash, &pos, return_value); +} +/* }}} */ + +/* {{{ proto mixed array_value_last(array stack) + Get the value of the last element of the array */ +PHP_FUNCTION(array_value_last) +{ + zval *stack; /* Input stack */ + HashPosition pos; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(stack, 0, 1) + ZEND_PARSE_PARAMETERS_END(); + + HashTable *target_hash = HASH_OF(stack); + zend_hash_internal_pointer_end_ex(target_hash, &pos); + array_value_result_helper(target_hash, &pos, return_value); +} +/* }}} */ + /* {{{ proto array array_count_values(array input) Return the value as key and the frequency of that value in input as value */ PHP_FUNCTION(array_count_values) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 494de40fce3e..f3c858e714e0 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -418,15 +418,24 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_array_keys, 0, 0, 1) ZEND_ARG_INFO(0, strict) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_array_key_first, 0) + ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_array_key_last, 0) + ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ +ZEND_END_ARG_INFO() + + ZEND_BEGIN_ARG_INFO(arginfo_array_values, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_array_key_first, 0) +ZEND_BEGIN_ARG_INFO(arginfo_array_value_first, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_array_key_last, 0) +ZEND_BEGIN_ARG_INFO(arginfo_array_value_last, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() @@ -3373,6 +3382,8 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(array_key_first, arginfo_array_key_first) PHP_FE(array_key_last, arginfo_array_key_last) PHP_FE(array_values, arginfo_array_values) + PHP_FE(array_value_first, arginfo_array_value_first) + PHP_FE(array_value_last, arginfo_array_value_last) PHP_FE(array_count_values, arginfo_array_count_values) PHP_FE(array_column, arginfo_array_column) PHP_FE(array_reverse, arginfo_array_reverse) diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index f227365a1fe0..b9989d51e820 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -72,6 +72,8 @@ PHP_FUNCTION(array_keys); PHP_FUNCTION(array_key_first); PHP_FUNCTION(array_key_last); PHP_FUNCTION(array_values); +PHP_FUNCTION(array_value_first); +PHP_FUNCTION(array_value_last); PHP_FUNCTION(array_count_values); PHP_FUNCTION(array_column); PHP_FUNCTION(array_reverse); diff --git a/ext/standard/tests/array/array_value_first.phpt b/ext/standard/tests/array/array_value_first.phpt new file mode 100644 index 000000000000..440ae699abe8 --- /dev/null +++ b/ext/standard/tests/array/array_value_first.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test array_value_first() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + print_r( $sub_array ); + echo "\nFirst value is :\n"; + var_dump( array_value_first($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +First value is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +First value is : +int(1) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +First value is : +string(3) "One" + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +First value is : +int(6) + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +First value is : +string(3) "aaa" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +First value is : +string(3) "one" + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +First value is : +string(3) "one" + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +First value is : +string(3) "fff" + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +First value is : +int(12) + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +First value is : +array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) +} + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +First value is : +int(2) + +Done diff --git a/ext/standard/tests/array/array_value_first_errors.phpt b/ext/standard/tests/array/array_value_first_errors.phpt new file mode 100644 index 000000000000..5502bee9d685 --- /dev/null +++ b/ext/standard/tests/array/array_value_first_errors.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_value_first() function (errors) +--FILE-- + +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_value_first() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_value_first() expects parameter 1 to be array, int given in %s on line %d +NULL + +Warning: array_value_first() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_value_first() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +Done diff --git a/ext/standard/tests/array/array_value_first_variation.phpt b/ext/standard/tests/array/array_value_first_variation.phpt new file mode 100644 index 000000000000..f400c23ee1e4 --- /dev/null +++ b/ext/standard/tests/array/array_value_first_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_value_first() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_value_first *** + +Current Element is : int(1) + +Next Element is : int(2) + +First value is : int(1) + +Current Element after array_value_first operation is: int(2) + +Done diff --git a/ext/standard/tests/array/array_value_last.phpt b/ext/standard/tests/array/array_value_last.phpt new file mode 100644 index 000000000000..9f790ec8a91f --- /dev/null +++ b/ext/standard/tests/array/array_value_last.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test array_value_last() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + print_r( $sub_array ); + echo "\nLast value is :\n"; + var_dump( array_value_last($sub_array) ); + $counter++; +} + +echo"\nDone"; +?> +--EXPECT-- +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +Last value is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +Last value is : +int(9) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +Last value is : +string(4) "Five" + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +Last value is : +string(4) "nine" + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +Last value is : +string(3) "eee" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +Last value is : +string(4) "five" + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +Last value is : +string(4) "five" + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +Last value is : +NULL + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +Last value is : +string(2) "45" + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +Last value is : +array(0) { +} + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +Last value is : +int(557) + +Done diff --git a/ext/standard/tests/array/array_value_last_errors.phpt b/ext/standard/tests/array/array_value_last_errors.phpt new file mode 100644 index 000000000000..309a53ed9fb0 --- /dev/null +++ b/ext/standard/tests/array/array_value_last_errors.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_value_last() function (errors) +--FILE-- + +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_value_last() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_value_last() expects parameter 1 to be array, int given in %s on line %d +NULL + +Warning: array_value_last() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_value_last() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +Done diff --git a/ext/standard/tests/array/array_value_last_variation.phpt b/ext/standard/tests/array/array_value_last_variation.phpt new file mode 100644 index 000000000000..42e26d2afa53 --- /dev/null +++ b/ext/standard/tests/array/array_value_last_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_value_last() function (variation) +--FILE-- + +--EXPECT-- +*** Checking for internal array pointer not being changed by array_value_last *** + +Current Element is : int(1) + +Next Element is : int(2) + +Last value is : int(9) + +Current Element after array_value_last operation is: int(2) + +Done From 03803ebac9e051153088ae833f006b35e85c4eee Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Tue, 19 Jun 2018 19:40:02 +0200 Subject: [PATCH 3/4] Remove unimplemented function from zend_hash.h which was used in a former implementation approach --- Zend/zend_hash.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 8c1ea7073b4b..220bccbb7621 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -232,7 +232,6 @@ ZEND_API zend_bool ZEND_FASTCALL zend_hash_str_exists(const HashTable *ht, const ZEND_API zend_bool ZEND_FASTCALL zend_hash_index_exists(const HashTable *ht, zend_ulong h); /* traversing */ -ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_first_pos(const HashTable *ht); ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos(const HashTable *ht); #define zend_hash_has_more_elements_ex(ht, pos) \ From f9ca90d8ae041bcfc4355e32a0fb12c9f69d535a Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Tue, 17 Jul 2018 10:29:55 +0200 Subject: [PATCH 4/4] Remove declined functions array_value_first() and array_value_last() Add additional test cases for array_key_first() and array_key_last() --- ext/standard/array.c | 50 ---- ext/standard/basic_functions.c | 10 - ext/standard/php_array.h | 2 - ext/standard/tests/array/array_key_first.phpt | 22 +- ext/standard/tests/array/array_key_last.phpt | 22 +- .../tests/array/array_value_first.phpt | 221 ------------------ .../tests/array/array_value_first_errors.phpt | 52 ----- .../array/array_value_first_variation.phpt | 36 --- .../tests/array/array_value_last.phpt | 215 ----------------- .../tests/array/array_value_last_errors.phpt | 52 ----- .../array/array_value_last_variation.phpt | 36 --- 11 files changed, 42 insertions(+), 676 deletions(-) delete mode 100644 ext/standard/tests/array/array_value_first.phpt delete mode 100644 ext/standard/tests/array/array_value_first_errors.phpt delete mode 100644 ext/standard/tests/array/array_value_first_variation.phpt delete mode 100644 ext/standard/tests/array/array_value_last.phpt delete mode 100644 ext/standard/tests/array/array_value_last_errors.phpt delete mode 100644 ext/standard/tests/array/array_value_last_variation.phpt diff --git a/ext/standard/array.c b/ext/standard/array.c index bb984f72b60c..4e45cc64c664 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4094,56 +4094,6 @@ PHP_FUNCTION(array_values) } /* }}} */ -/* {{{ array_value_result_helper - * Get a value out of a HashTable at the given position and copy the value into return_value. - */ -static inline -void array_value_result_helper(HashTable *ht, HashPosition *pos, zval *return_value) -{ - zval* array_value = zend_hash_get_current_data_ex(ht, pos); - - if (array_value == NULL) { - ZVAL_NULL(return_value); - return; - } - - ZVAL_COPY(return_value, array_value); -} -/* }}} */ - -/* {{{ proto mixed array_value_first(array stack) - Get the value of the first element of the array */ -PHP_FUNCTION(array_value_first) -{ - zval *stack; /* Input stack */ - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY_EX(stack, 0, 1) - ZEND_PARSE_PARAMETERS_END(); - - HashTable *target_hash = HASH_OF(stack); - HashPosition pos = 0; - array_value_result_helper(target_hash, &pos, return_value); -} -/* }}} */ - -/* {{{ proto mixed array_value_last(array stack) - Get the value of the last element of the array */ -PHP_FUNCTION(array_value_last) -{ - zval *stack; /* Input stack */ - HashPosition pos; - - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY_EX(stack, 0, 1) - ZEND_PARSE_PARAMETERS_END(); - - HashTable *target_hash = HASH_OF(stack); - zend_hash_internal_pointer_end_ex(target_hash, &pos); - array_value_result_helper(target_hash, &pos, return_value); -} -/* }}} */ - /* {{{ proto array array_count_values(array input) Return the value as key and the frequency of that value in input as value */ PHP_FUNCTION(array_count_values) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f3c858e714e0..543af5ef34ca 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -431,14 +431,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_values, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_array_value_first, 0) - ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_array_value_last, 0) - ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO(arginfo_array_count_values, 0) ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */ ZEND_END_ARG_INFO() @@ -3382,8 +3374,6 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(array_key_first, arginfo_array_key_first) PHP_FE(array_key_last, arginfo_array_key_last) PHP_FE(array_values, arginfo_array_values) - PHP_FE(array_value_first, arginfo_array_value_first) - PHP_FE(array_value_last, arginfo_array_value_last) PHP_FE(array_count_values, arginfo_array_count_values) PHP_FE(array_column, arginfo_array_column) PHP_FE(array_reverse, arginfo_array_reverse) diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index b9989d51e820..f227365a1fe0 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -72,8 +72,6 @@ PHP_FUNCTION(array_keys); PHP_FUNCTION(array_key_first); PHP_FUNCTION(array_key_last); PHP_FUNCTION(array_values); -PHP_FUNCTION(array_value_first); -PHP_FUNCTION(array_value_last); PHP_FUNCTION(array_count_values); PHP_FUNCTION(array_column); PHP_FUNCTION(array_reverse); diff --git a/ext/standard/tests/array/array_key_first.phpt b/ext/standard/tests/array/array_key_first.phpt index 1433efae8a55..62353860044b 100644 --- a/ext/standard/tests/array/array_key_first.phpt +++ b/ext/standard/tests/array/array_key_first.phpt @@ -19,7 +19,9 @@ $mixed_array = array( array( 12, "name", 'age', '45' ), array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, - 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ), + array( "foo" ), + array( 1 => "42" ) ); /* Loop to test normal functionality with different arrays inputs */ @@ -211,4 +213,22 @@ Array First key is : string(3) "one" +-- Input Array for Iteration 12 is -- +Array +( + [0] => foo +) + +First key is : +int(0) + +-- Input Array for Iteration 13 is -- +Array +( + [1] => 42 +) + +First key is : +int(1) + Done diff --git a/ext/standard/tests/array/array_key_last.phpt b/ext/standard/tests/array/array_key_last.phpt index 66d3035be5b1..599d80eac41b 100644 --- a/ext/standard/tests/array/array_key_last.phpt +++ b/ext/standard/tests/array/array_key_last.phpt @@ -19,7 +19,9 @@ $mixed_array = array( array( 12, "name", 'age', '45' ), array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, - 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ), + array( "foo" ), + array( 1 => "42" ) ); /* Loop to test normal functionality with different arrays inputs */ @@ -211,4 +213,22 @@ Array Last key is : string(3) "5.7" +-- Input Array for Iteration 12 is -- +Array +( + [0] => foo +) + +Last key is : +int(0) + +-- Input Array for Iteration 13 is -- +Array +( + [1] => 42 +) + +Last key is : +int(1) + Done diff --git a/ext/standard/tests/array/array_value_first.phpt b/ext/standard/tests/array/array_value_first.phpt deleted file mode 100644 index 440ae699abe8..000000000000 --- a/ext/standard/tests/array/array_value_first.phpt +++ /dev/null @@ -1,221 +0,0 @@ ---TEST-- -Test array_value_first() function ---FILE-- - "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), - array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), - array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), - array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", - "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), - array( 12, "name", 'age', '45' ), - array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), - array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, - 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) -); - -/* Loop to test normal functionality with different arrays inputs */ -echo "\n*** Normal testing with various array inputs ***\n"; - -$counter = 1; -foreach( $mixed_array as $sub_array ) -{ - echo "\n-- Input Array for Iteration $counter is --\n"; - print_r( $sub_array ); - echo "\nFirst value is :\n"; - var_dump( array_value_first($sub_array) ); - $counter++; -} - -echo"\nDone"; -?> ---EXPECT-- -*** Normal testing with various array inputs *** - --- Input Array for Iteration 1 is -- -Array -( -) - -First value is : -NULL - --- Input Array for Iteration 2 is -- -Array -( - [0] => 1 - [1] => 2 - [2] => 3 - [3] => 4 - [4] => 5 - [5] => 6 - [6] => 7 - [7] => 8 - [8] => 9 -) - -First value is : -int(1) - --- Input Array for Iteration 3 is -- -Array -( - [0] => One - [1] => _Two - [2] => Three - [3] => Four - [4] => Five -) - -First value is : -string(3) "One" - --- Input Array for Iteration 4 is -- -Array -( - [0] => 6 - [1] => six - [2] => 7 - [3] => seven - [4] => 8 - [5] => eight - [6] => 9 - [7] => nine -) - -First value is : -int(6) - --- Input Array for Iteration 5 is -- -Array -( - [a] => aaa - [A] => AAA - [c] => ccc - [d] => ddd - [e] => eee -) - -First value is : -string(3) "aaa" - --- Input Array for Iteration 6 is -- -Array -( - [1] => one - [2] => two - [3] => three - [4] => four - [5] => five -) - -First value is : -string(3) "one" - --- Input Array for Iteration 7 is -- -Array -( - [1] => one - [2] => two - [3] => 7 - [4] => four - [5] => five -) - -First value is : -string(3) "one" - --- Input Array for Iteration 8 is -- -Array -( - [f] => fff - [1] => one - [4] => 6 - [] => 3 - [2] => float - [F] => FFF - [blank] => - [3] => 3.7 - [5] => Five - [6] => 8.6 - [4name] => jonny - [a] => -) - -First value is : -string(3) "fff" - --- Input Array for Iteration 9 is -- -Array -( - [0] => 12 - [1] => name - [2] => age - [3] => 45 -) - -First value is : -int(12) - --- Input Array for Iteration 10 is -- -Array -( - [0] => Array - ( - [0] => oNe - [1] => tWo - [2] => 4 - ) - - [1] => Array - ( - [0] => 10 - [1] => 20 - [2] => 30 - [3] => 40 - [4] => 50 - ) - - [2] => Array - ( - ) - -) - -First value is : -array(3) { - [0]=> - string(3) "oNe" - [1]=> - string(3) "tWo" - [2]=> - int(4) -} - --- Input Array for Iteration 11 is -- -Array -( - [one] => 2 - [three] => 3 - [0] => 3 - [1] => 4 - [3] => 33 - [4] => 44 - [5] => 57 - [6] => 6 - [5.4] => 554 - [5.7] => 557 -) - -First value is : -int(2) - -Done diff --git a/ext/standard/tests/array/array_value_first_errors.phpt b/ext/standard/tests/array/array_value_first_errors.phpt deleted file mode 100644 index 5502bee9d685..000000000000 --- a/ext/standard/tests/array/array_value_first_errors.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -Test array_value_first() function (errors) ---FILE-- - ---EXPECTF-- -*** Testing Error Conditions *** - -Warning: array_value_first() expects exactly 1 parameter, 0 given in %s on line %d -NULL - -Warning: array_value_first() expects parameter 1 to be array, int given in %s on line %d -NULL - -Warning: array_value_first() expects parameter 1 to be array, string given in %s on line %d -NULL - -Warning: array_value_first() expects exactly 1 parameter, 2 given in %s on line %d -NULL -NULL - -Done diff --git a/ext/standard/tests/array/array_value_first_variation.phpt b/ext/standard/tests/array/array_value_first_variation.phpt deleted file mode 100644 index f400c23ee1e4..000000000000 --- a/ext/standard/tests/array/array_value_first_variation.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Test array_value_first() function (variation) ---FILE-- - ---EXPECT-- -*** Checking for internal array pointer not being changed by array_value_first *** - -Current Element is : int(1) - -Next Element is : int(2) - -First value is : int(1) - -Current Element after array_value_first operation is: int(2) - -Done diff --git a/ext/standard/tests/array/array_value_last.phpt b/ext/standard/tests/array/array_value_last.phpt deleted file mode 100644 index 9f790ec8a91f..000000000000 --- a/ext/standard/tests/array/array_value_last.phpt +++ /dev/null @@ -1,215 +0,0 @@ ---TEST-- -Test array_value_last() function ---FILE-- - "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), - array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), - array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), - array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", - "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), - array( 12, "name", 'age', '45' ), - array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), - array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, - 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) -); - -/* Loop to test normal functionality with different arrays inputs */ -echo "\n*** Normal testing with various array inputs ***\n"; - -$counter = 1; -foreach( $mixed_array as $sub_array ) -{ - echo "\n-- Input Array for Iteration $counter is --\n"; - print_r( $sub_array ); - echo "\nLast value is :\n"; - var_dump( array_value_last($sub_array) ); - $counter++; -} - -echo"\nDone"; -?> ---EXPECT-- -*** Normal testing with various array inputs *** - --- Input Array for Iteration 1 is -- -Array -( -) - -Last value is : -NULL - --- Input Array for Iteration 2 is -- -Array -( - [0] => 1 - [1] => 2 - [2] => 3 - [3] => 4 - [4] => 5 - [5] => 6 - [6] => 7 - [7] => 8 - [8] => 9 -) - -Last value is : -int(9) - --- Input Array for Iteration 3 is -- -Array -( - [0] => One - [1] => _Two - [2] => Three - [3] => Four - [4] => Five -) - -Last value is : -string(4) "Five" - --- Input Array for Iteration 4 is -- -Array -( - [0] => 6 - [1] => six - [2] => 7 - [3] => seven - [4] => 8 - [5] => eight - [6] => 9 - [7] => nine -) - -Last value is : -string(4) "nine" - --- Input Array for Iteration 5 is -- -Array -( - [a] => aaa - [A] => AAA - [c] => ccc - [d] => ddd - [e] => eee -) - -Last value is : -string(3) "eee" - --- Input Array for Iteration 6 is -- -Array -( - [1] => one - [2] => two - [3] => three - [4] => four - [5] => five -) - -Last value is : -string(4) "five" - --- Input Array for Iteration 7 is -- -Array -( - [1] => one - [2] => two - [3] => 7 - [4] => four - [5] => five -) - -Last value is : -string(4) "five" - --- Input Array for Iteration 8 is -- -Array -( - [f] => fff - [1] => one - [4] => 6 - [] => 3 - [2] => float - [F] => FFF - [blank] => - [3] => 3.7 - [5] => Five - [6] => 8.6 - [4name] => jonny - [a] => -) - -Last value is : -NULL - --- Input Array for Iteration 9 is -- -Array -( - [0] => 12 - [1] => name - [2] => age - [3] => 45 -) - -Last value is : -string(2) "45" - --- Input Array for Iteration 10 is -- -Array -( - [0] => Array - ( - [0] => oNe - [1] => tWo - [2] => 4 - ) - - [1] => Array - ( - [0] => 10 - [1] => 20 - [2] => 30 - [3] => 40 - [4] => 50 - ) - - [2] => Array - ( - ) - -) - -Last value is : -array(0) { -} - --- Input Array for Iteration 11 is -- -Array -( - [one] => 2 - [three] => 3 - [0] => 3 - [1] => 4 - [3] => 33 - [4] => 44 - [5] => 57 - [6] => 6 - [5.4] => 554 - [5.7] => 557 -) - -Last value is : -int(557) - -Done diff --git a/ext/standard/tests/array/array_value_last_errors.phpt b/ext/standard/tests/array/array_value_last_errors.phpt deleted file mode 100644 index 309a53ed9fb0..000000000000 --- a/ext/standard/tests/array/array_value_last_errors.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -Test array_value_last() function (errors) ---FILE-- - ---EXPECTF-- -*** Testing Error Conditions *** - -Warning: array_value_last() expects exactly 1 parameter, 0 given in %s on line %d -NULL - -Warning: array_value_last() expects parameter 1 to be array, int given in %s on line %d -NULL - -Warning: array_value_last() expects parameter 1 to be array, string given in %s on line %d -NULL - -Warning: array_value_last() expects exactly 1 parameter, 2 given in %s on line %d -NULL -NULL - -Done diff --git a/ext/standard/tests/array/array_value_last_variation.phpt b/ext/standard/tests/array/array_value_last_variation.phpt deleted file mode 100644 index 42e26d2afa53..000000000000 --- a/ext/standard/tests/array/array_value_last_variation.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Test array_value_last() function (variation) ---FILE-- - ---EXPECT-- -*** Checking for internal array pointer not being changed by array_value_last *** - -Current Element is : int(1) - -Next Element is : int(2) - -Last value is : int(9) - -Current Element after array_value_last operation is: int(2) - -Done