diff options
author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:39:08 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:39:08 -0400 |
commit | 993e1866df547532a05ab6db76c9ff5aefc9a3df (patch) | |
tree | 169d3bde0974235d3cde164786ef6f381a4749a7 /ext/standard | |
parent | 1f589a2bd44ba835ad1b009a5d83abd453724829 (diff) | |
download | php-993e1866df547532a05ab6db76c9ff5aefc9a3df.tar.gz |
Imported Upstream version 5.2.6upstream/5.2.6
Diffstat (limited to 'ext/standard')
922 files changed, 84107 insertions, 3487 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index e3f2b7609..6f154b7d9 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.308.2.21.2.42 2007/11/06 13:28:21 jani Exp $ */ +/* $Id: array.c,v 1.308.2.21.2.55 2008/03/12 19:13:00 felipe Exp $ */ #include "php.h" #include "php_ini.h" @@ -102,7 +102,7 @@ ZEND_DECLARE_MODULE_GLOBALS(array) */ static void php_array_init_globals(zend_array_globals *array_globals) { - memset(array_globals, 0, sizeof(array_globals)); + memset(array_globals, 0, sizeof(zend_array_globals)); } /* }}} */ @@ -283,6 +283,11 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ zval **element; if (Z_TYPE_P(array) == IS_ARRAY) { + if (Z_ARRVAL_P(array)->nApplyCount > 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); + return 0; + } + cnt = zend_hash_num_elements(Z_ARRVAL_P(array)); if (mode == COUNT_RECURSIVE) { HashPosition pos; @@ -290,7 +295,9 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **) &element, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos)) { + Z_ARRVAL_P(array)->nApplyCount++; cnt += php_count_recursive(*element, COUNT_RECURSIVE TSRMLS_CC); + Z_ARRVAL_P(array)->nApplyCount--; } } } @@ -324,7 +331,7 @@ PHP_FUNCTION(count) if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) { zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); if (retval) { - convert_to_long(retval); + convert_to_long_ex(&retval); RETVAL_LONG(Z_LVAL_P(retval)); zval_ptr_dtor(&retval); } @@ -1077,7 +1084,7 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive if (recursive && Z_TYPE_PP(args[0]) == IS_ARRAY) { HashTable *thash; - SEPARATE_ZVAL_TO_MAKE_IS_REF(args[0]); + SEPARATE_ZVAL_IF_NOT_REF(args[0]); thash = HASH_OF(*(args[0])); if (thash->nApplyCount > 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); @@ -1975,6 +1982,7 @@ PHP_FUNCTION(array_push) new_var->refcount++; if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var, sizeof(zval *), NULL) == FAILURE) { + new_var->refcount--; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element to the array as the next element is already occupied"); efree(args); RETURN_FALSE; @@ -2201,103 +2209,83 @@ PHP_FUNCTION(array_splice) Returns elements specified by offset and length */ PHP_FUNCTION(array_slice) { - zval **input, /* Input array */ - **offset, /* Offset to get elements from */ - **length, /* How many elements to get */ - **entry, /* An array entry */ - **z_preserve_keys; /* Whether to preserve keys while copying to the new array or not */ - int offset_val, /* Value of the offset argument */ - length_val, /* Value of the length argument */ - num_in, /* Number of elements in the input array */ - pos, /* Current position in the array */ - argc; /* Number of function arguments */ - + zval *input, /* Input array */ + **z_length, /* How many elements to get */ + **entry; /* An array entry */ + long offset, /* Offset to get elements from */ + length = 0; + zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */ + int num_in, /* Number of elements in the input array */ + pos; /* Current position in the array */ char *string_key; uint string_key_len; ulong num_key; HashPosition hpos; - zend_bool preserve_keys = 0; - /* Get the arguments and do error-checking */ - argc = ZEND_NUM_ARGS(); - if (argc < 2 || argc > 4 || zend_get_parameters_ex(argc, &input, &offset, &length, &z_preserve_keys)) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|Zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) { return; } - - /* Make sure offset and length are integers and assume - we want all entries from offset to the end if length - is not passed */ - convert_to_long_ex(offset); - offset_val = Z_LVAL_PP(offset); - if (argc >= 3 && Z_TYPE_PP(length) != IS_NULL) { - convert_to_long_ex(length); - length_val = Z_LVAL_PP(length); + + /* Get number of entries in the input hash */ + num_in = zend_hash_num_elements(Z_ARRVAL_P(input)); + + /* We want all entries from offset to the end if length is not passed or is null */ + if (ZEND_NUM_ARGS() < 3 || Z_TYPE_PP(z_length) == IS_NULL) { + length = num_in; } else { - length_val = zend_hash_num_elements(Z_ARRVAL_PP(input)); + convert_to_long_ex(z_length); + length = Z_LVAL_PP(z_length); } - if (ZEND_NUM_ARGS() > 3) { - convert_to_boolean_ex(z_preserve_keys); - preserve_keys = Z_BVAL_PP(z_preserve_keys); - } - /* Initialize returned array */ array_init(return_value); - - /* Get number of entries in the input hash */ - num_in = zend_hash_num_elements(Z_ARRVAL_PP(input)); - + /* Clamp the offset.. */ - if (offset_val > num_in) + if (offset > num_in) { return; - else if (offset_val < 0 && (offset_val = (num_in + offset_val)) < 0) - offset_val = 0; - + } else if (offset < 0 && (offset = (num_in + offset)) < 0) { + offset = 0; + } + /* ..and the length */ - if (length_val < 0) { - length_val = num_in - offset_val + length_val; - } else if (((unsigned)offset_val + (unsigned)length_val) > (unsigned)num_in) { - length_val = num_in - offset_val; + if (length < 0) { + length = num_in - offset + length; + } else if (((unsigned) offset + (unsigned) length) > (unsigned) num_in) { + length = num_in - offset; } - - if (length_val == 0) + + if (length == 0) { return; - + } + /* Start at the beginning and go until we hit offset */ pos = 0; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &hpos); - while (pos < offset_val && zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &hpos); + while (pos < offset && zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &hpos) == SUCCESS) { pos++; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos); + zend_hash_move_forward_ex(Z_ARRVAL_P(input), &hpos); } - + /* Copy elements from input array to the one that's returned */ - while (pos < offset_val+length_val && zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) { - - (*entry)->refcount++; + while (pos < offset + length && zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &hpos) == SUCCESS) { + + zval_add_ref(entry); - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &hpos)) { + switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &string_key_len, &num_key, 0, &hpos)) { case HASH_KEY_IS_STRING: - zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, - entry, sizeof(zval *), NULL); + zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, entry, sizeof(zval *), NULL); break; - + case HASH_KEY_IS_LONG: - if (preserve_keys) - zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, - entry, sizeof(zval *), NULL); - else - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), - entry, sizeof(zval *), NULL); + if (preserve_keys) { + zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(zval *), NULL); + } else { + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, sizeof(zval *), NULL); + } break; } pos++; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos); + zend_hash_move_forward_ex(Z_ARRVAL_P(input), &hpos); } } /* }}} */ @@ -2314,20 +2302,40 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: - if (recursive && - zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) { - if (*src_entry == *dest_entry && ((*dest_entry)->refcount % 2)) { + if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) { + HashTable *thash = HASH_OF(*dest_entry); + + if ((thash && thash->nApplyCount > 1) || (*src_entry == *dest_entry && (*dest_entry)->is_ref && ((*dest_entry)->refcount % 2))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); return 0; } SEPARATE_ZVAL(dest_entry); SEPARATE_ZVAL(src_entry); - convert_to_array_ex(dest_entry); - convert_to_array_ex(src_entry); - if (!php_array_merge(Z_ARRVAL_PP(dest_entry), - Z_ARRVAL_PP(src_entry), recursive TSRMLS_CC)) + if (Z_TYPE_PP(dest_entry) == IS_NULL) { + convert_to_array_ex(dest_entry); + add_next_index_null(*dest_entry); + } else { + convert_to_array_ex(dest_entry); + } + if (Z_TYPE_PP(src_entry) == IS_NULL) { + convert_to_array_ex(src_entry); + add_next_index_null(*src_entry); + } else { + convert_to_array_ex(src_entry); + } + if (thash) { + thash->nApplyCount++; + } + if (!php_array_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry), recursive TSRMLS_CC)) { + if (thash) { + thash->nApplyCount--; + } return 0; + } + if (thash) { + thash->nApplyCount--; + } } else { (*src_entry)->refcount++; @@ -2655,6 +2663,11 @@ PHP_FUNCTION(array_pad) /* Do some initial calculations */ input_size = zend_hash_num_elements(Z_ARRVAL_PP(input)); pad_size_abs = abs(Z_LVAL_PP(pad_size)); + if (pad_size_abs < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time"); + zval_dtor(return_value); + RETURN_FALSE; + } do_pad = (input_size >= pad_size_abs) ? 0 : 1; /* Copy the original array */ @@ -3722,13 +3735,14 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ } c = 1; for (i = 1; i < arr_argc; i++) { + Bucket **ptr = ptrs[i]; if (behavior == DIFF_NORMAL) { - while (*ptrs[i] && (0 < (c = diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { - ptrs[i]++; + while (*ptr && (0 < (c = diff_data_compare_func(ptrs[0], ptr TSRMLS_CC)))) { + ptr++; } } else if (behavior & DIFF_ASSOC) { /* triggered also when DIFF_KEY */ - while (*ptrs[i] && (0 < (c = diff_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { - ptrs[i]++; + while (*ptr && (0 != (c = diff_key_compare_func(ptrs[0], ptr TSRMLS_CC)))) { + ptr++; } } if (!c) { @@ -3742,11 +3756,11 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ In this branch is execute only when DIFF_ASSOC. If behavior == DIFF_KEY data comparison is not needed - skipped. */ - if (*ptrs[i]) { + if (*ptr) { if (data_compare_type == DIFF_COMP_DATA_USER) { BG(user_compare_func_name) = args[arr_argc]; } - if (diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC) != 0) { + if (diff_data_compare_func(ptrs[0], ptr TSRMLS_CC) != 0) { /* the data is not the same */ c = -1; if (key_compare_type == DIFF_COMP_KEY_USER) { diff --git a/ext/standard/assert.c b/ext/standard/assert.c index 220ffad51..c4fb5a13e 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: assert.c,v 1.60.2.3.2.6 2007/02/16 16:35:04 dmitry Exp $ */ +/* $Id: assert.c,v 1.60.2.3.2.7 2007/12/31 07:20:12 sebastian Exp $ */ /* {{{ includes/startup/misc */ diff --git a/ext/standard/base64.c b/ext/standard/base64.c index 2bfe83198..b3179b99f 100644 --- a/ext/standard/base64.c +++ b/ext/standard/base64.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: base64.c,v 1.43.2.2.2.3 2007/07/21 01:24:26 jani Exp $ */ +/* $Id: base64.c,v 1.43.2.2.2.4 2007/12/31 07:20:12 sebastian Exp $ */ #include <string.h> diff --git a/ext/standard/base64.h b/ext/standard/base64.h index 20c3f3dbe..11a65e1b1 100644 --- a/ext/standard/base64.h +++ b/ext/standard/base64.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: base64.h,v 1.14.2.1.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: base64.h,v 1.14.2.1.2.3 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef BASE64_H #define BASE64_H diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 43b3b1407..3d61f3d0c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.66 2007/10/22 07:37:20 dmitry Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.69 2008/03/20 00:55:26 dsp Exp $ */ #include "php.h" #include "php_streams.h" @@ -4568,10 +4568,11 @@ PHP_FUNCTION(getopt) * in order to be on the safe side, even though it is also available * from the symbol table. */ - if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE || - zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) { + if ((zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE || + zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) && Z_TYPE_PP(args) == IS_ARRAY + ) { int pos = 0; - zval **arg; + zval **entry; argc = zend_hash_num_elements(Z_ARRVAL_PP(args)); @@ -4586,8 +4587,22 @@ PHP_FUNCTION(getopt) /* Iterate over the hash to construct the argv array. */ while (zend_hash_get_current_data(Z_ARRVAL_PP(args), - (void **)&arg) == SUCCESS) { - argv[pos++] = estrdup(Z_STRVAL_PP(arg)); + (void **)&entry) == SUCCESS) { + zval arg, *arg_ptr = *entry; + + if (Z_TYPE_PP(entry) != IS_STRING) { + arg = **entry; + zval_copy_ctor(&arg); + convert_to_string(&arg); + arg_ptr = &arg; + } + + argv[pos++] = estrdup(Z_STRVAL_P(arg_ptr)); + + if (arg_ptr != *entry) { + zval_dtor(&arg); + } + zend_hash_move_forward(Z_ARRVAL_PP(args)); } @@ -4605,7 +4620,7 @@ PHP_FUNCTION(getopt) #ifdef HARTMUT_0 int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts)); struct option *p; - zval **arg; + zval **entry; char *name; longopts = (struct option *)ecalloc(c+1, sizeof(struct option)); @@ -4618,10 +4633,19 @@ PHP_FUNCTION(getopt) /* Iterate over the hash to construct the argv array. */ while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), - (void **)&arg) == SUCCESS) { + (void **)&entry) == SUCCESS) { + zval arg, *arg_ptr = *entry; + + if (Z_TYPE_PP(entry) != IS_STRING) { + arg = **entry; + zval_copy_ctor(&arg); + convert_to_string(&arg); + arg_ptr = &arg; + } + p->has_arg = 0; - name = estrdup(Z_STRVAL_PP(arg)); + name = estrdup(Z_STRVAL_P(arg_ptr)); len = strlen(name); if((len > 0) && (name[len-1] == ':')) { p->has_arg++; @@ -4636,6 +4660,10 @@ PHP_FUNCTION(getopt) p->flag = NULL; p->val = 0; + if (arg_ptr != *entry) { + zval_dtor(&arg); + } + zend_hash_move_forward(Z_ARRVAL_P(p_longopts)); p++; } @@ -5191,8 +5219,10 @@ PHP_FUNCTION(call_user_method) SEPARATE_ZVAL(params[0]); convert_to_string(*params[0]); - if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS) { + if (retval_ptr) { + COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0])); } @@ -5233,8 +5263,10 @@ PHP_FUNCTION(call_user_method_array) element++; } - if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS) { + if (retval_ptr) { + COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name)); } diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 767ca8b2e..b9269fe8a 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.h,v 1.139.2.4.2.6 2007/07/21 01:24:26 jani Exp $ */ +/* $Id: basic_functions.h,v 1.139.2.4.2.7 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef BASIC_FUNCTIONS_H #define BASIC_FUNCTIONS_H diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index 3e661fd9b..f8fde93dd 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: browscap.c,v 1.85.2.2.2.4 2007/10/04 13:31:10 jani Exp $ */ +/* $Id: browscap.c,v 1.85.2.2.2.5 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "php_regex.h" diff --git a/ext/standard/crc32.c b/ext/standard/crc32.c index 7116e468a..44e711b1b 100644 --- a/ext/standard/crc32.c +++ b/ext/standard/crc32.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: crc32.c,v 1.16.2.4.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: crc32.c,v 1.16.2.4.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "basic_functions.h" diff --git a/ext/standard/crc32.h b/ext/standard/crc32.h index 3fa98d45a..477bac1de 100644 --- a/ext/standard/crc32.h +++ b/ext/standard/crc32.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: crc32.h,v 1.6.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: crc32.h,v 1.6.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ /* * This code implements the AUTODIN II polynomial diff --git a/ext/standard/credits.c b/ext/standard/credits.c index cef6c76dd..d6f0a8e6f 100644 --- a/ext/standard/credits.c +++ b/ext/standard/credits.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: credits.c,v 1.36.2.4.2.4 2007/05/22 15:44:11 bjori Exp $ */ +/* $Id: credits.c,v 1.36.2.4.2.6 2008/04/10 05:32:26 philip Exp $ */ #include "php.h" #include "info.h" @@ -96,9 +96,9 @@ PHPAPI void php_print_credits(int flag TSRMLS_DC) if (flag & PHP_CREDITS_DOCS) { php_info_print_table_start(); php_info_print_table_colspan_header(2, "PHP Documentation"); - CREDIT_LINE("Authors", "Mehdi Achour, Friedhelm Betz, Antony Dovgal, Nuno Lopes, Philip Olson, Georg Richter, Damien Seguy, Jakub Vrana"); + CREDIT_LINE("Authors", "Mehdi Achour, Friedhelm Betz, Antony Dovgal, Nuno Lopes, Hannes Magnusson, Georg Richter, Damien Seguy, Jakub Vrana"); CREDIT_LINE("Editor", "Philip Olson"); - CREDIT_LINE("User Note Maintainers", "Mehdi Achour, Friedhelm Betz, Vincent Gevers, Aidan Lister, Nuno Lopes, Tom Sommer"); + CREDIT_LINE("User Note Maintainers", "Friedhelm Betz, Etienne Kneuss, Nuno Lopes, Hannes Magnusson, Felipe Pena, Maciek Sokolewicz"); CREDIT_LINE("Other Contributors", "Previously active authors, editors and other contributors are listed in the manual."); php_info_print_table_end(); } diff --git a/ext/standard/credits.h b/ext/standard/credits.h index 27ad4dd41..f8466147a 100644 --- a/ext/standard/credits.h +++ b/ext/standard/credits.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: credits.h,v 1.11.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: credits.h,v 1.11.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef CREDITS_H #define CREDITS_H diff --git a/ext/standard/credits_ext.h b/ext/standard/credits_ext.h index b468545c6..2288bb812 100644 --- a/ext/standard/credits_ext.h +++ b/ext/standard/credits_ext.h @@ -79,7 +79,7 @@ CREDIT_LINE("System V Message based IPC", "Wez Furlong"); CREDIT_LINE("System V Semaphores", "Tom May"); CREDIT_LINE("System V Shared Memory", "Christian Cartus"); CREDIT_LINE("tidy", "John Coggeshall, Ilia Alshanetsky"); -CREDIT_LINE("tokenizer", "Andrei Zmievski"); +CREDIT_LINE("tokenizer", "Andrei Zmievski, Johannes Schlueter"); CREDIT_LINE("WDDX", "Andrei Zmievski"); CREDIT_LINE("XMLReader", "Rob Richards"); CREDIT_LINE("xmlrpc", "Dan Libby"); diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c index 2a74d1bd0..fa51d6f7d 100644 --- a/ext/standard/crypt.c +++ b/ext/standard/crypt.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: crypt.c,v 1.62.2.1.2.6 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: crypt.c,v 1.62.2.1.2.7 2007/12/31 07:20:12 sebastian Exp $ */ #include <stdlib.h> #include "php.h" diff --git a/ext/standard/css.c b/ext/standard/css.c index 8595e0d3d..e138ab6c6 100644 --- a/ext/standard/css.c +++ b/ext/standard/css.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: css.c,v 1.13.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: css.c,v 1.13.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "info.h" diff --git a/ext/standard/css.h b/ext/standard/css.h index fdced8f61..ad80fa783 100644 --- a/ext/standard/css.h +++ b/ext/standard/css.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: css.h,v 1.6.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: css.h,v 1.6.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef CSS_H #define CSS_H diff --git a/ext/standard/cyr_convert.c b/ext/standard/cyr_convert.c index ac2eef59b..ff1bd5f94 100644 --- a/ext/standard/cyr_convert.c +++ b/ext/standard/cyr_convert.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cyr_convert.c,v 1.27.2.3.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: cyr_convert.c,v 1.27.2.3.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include <stdlib.h> diff --git a/ext/standard/cyr_convert.h b/ext/standard/cyr_convert.h index fba4877ba..970edc992 100644 --- a/ext/standard/cyr_convert.h +++ b/ext/standard/cyr_convert.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cyr_convert.h,v 1.11.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: cyr_convert.h,v 1.11.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef CYR_CONVERT_H #define CYR_CONVERT_H diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index afb5e771d..c0bb09be0 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: datetime.c,v 1.134.2.2.2.4 2007/06/07 08:59:00 tony2001 Exp $ */ +/* $Id: datetime.c,v 1.134.2.2.2.5 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "zend_operators.h" diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h index 1f8bcc99f..c0c7a47d0 100644 --- a/ext/standard/datetime.h +++ b/ext/standard/datetime.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: datetime.h,v 1.23.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: datetime.h,v 1.23.2.2.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef DATETIME_H #define DATETIME_H diff --git a/ext/standard/dir.c b/ext/standard/dir.c index a3f540d2e..f6737ed1a 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dir.c,v 1.147.2.3.2.12 2007/09/19 22:37:58 iliaa Exp $ */ +/* $Id: dir.c,v 1.147.2.3.2.16 2008/03/05 12:10:18 tony2001 Exp $ */ /* {{{ includes/startup/misc */ @@ -256,14 +256,16 @@ PHP_FUNCTION(closedir) { zval **id, **tmp, *myself; php_stream *dirp; + int rsrc_id; FETCH_DIRP(); - if (dirp->rsrc_id == DIRG(default_dir)) { + rsrc_id = dirp->rsrc_id; + zend_list_delete(dirp->rsrc_id); + + if (rsrc_id == DIRG(default_dir)) { php_set_default_dir(-1 TSRMLS_CC); } - - zend_list_delete(dirp->rsrc_id); } /* }}} */ @@ -467,7 +469,7 @@ no_results: array_init(return_value); for (n = 0; n < globbuf.gl_pathc; n++) { if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) { - if (PG(safe_mode) && (!php_checkuid(globbuf.gl_pathv[n], NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + if (PG(safe_mode) && (!php_checkuid_ex(globbuf.gl_pathv[n], NULL, CHECKUID_CHECK_FILE_AND_DIR, CHECKUID_NO_ERRORS))) { basedir_limit = 1; continue; } else if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0 TSRMLS_CC)) { diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 09f186cf0..f652d2536 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dl.c,v 1.106.2.1.2.5 2007/09/18 20:19:34 stas Exp $ */ +/* $Id: dl.c,v 1.106.2.1.2.6 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "dl.h" diff --git a/ext/standard/dl.h b/ext/standard/dl.h index 114680770..6b00fa74e 100644 --- a/ext/standard/dl.h +++ b/ext/standard/dl.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dl.h,v 1.23.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: dl.h,v 1.23.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef DL_H #define DL_H diff --git a/ext/standard/dns.c b/ext/standard/dns.c index aba99dc79..a224a1cd9 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dns.c,v 1.70.2.7.2.5 2007/06/26 11:04:55 tony2001 Exp $ */ +/* $Id: dns.c,v 1.70.2.7.2.6 2007/12/31 07:20:12 sebastian Exp $ */ /* {{{ includes */ #include "php.h" diff --git a/ext/standard/dns.h b/ext/standard/dns.h index cc4772aab..356ced73e 100644 --- a/ext/standard/dns.h +++ b/ext/standard/dns.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dns.h,v 1.19.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: dns.h,v 1.19.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef DNS_H #define DNS_H diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 8f999c39f..7f1aea174 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ | Ilia Alshanetsky <iliaa@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: exec.c,v 1.113.2.3.2.2 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: exec.c,v 1.113.2.3.2.10 2008/04/08 17:17:07 iliaa Exp $ */ #include <stdio.h> #include "php.h" @@ -25,6 +25,7 @@ #include "safe_mode.h" #include "ext/standard/head.h" #include "ext/standard/file.h" +#include "basic_functions.h" #include "exec.h" #include "php_globals.h" #include "SAPI.h" @@ -265,11 +266,25 @@ char *php_escape_shell_cmd(char *str) { register int x, y, l; char *cmd; char *p = NULL; + + TSRMLS_FETCH(); l = strlen(str); cmd = safe_emalloc(2, l, 1); for (x = 0, y = 0; x < l; x++) { + int mb_len = php_mblen(str + x, (l - x)); + + /* skip non-valid multibyte characters */ + if (mb_len < 0) { + continue; + } else if (mb_len > 1) { + memcpy(cmd + y, str + x, mb_len); + y += mb_len; + x += mb_len - 1; + continue; + } + switch (str[x]) { case '"': case '\'': @@ -328,6 +343,7 @@ char *php_escape_shell_cmd(char *str) { char *php_escape_shell_arg(char *str) { int x, y, l; char *cmd; + TSRMLS_FETCH(); y = 0; l = strlen(str); @@ -341,6 +357,18 @@ char *php_escape_shell_arg(char *str) { #endif for (x = 0; x < l; x++) { + int mb_len = php_mblen(str + x, (l - x)); + + /* skip non-valid multibyte characters */ + if (mb_len < 0) { + continue; + } else if (mb_len > 1) { + memcpy(cmd + y, str + x, mb_len); + y += mb_len; + x += mb_len - 1; + continue; + } + switch (str[x]) { #ifdef PHP_WIN32 case '"': @@ -372,18 +400,19 @@ char *php_escape_shell_arg(char *str) { Escape shell metacharacters */ PHP_FUNCTION(escapeshellcmd) { - zval **arg1; + char *command; + int command_len; char *cmd = NULL; - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &command, &command_len) == FAILURE) { + return; } - - convert_to_string_ex(arg1); - if (Z_STRLEN_PP(arg1)) { - cmd = php_escape_shell_cmd(Z_STRVAL_PP(arg1)); - RETVAL_STRING(cmd, 1); - efree(cmd); + + if (command_len) { + cmd = php_escape_shell_cmd(command); + RETVAL_STRING(cmd, 0); + } else { + RETVAL_EMPTY_STRING(); } } /* }}} */ @@ -392,18 +421,17 @@ PHP_FUNCTION(escapeshellcmd) Quote and escape an argument for use in a shell command */ PHP_FUNCTION(escapeshellarg) { - zval **arg1; + char *argument; + int argument_len; char *cmd = NULL; - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &argument, &argument_len) == FAILURE) { + return; } - - convert_to_string_ex(arg1); - if (Z_STRLEN_PP(arg1)) { - cmd = php_escape_shell_arg(Z_STRVAL_PP(arg1)); - RETVAL_STRING(cmd, 1); - efree(cmd); + + if (argument) { + cmd = php_escape_shell_arg(argument); + RETVAL_STRING(cmd, 0); } } /* }}} */ diff --git a/ext/standard/exec.h b/ext/standard/exec.h index 43d798b2b..371f695e1 100644 --- a/ext/standard/exec.h +++ b/ext/standard/exec.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exec.h,v 1.24.2.3.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: exec.h,v 1.24.2.3.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef EXEC_H #define EXEC_H diff --git a/ext/standard/file.c b/ext/standard/file.c index e10295496..8ff709c58 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.409.2.6.2.28 2007/09/04 12:51:49 iliaa Exp $ */ +/* $Id: file.c,v 1.409.2.6.2.31 2007/12/31 07:20:12 sebastian Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -592,6 +592,7 @@ PHP_FUNCTION(file_put_contents) zval *zcontext = NULL; php_stream_context *context = NULL; php_stream *srcstream = NULL; + char mode[3] = "wb"; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { @@ -604,8 +605,14 @@ PHP_FUNCTION(file_put_contents) context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); - stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb", - ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); + if (flags & PHP_FILE_APPEND) { + mode[0] = 'a'; + } else if (flags & LOCK_EX) { + mode[0] = 'c'; + } + mode[2] = '\0'; + + stream = php_stream_open_wrapper_ex(filename, mode, ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); if (stream == NULL) { RETURN_FALSE; } @@ -615,6 +622,10 @@ PHP_FUNCTION(file_put_contents) RETURN_FALSE; } + if (mode[0] == 'c') { + php_stream_truncate_set_size(stream, 0); + } + switch (Z_TYPE_P(data)) { case IS_RESOURCE: numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL); diff --git a/ext/standard/file.h b/ext/standard/file.h index 7a1c7d1b3..d4d16bc09 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.94.2.2.2.5 2007/01/10 14:40:06 bjori Exp $ */ +/* $Id: file.h,v 1.94.2.2.2.6 2007/12/31 07:20:12 sebastian Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index df60b2e2d..a9f3f1000 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filestat.c,v 1.136.2.8.2.15 2007/10/31 13:23:06 jani Exp $ */ +/* $Id: filestat.c,v 1.136.2.8.2.16 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "safe_mode.h" diff --git a/ext/standard/filters.c b/ext/standard/filters.c index 763272460..4e41063c4 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filters.c,v 1.44.2.6.2.5 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: filters.c,v 1.44.2.6.2.6 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "php_globals.h" diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c index c153c3457..167702b85 100644 --- a/ext/standard/flock_compat.c +++ b/ext/standard/flock_compat.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: flock_compat.c,v 1.29.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: flock_compat.c,v 1.29.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include <errno.h> diff --git a/ext/standard/flock_compat.h b/ext/standard/flock_compat.h index 51ae7ac4e..ac6d55cb3 100644 --- a/ext/standard/flock_compat.h +++ b/ext/standard/flock_compat.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: flock_compat.h,v 1.20.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: flock_compat.h,v 1.20.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef FLOCK_COMPAT_H #define FLOCK_COMPAT_H diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 46c782536..662d85cd2 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: formatted_print.c,v 1.82.2.1.2.17 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: formatted_print.c,v 1.82.2.1.2.19 2008/03/17 23:00:41 stas Exp $ */ #include <math.h> /* modf() */ #include "php.h" @@ -76,6 +76,7 @@ php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add, register int npad; int req_size; int copy_len; + int m_width; copy_len = (expprec ? MIN(max_width, len) : len); npad = min_width - copy_len; @@ -86,11 +87,19 @@ php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add, PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n", *buffer, *pos, *size, add, min_width, padding, alignment)); + m_width = MAX(min_width, copy_len); - req_size = *pos + MAX(min_width, copy_len) + 1; + if(m_width > INT_MAX - *pos - 1) { + zend_error_noreturn(E_ERROR, "Field width %d is too long", m_width); + } + + req_size = *pos + m_width + 1; if (req_size > *size) { while (req_size > *size) { + if(*size > INT_MAX/2) { + zend_error_noreturn(E_ERROR, "Field width %d is too long", req_size); + } *size <<= 1; } PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size)); diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 5dedcc841..d54b3b5e9 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.121.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: fsock.c,v 1.121.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "php_globals.h" diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h index 6ae55d19a..10531b68a 100644 --- a/ext/standard/fsock.h +++ b/ext/standard/fsock.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.h,v 1.50.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: fsock.h,v 1.50.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ /* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */ diff --git a/ext/standard/ftok.c b/ext/standard/ftok.c index a63708177..40b74d547 100644 --- a/ext/standard/ftok.c +++ b/ext/standard/ftok.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ftok.c,v 1.16.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: ftok.c,v 1.16.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index e408615b6..c2e3896dc 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ | Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: ftp_fopen_wrapper.c,v 1.85.2.4.2.6 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: ftp_fopen_wrapper.c,v 1.85.2.4.2.9 2008/01/08 19:10:16 iliaa Exp $ */ #include "php.h" #include "php_globals.h" @@ -300,19 +300,21 @@ connect_errexit: /* {{{ php_fopen_do_pasv */ -static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, int ip_size, char **phoststart TSRMLS_DC) +static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, size_t ip_size, char **phoststart TSRMLS_DC) { char tmp_line[512]; int result, i; unsigned short portno; char *tpath, *ttpath, *hoststart=NULL; +#ifdef HAVE_IPV6 /* We try EPSV first, needed for IPv6 and works on some IPv4 servers */ php_stream_write_string(stream, "EPSV\r\n"); result = GET_FTP_RESULT(stream); /* check if we got a 229 response */ if (result != 229) { +#endif /* EPSV failed, let's try PASV */ php_stream_write_string(stream, "PASV\r\n"); result = GET_FTP_RESULT(stream); @@ -357,6 +359,8 @@ static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, int ip_siz tpath++; /* pull out the LSB of the port */ portno += (unsigned short) strtoul(tpath, &ttpath, 10); + +#ifdef HAVE_IPV6 } else { /* parse epsv command (|||6446|) */ for (i = 0, tpath = tmp_line + 4; *tpath; tpath++) { @@ -372,7 +376,8 @@ static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, int ip_siz /* pull out the port */ portno = (unsigned short) strtoul(tpath + 1, &ttpath, 10); } - +#endif + if (ttpath == NULL) { /* didn't get correct response from EPSV/PASV */ return 0; @@ -771,6 +776,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, char *url, int f ssb->sb.st_mode |= S_IFDIR; } + php_stream_write_string(stream, "TYPE I\r\n"); /* we need this since some servers refuse to accept SIZE command in ASCII mode */ php_stream_printf(stream TSRMLS_CC, "SIZE %s\r\n", (resource->path != NULL ? resource->path : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { diff --git a/ext/standard/head.c b/ext/standard/head.c index 868015f9e..f0502ab21 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ -/* $Id: head.c,v 1.84.2.1.2.7 2007/02/26 02:12:36 iliaa Exp $ */ +/* $Id: head.c,v 1.84.2.1.2.8 2007/12/31 07:20:12 sebastian Exp $ */ #include <stdio.h> #include "php.h" diff --git a/ext/standard/head.h b/ext/standard/head.h index 1afac8063..365ef3ea1 100644 --- a/ext/standard/head.h +++ b/ext/standard/head.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: head.h,v 1.28.2.1.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: head.h,v 1.28.2.1.2.3 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef HEAD_H #define HEAD_H diff --git a/ext/standard/html.c b/ext/standard/html.c index 357257997..dd8afdc9c 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: html.c,v 1.111.2.2.2.15 2007/10/03 04:53:05 stas Exp $ */ +/* $Id: html.c,v 1.111.2.2.2.20 2008/04/11 19:01:25 felipe Exp $ */ /* * HTML entity resources: @@ -847,7 +847,7 @@ det_charset: /* now walk the charset map and look for the codeset */ for (i = 0; charset_map[i].codeset; i++) { - if (strncasecmp(charset_hint, charset_map[i].codeset, len) == 0) { + if (len == strlen(charset_map[i].codeset) && strncasecmp(charset_hint, charset_map[i].codeset, len) == 0) { charset = charset_map[i].charset; found = 1; break; @@ -954,6 +954,7 @@ PHPAPI char *php_unescape_html_entities(unsigned char *old, int oldlen, int *new case cs_cp1251: case cs_8859_5: case cs_cp866: + case cs_koi8r: replacement[0] = k; replacement[1] = '\0'; replacement_len = 1; diff --git a/ext/standard/html.h b/ext/standard/html.h index b7ef2823c..e5bdafc4d 100644 --- a/ext/standard/html.h +++ b/ext/standard/html.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: html.h,v 1.20.2.1.2.3 2007/05/22 12:37:00 iliaa Exp $ */ +/* $Id: html.h,v 1.20.2.1.2.4 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef HTML_H #define HTML_H diff --git a/ext/standard/http.c b/ext/standard/http.c index a82ca61fa..85ad35c83 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.14.2.4.2.4 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: http.c,v 1.14.2.4.2.6 2008/01/10 20:32:41 shire Exp $ */ #include "php_http.h" #include "php_ini.h" @@ -105,7 +105,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, *p = '\0'; } else { /* Is an integer key */ - ekey_len = spprintf(&ekey, 12, "%ld", idx); + ekey_len = spprintf(&ekey, 0, "%ld", idx); newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 3 /* %5B */; newprefix = emalloc(newprefix_len + 1); p = newprefix; @@ -153,7 +153,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, if (num_prefix) { smart_str_appendl(formstr, num_prefix, num_prefix_len); } - ekey_len = spprintf(&ekey, 12, "%ld", idx); + ekey_len = spprintf(&ekey, 0, "%ld", idx); smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } @@ -165,10 +165,10 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, break; case IS_LONG: case IS_BOOL: - ekey_len = spprintf(&ekey, 12, "%ld", Z_LVAL_PP(zdata)); + ekey_len = spprintf(&ekey, 0, "%ld", Z_LVAL_PP(zdata)); break; case IS_DOUBLE: - ekey_len = spprintf(&ekey, 48, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata)); + ekey_len = spprintf(&ekey, 0, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata)); break; default: /* fall back on convert to string */ diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 0d964fd14..bdd811f8a 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ | Sara Golemon <pollita@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: http_fopen_wrapper.c,v 1.99.2.12.2.10 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.99.2.12.2.12 2008/04/08 00:03:34 iliaa Exp $ */ #include "php.h" #include "php_globals.h" @@ -105,6 +105,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *protocol_version = NULL; int protocol_version_len = 3; /* Default: "1.0" */ struct timeval timeout; + char *user_headers = NULL; tmp_line[0] = '\0'; @@ -351,10 +352,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, efree(tmp); tmp = tmp_c; } - - /* Output trimmed headers with \r\n at the end */ - php_stream_write(stream, tmp, strlen(tmp)); - php_stream_write(stream, "\r\n", sizeof("\r\n") - 1); + + user_headers = estrdup(tmp); /* Make lowercase for easy comparison against 'standard' headers */ php_strtolower(tmp, strlen(tmp)); @@ -452,6 +451,27 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, } } + if (user_headers) { + /* A bit weird, but some servers require that Content-Length be sent prior to Content-Type for POST + * see bug #44603 for details. Since Content-Type maybe part of user's headers we need to do this check first. + */ + if ( + header_init && + context && + !(have_header & HTTP_HEADER_CONTENT_LENGTH) && + php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS && + Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0 + ) { + scratch_len = slprintf(scratch, scratch_len, "Content-Length: %d\r\n", Z_STRLEN_PP(tmpzval)); + php_stream_write(stream, scratch, scratch_len); + have_header |= HTTP_HEADER_CONTENT_LENGTH; + } + + php_stream_write(stream, user_headers, strlen(user_headers)); + php_stream_write(stream, "\r\n", sizeof("\r\n")-1); + efree(user_headers); + } + /* Request content, such as for POST requests */ if (header_init && context && php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS && diff --git a/ext/standard/image.c b/ext/standard/image.c index 0356da8dc..8dbd04299 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: image.c,v 1.114.2.2.2.6 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: image.c,v 1.114.2.2.2.7 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include <stdio.h> diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c index 3f6d85bd1..d669f2ce6 100644 --- a/ext/standard/incomplete_class.c +++ b/ext/standard/incomplete_class.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ */ -/* $Id: incomplete_class.c,v 1.28.2.2.2.2 2007/02/01 14:07:43 tony2001 Exp $ */ +/* $Id: incomplete_class.c,v 1.28.2.2.2.3 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "basic_functions.h" diff --git a/ext/standard/info.c b/ext/standard/info.c index 0c6741952..6cd9057a3 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: info.c,v 1.249.2.10.2.14 2007/07/21 01:24:26 jani Exp $ */ +/* $Id: info.c,v 1.249.2.10.2.17 2008/03/05 21:09:29 pajoye Exp $ */ #include "php.h" #include "php_ini.h" @@ -277,7 +277,7 @@ PHPAPI char *php_get_uname(char mode) php_uname = tmp_uname; break; case PROCESSOR_ARCHITECTURE_MIPS : - php_uname = "MIPS R4000"; + snprintf(tmp_uname, sizeof(tmp_uname), "MIPS R%d000", SysInfo.wProcessorLevel); php_uname = tmp_uname; break; case PROCESSOR_ARCHITECTURE_ALPHA : @@ -326,6 +326,30 @@ PHPAPI char *php_get_uname(char mode) if (uname((struct utsname *)&buf) == -1) { php_uname = PHP_UNAME; } else { +#ifdef NETWARE + if (mode == 's') { + php_uname = buf.sysname; + } else if (mode == 'r') { + snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d", + buf.netware_major, buf.netware_minor, buf.netware_revision); + php_uname = tmp_uname; + } else if (mode == 'n') { + php_uname = buf.servername; + } else if (mode == 'v') { + snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d", + buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold); + php_uname = tmp_uname; + } else if (mode == 'm') { + php_uname = buf.machine; + } else { /* assume mode == 'a' */ + snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s", + buf.sysname, buf.servername, + buf.netware_major, buf.netware_minor, buf.netware_revision, + buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold, + buf.machine); + php_uname = tmp_uname; + } +#else if (mode == 's') { php_uname = buf.sysname; } else if (mode == 'r') { @@ -342,6 +366,7 @@ PHPAPI char *php_get_uname(char mode) buf.machine); php_uname = tmp_uname; } +#endif /* NETWARE */ } #else php_uname = PHP_UNAME; diff --git a/ext/standard/info.h b/ext/standard/info.h index e41257a18..931c842ef 100644 --- a/ext/standard/info.h +++ b/ext/standard/info.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: info.h,v 1.38.2.1.2.5 2007/06/09 11:44:08 sniper Exp $ */ +/* $Id: info.h,v 1.38.2.1.2.6 2007/12/31 07:20:12 sebastian Exp $ */ #ifndef INFO_H #define INFO_H diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 8939779df..578534d41 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: iptc.c,v 1.50.2.2.2.5 2007/05/10 12:23:25 tony2001 Exp $ */ +/* $Id: iptc.c,v 1.50.2.2.2.6 2007/12/31 07:20:12 sebastian Exp $ */ /* * Functions to parse & compse IPTC data. diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c index 958a2c364..c5bd5c866 100644 --- a/ext/standard/lcg.c +++ b/ext/standard/lcg.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: lcg.c,v 1.41.2.1.2.2 2007/05/17 06:38:13 rasmus Exp $ */ +/* $Id: lcg.c,v 1.41.2.1.2.3 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "php_lcg.h" diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c index 1ed2edf84..c5c6caa08 100644 --- a/ext/standard/levenshtein.c +++ b/ext/standard/levenshtein.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: levenshtein.c,v 1.34.2.1.2.3 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: levenshtein.c,v 1.34.2.1.2.4 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include <stdlib.h> diff --git a/ext/standard/link.c b/ext/standard/link.c index c352e59fb..24afc561d 100644 --- a/ext/standard/link.c +++ b/ext/standard/link.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: link.c,v 1.52.2.1.2.3 2007/07/10 13:21:11 dmitry Exp $ */ +/* $Id: link.c,v 1.52.2.1.2.4 2007/12/31 07:20:12 sebastian Exp $ */ #include "php.h" #include "php_filestat.h" diff --git a/ext/standard/mail.c b/ext/standard/mail.c index fe348786b..3f9763ba0 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mail.c,v 1.87.2.1.2.8 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: mail.c,v 1.87.2.1.2.9 2007/12/31 07:20:12 sebastian Exp $ */ #include <stdlib.h> #include <ctype.h> diff --git a/ext/standard/math.c b/ext/standard/math.c index 0d16ad2ff..8f293ae71 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: math.c,v 1.131.2.2.2.6 2007/05/23 15:01:00 iliaa Exp $ */ +/* $Id: math.c,v 1.131.2.2.2.9 2008/02/21 11:53:51 tony2001 Exp $ */ #include "php.h" #include "php_math.h" @@ -471,14 +471,13 @@ PHP_FUNCTION(pow) Returns e raised to the power of the number */ PHP_FUNCTION(exp) { - zval **num; + double num; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) { + return; } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = exp(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; + + RETURN_DOUBLE(exp(num)); } /* }}} */ diff --git a/ext/standard/md5.c b/ext/standard/md5.c index 7bc85bcf0..16c295b4b 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: md5.c,v 1.39.2.1.2.4 2007/05/27 15:29:38 nlopess Exp $ */ +/* $Id: md5.c,v 1.39.2.1.2.5 2007/12/31 07:20:13 sebastian Exp $ */ /* * md5.c - Copyright 1997 Lachlan Roche diff --git a/ext/standard/md5.h b/ext/standard/md5.h index 548b8743b..b9285c1ba 100644 --- a/ext/standard/md5.h +++ b/ext/standard/md5.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: md5.h,v 1.17.2.1.2.2 2007/05/19 20:30:35 iliaa Exp $ */ +/* $Id: md5.h,v 1.17.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef MD5_H #define MD5_H diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c index f780818a9..3c8cb93aa 100644 --- a/ext/standard/metaphone.c +++ b/ext/standard/metaphone.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: metaphone.c,v 1.28.2.1.2.4 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: metaphone.c,v 1.28.2.1.2.7 2008/02/27 01:10:56 felipe Exp $ */ /* Based on CPANs "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com> @@ -144,13 +144,18 @@ static char Lookahead(char *word, int how_far) * could be one though; or more too). */ #define Phonize(c) { \ if (p_idx >= max_buffer_len) { \ - *phoned_word = erealloc(*phoned_word, max_buffer_len + 2); \ + *phoned_word = safe_erealloc(*phoned_word, 2, sizeof(char), max_buffer_len); \ max_buffer_len += 2; \ } \ (*phoned_word)[p_idx++] = c; \ } /* Slap a null character on the end of the phoned word */ -#define End_Phoned_Word {(*phoned_word)[p_idx] = '\0';} +#define End_Phoned_Word { \ + if (p_idx == max_buffer_len) { \ + *phoned_word = safe_erealloc(*phoned_word, 1, sizeof(char), max_buffer_len); \ + } \ + (*phoned_word)[p_idx] = '\0'; \ + } /* How long is the phoned word? */ #define Phone_Len (p_idx) diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c index 552b1503b..6b26c641d 100644 --- a/ext/standard/microtime.c +++ b/ext/standard/microtime.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: microtime.c,v 1.53.2.2.2.3 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: microtime.c,v 1.53.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/microtime.h b/ext/standard/microtime.h index 9cf5806e7..ca564c55c 100644 --- a/ext/standard/microtime.h +++ b/ext/standard/microtime.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: microtime.h,v 1.14.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: microtime.h,v 1.14.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef MICROTIME_H #define MICROTIME_H diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 097b70788..7233cb3b3 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Chris Schneider <cschneid@relog.ch> | +----------------------------------------------------------------------+ */ -/* $Id: pack.c,v 1.57.2.5.2.6 2007/09/22 15:25:46 iliaa Exp $ */ +/* $Id: pack.c,v 1.57.2.5.2.7 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/pack.h b/ext/standard/pack.h index d28f0431e..88680fada 100644 --- a/ext/standard/pack.h +++ b/ext/standard/pack.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pack.h,v 1.16.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: pack.h,v 1.16.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PACK_H #define PACK_H diff --git a/ext/standard/pageinfo.c b/ext/standard/pageinfo.c index ea23c5082..1dd1c6123 100644 --- a/ext/standard/pageinfo.c +++ b/ext/standard/pageinfo.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pageinfo.c,v 1.40.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: pageinfo.c,v 1.40.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" #include "pageinfo.h" diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h index 926e88617..e3e59f96c 100644 --- a/ext/standard/pageinfo.h +++ b/ext/standard/pageinfo.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pageinfo.h,v 1.14.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: pageinfo.h,v 1.14.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PAGEINFO_H #define PAGEINFO_H diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index 02190b8df..d77edf899 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_array.h,v 1.50.2.2.2.3 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_array.h,v 1.50.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_ARRAY_H #define PHP_ARRAY_H diff --git a/ext/standard/php_assert.h b/ext/standard/php_assert.h index abc02f962..b3c61c1bf 100644 --- a/ext/standard/php_assert.h +++ b/ext/standard/php_assert.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_assert.h,v 1.15.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_assert.h,v 1.15.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_ASSERT_H #define PHP_ASSERT_H diff --git a/ext/standard/php_browscap.h b/ext/standard/php_browscap.h index 074786bd2..a5a79c7a8 100644 --- a/ext/standard/php_browscap.h +++ b/ext/standard/php_browscap.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_browscap.h,v 1.13.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_browscap.h,v 1.13.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_BROWSCAP_H #define PHP_BROWSCAP_H diff --git a/ext/standard/php_crypt.h b/ext/standard/php_crypt.h index f212c4590..1a631057c 100644 --- a/ext/standard/php_crypt.h +++ b/ext/standard/php_crypt.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_crypt.h,v 1.18.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_crypt.h,v 1.18.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_CRYPT_H #define PHP_CRYPT_H diff --git a/ext/standard/php_dir.h b/ext/standard/php_dir.h index d21331f32..14fb5d69f 100644 --- a/ext/standard/php_dir.h +++ b/ext/standard/php_dir.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dir.h,v 1.24.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_dir.h,v 1.24.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_DIR_H #define PHP_DIR_H diff --git a/ext/standard/php_ext_syslog.h b/ext/standard/php_ext_syslog.h index bf83de826..e5ff1e918 100644 --- a/ext/standard/php_ext_syslog.h +++ b/ext/standard/php_ext_syslog.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ext_syslog.h,v 1.12.2.2.2.2 2007/05/17 06:38:13 rasmus Exp $ */ +/* $Id: php_ext_syslog.h,v 1.12.2.2.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_EXT_SYSLOG_H #define PHP_EXT_SYSLOG_H diff --git a/ext/standard/php_filestat.h b/ext/standard/php_filestat.h index d30cf37de..bd66459ba 100644 --- a/ext/standard/php_filestat.h +++ b/ext/standard/php_filestat.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_filestat.h,v 1.24.2.4.2.2 2007/10/31 13:23:06 jani Exp $ */ +/* $Id: php_filestat.h,v 1.24.2.4.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_FILESTAT_H #define PHP_FILESTAT_H diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 6afbc4531..64e05e0c3 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_fopen_wrapper.c,v 1.45.2.4.2.8 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: php_fopen_wrapper.c,v 1.45.2.4.2.9 2007/12/31 07:20:13 sebastian Exp $ */ #include <stdio.h> #include <stdlib.h> diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h index c63022b01..b32ae7272 100644 --- a/ext/standard/php_fopen_wrappers.h +++ b/ext/standard/php_fopen_wrappers.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_fopen_wrappers.h,v 1.21.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_fopen_wrappers.h,v 1.21.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_FOPEN_WRAPPERS_H #define PHP_FOPEN_WRAPPERS_H diff --git a/ext/standard/php_ftok.h b/ext/standard/php_ftok.h index 444761029..c3b4b9825 100644 --- a/ext/standard/php_ftok.h +++ b/ext/standard/php_ftok.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ftok.h,v 1.9.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_ftok.h,v 1.9.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_FTOK_H #define PHP_FTOK_H diff --git a/ext/standard/php_http.h b/ext/standard/php_http.h index 806beaaa8..9097a67de 100644 --- a/ext/standard/php_http.h +++ b/ext/standard/php_http.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.5.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_http.h,v 1.5.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_HTTP_H #define PHP_HTTP_H diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h index 37812fbff..33f8495e9 100644 --- a/ext/standard/php_image.h +++ b/ext/standard/php_image.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_image.h,v 1.29.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_image.h,v 1.29.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_IMAGE_H #define PHP_IMAGE_H diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h index b194ede8d..8d3061af3 100644 --- a/ext/standard/php_incomplete_class.h +++ b/ext/standard/php_incomplete_class.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_incomplete_class.h,v 1.17.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_incomplete_class.h,v 1.17.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_INCOMPLETE_CLASS_H #define PHP_INCOMPLETE_CLASS_H diff --git a/ext/standard/php_iptc.h b/ext/standard/php_iptc.h index c85b84ab2..18d77e3f8 100644 --- a/ext/standard/php_iptc.h +++ b/ext/standard/php_iptc.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_iptc.h,v 1.11.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_iptc.h,v 1.11.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_IPTC_H #define PHP_IPTC_H diff --git a/ext/standard/php_lcg.h b/ext/standard/php_lcg.h index 9e04442e5..93aa78e64 100644 --- a/ext/standard/php_lcg.h +++ b/ext/standard/php_lcg.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_lcg.h,v 1.21.2.1.2.2 2007/05/18 11:36:55 rasmus Exp $ */ +/* $Id: php_lcg.h,v 1.21.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_LCG_H #define PHP_LCG_H diff --git a/ext/standard/php_link.h b/ext/standard/php_link.h index 0cde3a678..353f5dc27 100644 --- a/ext/standard/php_link.h +++ b/ext/standard/php_link.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_link.h,v 1.12.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_link.h,v 1.12.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_LINK_H #define PHP_LINK_H diff --git a/ext/standard/php_mail.h b/ext/standard/php_mail.h index f159bc916..7b249a015 100644 --- a/ext/standard/php_mail.h +++ b/ext/standard/php_mail.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_mail.h,v 1.18.2.1.2.2 2007/07/11 17:36:56 johannes Exp $ */ +/* $Id: php_mail.h,v 1.18.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_MAIL_H #define PHP_MAIL_H diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h index e7766a57a..84b750a0e 100644 --- a/ext/standard/php_math.h +++ b/ext/standard/php_math.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_math.h,v 1.28.2.2.2.3 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_math.h,v 1.28.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_MATH_H #define PHP_MATH_H diff --git a/ext/standard/php_metaphone.h b/ext/standard/php_metaphone.h index b886a357f..3706392bc 100644 --- a/ext/standard/php_metaphone.h +++ b/ext/standard/php_metaphone.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_metaphone.h,v 1.16.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_metaphone.h,v 1.16.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_METAPHONE_H #define PHP_METAPHONE_H diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h index b6bb2c348..7a12d2466 100644 --- a/ext/standard/php_rand.h +++ b/ext/standard/php_rand.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -20,7 +20,7 @@ | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | +----------------------------------------------------------------------+ */ -/* $Id: php_rand.h,v 1.28.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_rand.h,v 1.28.2.1.2.4 2008/03/07 08:56:45 tony2001 Exp $ */ #ifndef PHP_RAND_H #define PHP_RAND_H @@ -47,9 +47,9 @@ #define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */ #ifdef PHP_WIN32 -#define GENERATE_SEED() ((long) (time(0) * GetCurrentProcessId() * 1000000 * php_combined_lcg(TSRMLS_C))) +#define GENERATE_SEED() (((long) (time(0) * GetCurrentProcessId())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) #else -#define GENERATE_SEED() ((long) (time(0) * getpid() * 1000000 * php_combined_lcg(TSRMLS_C))) +#define GENERATE_SEED() (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) #endif PHPAPI void php_srand(long seed TSRMLS_DC); diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h index 4e8eb52fc..fd6dfb6dc 100644 --- a/ext/standard/php_smart_str.h +++ b/ext/standard/php_smart_str.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_smart_str.h,v 1.30.2.3.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_smart_str.h,v 1.30.2.3.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_SMART_STR_H #define PHP_SMART_STR_H diff --git a/ext/standard/php_smart_str_public.h b/ext/standard/php_smart_str_public.h index d71d30618..2d119e790 100644 --- a/ext/standard/php_smart_str_public.h +++ b/ext/standard/php_smart_str_public.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_smart_str_public.h,v 1.10.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_smart_str_public.h,v 1.10.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_SMART_STR_PUBLIC_H #define PHP_SMART_STR_PUBLIC_H diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h index e210bf6fb..dd41fc25a 100644 --- a/ext/standard/php_standard.h +++ b/ext/standard/php_standard.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_standard.h,v 1.24.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_standard.h,v 1.24.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #include "basic_functions.h" #include "php_math.h" diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index b4936d84e..c2b038fdd 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_string.h,v 1.87.2.2.2.3 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_string.h,v 1.87.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ diff --git a/ext/standard/php_type.h b/ext/standard/php_type.h index fee24bdf7..bd170239e 100644 --- a/ext/standard/php_type.h +++ b/ext/standard/php_type.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_type.h,v 1.6.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_type.h,v 1.6.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_TYPE_H #define PHP_TYPE_H diff --git a/ext/standard/php_uuencode.h b/ext/standard/php_uuencode.h index 908d64e6e..0bab2fc6c 100644 --- a/ext/standard/php_uuencode.h +++ b/ext/standard/php_uuencode.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_uuencode.h,v 1.4.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_uuencode.h,v 1.4.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_UUENCODE_H #define PHP_UUENCODE_H diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h index 0c9693049..19527286b 100644 --- a/ext/standard/php_var.h +++ b/ext/standard/php_var.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_var.h,v 1.30.2.1.2.6 2007/05/22 14:34:22 tony2001 Exp $ */ +/* $Id: php_var.h,v 1.30.2.1.2.7 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_VAR_H #define PHP_VAR_H diff --git a/ext/standard/php_versioning.h b/ext/standard/php_versioning.h index a23aa7506..2f502e305 100644 --- a/ext/standard/php_versioning.h +++ b/ext/standard/php_versioning.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_versioning.h,v 1.10.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_versioning.h,v 1.10.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef PHP_VERSIONING_H #define PHP_VERSIONING_H diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 2ef4b6790..69fca4d71 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: proc_open.c,v 1.36.2.1.2.17 2007/09/12 11:42:43 nlopess Exp $ */ +/* $Id: proc_open.c,v 1.36.2.1.2.19 2008/04/08 08:45:51 jani Exp $ */ #if 0 && (defined(__linux__) || defined(sun) || defined(__IRIX__)) # define _BSD_SOURCE /* linux wants this when XOPEN mode is on */ @@ -624,7 +624,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } - if (strcmp(Z_STRVAL_PP(zmode), "w") != 0) { + if (strncmp(Z_STRVAL_PP(zmode), "w", 1) != 0) { descriptors[ndesc].parentend = newpipe[1]; descriptors[ndesc].childend = newpipe[0]; descriptors[ndesc].mode |= DESC_PARENT_MODE_WRITE; diff --git a/ext/standard/proc_open.h b/ext/standard/proc_open.h index 520a83e92..10625f5b1 100644 --- a/ext/standard/proc_open.h +++ b/ext/standard/proc_open.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: proc_open.h,v 1.5.2.1.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: proc_open.h,v 1.5.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifdef PHP_WIN32 typedef HANDLE php_file_descriptor_t; diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c index a8ba0f8c2..b57d826a6 100644 --- a/ext/standard/quot_print.c +++ b/ext/standard/quot_print.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: quot_print.c,v 1.29.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: quot_print.c,v 1.29.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #include <stdlib.h> diff --git a/ext/standard/quot_print.h b/ext/standard/quot_print.h index 9ffc9286b..37a10ff2e 100644 --- a/ext/standard/quot_print.h +++ b/ext/standard/quot_print.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: quot_print.h,v 1.13.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: quot_print.h,v 1.13.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef QUOT_PRINT_H #define QUOT_PRINT_H diff --git a/ext/standard/rand.c b/ext/standard/rand.c index d9161a15f..eee131b78 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -23,7 +23,7 @@ | Shawn Cokus <Cokus@math.washington.edu> | +----------------------------------------------------------------------+ */ -/* $Id: rand.c,v 1.70.2.1.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: rand.c,v 1.70.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #include <stdlib.h> diff --git a/ext/standard/reg.c b/ext/standard/reg.c index beacf285f..3c3a02c54 100644 --- a/ext/standard/reg.c +++ b/ext/standard/reg.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> | +----------------------------------------------------------------------+ */ -/* $Id: reg.c,v 1.82.2.3.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: reg.c,v 1.82.2.3.2.5 2008/04/20 01:43:18 felipe Exp $ */ #include <stdio.h> #include <ctype.h> @@ -564,7 +564,9 @@ static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase) } else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) { /* No more matches */ regfree(&re); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Regular Expression to split()"); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Regular Expression"); + zend_hash_destroy(Z_ARRVAL_P(return_value)); efree(Z_ARRVAL_P(return_value)); RETURN_FALSE; diff --git a/ext/standard/reg.h b/ext/standard/reg.h index 2d3b7e8ea..6557916cf 100644 --- a/ext/standard/reg.h +++ b/ext/standard/reg.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ */ -/* $Id: reg.h,v 1.21.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: reg.h,v 1.21.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef REG_H #define REG_H diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c index 26e5e1783..d5c591d1f 100644 --- a/ext/standard/scanf.c +++ b/ext/standard/scanf.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: scanf.c,v 1.31.2.2.2.5 2007/07/26 15:24:06 jani Exp $ */ +/* $Id: scanf.c,v 1.31.2.2.2.6 2007/12/31 07:20:13 sebastian Exp $ */ /* scanf.c -- diff --git a/ext/standard/scanf.h b/ext/standard/scanf.h index 391c9d504..25ef8c45c 100644 --- a/ext/standard/scanf.h +++ b/ext/standard/scanf.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: scanf.h,v 1.14.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: scanf.h,v 1.14.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef SCANF_H #define SCANF_H diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c index 9db3afe76..1fae65324 100644 --- a/ext/standard/sha1.c +++ b/ext/standard/sha1.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sha1.c,v 1.13.2.1.2.3 2007/05/27 14:50:09 sniper Exp $ */ +/* $Id: sha1.c,v 1.13.2.1.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/sha1.h b/ext/standard/sha1.h index fc9049000..a29f96190 100644 --- a/ext/standard/sha1.h +++ b/ext/standard/sha1.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sha1.h,v 1.5.2.1.2.2 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: sha1.h,v 1.5.2.1.2.3 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef SHA1_H #define SHA1_H diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c index 31f803dff..20ee0b73a 100644 --- a/ext/standard/soundex.c +++ b/ext/standard/soundex.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no> | +----------------------------------------------------------------------+ */ -/* $Id: soundex.c,v 1.25.2.1.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: soundex.c,v 1.25.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" #include <stdlib.h> diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 7963e529a..c8542fba8 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.c,v 1.58.2.6.2.16 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: streamsfuncs.c,v 1.58.2.6.2.19 2008/02/03 16:15:30 iliaa Exp $ */ #include "php.h" #include "php_globals.h" @@ -1325,6 +1325,9 @@ PHP_FUNCTION(stream_socket_enable_crypto) if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) { RETURN_FALSE; } + } else if (enable) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type"); + RETURN_FALSE; } ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC); @@ -1361,7 +1364,7 @@ PHP_FUNCTION(stream_is_local) wrapper = stream->wrapper; } else { convert_to_string_ex(&zstream); - wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC); + wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0 TSRMLS_CC); } if(!wrapper) { diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index f2ad960f4..b966ed57d 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.h,v 1.13.2.1.2.4 2007/07/09 17:27:24 dmitry Exp $ */ +/* $Id: streamsfuncs.h,v 1.13.2.1.2.5 2007/12/31 07:20:13 sebastian Exp $ */ /* Flags for stream_socket_client */ #define PHP_STREAM_CLIENT_PERSISTENT 1 diff --git a/ext/standard/string.c b/ext/standard/string.c index c1e898ea2..8125c18e2 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.14.2.70 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: string.c,v 1.445.2.14.2.73 2008/01/16 08:35:59 tony2001 Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -452,15 +452,182 @@ PHP_MINIT_FUNCTION(nl_langinfo) Query language and locale information */ PHP_FUNCTION(nl_langinfo) { - zval **item; + long item; char *value; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &item) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &item) == FAILURE) { + return; + } + + switch(item) { /* {{{ */ +#ifdef ABDAY_1 + case ABDAY_1: + case ABDAY_2: + case ABDAY_3: + case ABDAY_4: + case ABDAY_5: + case ABDAY_6: + case ABDAY_7: +#endif +#ifdef DAY_1 + case DAY_1: + case DAY_2: + case DAY_3: + case DAY_4: + case DAY_5: + case DAY_6: + case DAY_7: +#endif +#ifdef ABMON_1 + case ABMON_1: + case ABMON_2: + case ABMON_3: + case ABMON_4: + case ABMON_5: + case ABMON_6: + case ABMON_7: + case ABMON_8: + case ABMON_9: + case ABMON_10: + case ABMON_11: + case ABMON_12: +#endif +#ifdef MON_1 + case MON_1: + case MON_2: + case MON_3: + case MON_4: + case MON_5: + case MON_6: + case MON_7: + case MON_8: + case MON_9: + case MON_10: + case MON_11: + case MON_12: +#endif +#ifdef AM_STR + case AM_STR: +#endif +#ifdef PM_STR + case PM_STR: +#endif +#ifdef D_T_FMT + case D_T_FMT: +#endif +#ifdef D_FMT + case D_FMT: +#endif +#ifdef T_FMT + case T_FMT: +#endif +#ifdef T_FMT_AMPM + case T_FMT_AMPM: +#endif +#ifdef ERA + case ERA: +#endif +#ifdef ERA_YEAR + case ERA_YEAR: +#endif +#ifdef ERA_D_T_FMT + case ERA_D_T_FMT: +#endif +#ifdef ERA_D_FMT + case ERA_D_FMT: +#endif +#ifdef ERA_T_FMT + case ERA_T_FMT: +#endif +#ifdef ALT_DIGITS + case ALT_DIGITS: +#endif +#ifdef INT_CURR_SYMBOL + case INT_CURR_SYMBOL: +#endif +#ifdef CURRENCY_SYMBOL + case CURRENCY_SYMBOL: +#endif +#ifdef CRNCYSTR + case CRNCYSTR: +#endif +#ifdef MON_DECIMAL_POINT + case MON_DECIMAL_POINT: +#endif +#ifdef MON_THOUSANDS_SEP + case MON_THOUSANDS_SEP: +#endif +#ifdef MON_GROUPING + case MON_GROUPING: +#endif +#ifdef POSITIVE_SIGN + case POSITIVE_SIGN: +#endif +#ifdef NEGATIVE_SIGN + case NEGATIVE_SIGN: +#endif +#ifdef INT_FRAC_DIGITS + case INT_FRAC_DIGITS: +#endif +#ifdef FRAC_DIGITS + case FRAC_DIGITS: +#endif +#ifdef P_CS_PRECEDES + case P_CS_PRECEDES: +#endif +#ifdef P_SEP_BY_SPACE + case P_SEP_BY_SPACE: +#endif +#ifdef N_CS_PRECEDES + case N_CS_PRECEDES: +#endif +#ifdef N_SEP_BY_SPACE + case N_SEP_BY_SPACE: +#endif +#ifdef P_SIGN_POSN + case P_SIGN_POSN: +#endif +#ifdef N_SIGN_POSN + case N_SIGN_POSN: +#endif +#ifdef DECIMAL_POINT + case DECIMAL_POINT: +#endif +#ifdef RADIXCHAR + case RADIXCHAR: +#endif +#ifdef THOUSANDS_SEP + case THOUSANDS_SEP: +#endif +#ifdef THOUSEP + case THOUSEP: +#endif +#ifdef GROUPING + case GROUPING: +#endif +#ifdef YESEXPR + case YESEXPR: +#endif +#ifdef NOEXPR + case NOEXPR: +#endif +#ifdef YESSTR + case YESSTR: +#endif +#ifdef NOSTR + case NOSTR: +#endif +#ifdef CODESET + case CODESET: +#endif + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Item '%ld' is not valid", item); + RETURN_FALSE; } - convert_to_long_ex(item); + /* }}} */ - value = nl_langinfo(Z_LVAL_PP(item)); + value = nl_langinfo(item); if (value == NULL) { RETURN_FALSE; } else { @@ -4966,7 +5133,7 @@ PHP_FUNCTION(str_word_count) while (p < e) { s = p; - while (p < e && (isalpha(*p) || (char_list && ch[(unsigned char)*p]) || *p == '\'' || *p == '-')) { + while (p < e && (isalpha((unsigned char)*p) || (char_list && ch[(unsigned char)*p]) || *p == '\'' || *p == '-')) { p++; } if (p > s) { diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c index a3a2391a6..985bb8411 100644 --- a/ext/standard/syslog.c +++ b/ext/standard/syslog.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: syslog.c,v 1.49.2.3.2.2 2007/05/17 06:38:13 rasmus Exp $ */ +/* $Id: syslog.c,v 1.49.2.3.2.4 2008/02/20 15:28:37 iliaa Exp $ */ #include "php.h" @@ -110,6 +110,7 @@ PHP_RINIT_FUNCTION(syslog) } else { BG(syslog_started)=0; } + BG(syslog_device) = NULL; return SUCCESS; } @@ -126,6 +127,7 @@ PHP_MSHUTDOWN_FUNCTION(syslog) { if (BG(syslog_device)) { free(BG(syslog_device)); + BG(syslog_device) = NULL; } return SUCCESS; } diff --git a/ext/standard/tests/array/array_change_key_case_variation1.phpt b/ext/standard/tests/array/array_change_key_case_variation1.phpt new file mode 100644 index 000000000..e70774e01 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation1.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $input argument to test behaviour of array_change_key_case() + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_change_key_case($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_change_key_case_variation2.phpt b/ext/standard/tests/array/array_change_key_case_variation2.phpt new file mode 100644 index 000000000..cce432e8d --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation2.phpt @@ -0,0 +1,318 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Pass different data types as $case arg +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $case argument to array_change_key_case() to test behaviour + * Where possible, CASE_UPPER has been entered as a string value + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$array = array ('one' => 1, 'TWO' => 2, 'Three' => 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +CASE_UPPER +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $case argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "CASE_UPPER", + 'CASE_UPPER', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_change_key_case($array, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 2 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 3 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 4 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 5 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 6 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 7 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 8 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 12 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 15 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 16 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 17 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 18 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 19 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 20 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 21 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 22 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 23 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation3.phpt b/ext/standard/tests/array/array_change_key_case_variation3.phpt new file mode 100644 index 000000000..596703385 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation3.phpt @@ -0,0 +1,197 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different data types as keys +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays with different data types as keys to array_change_key_case() + * to test conversion + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_change_key_case($input, CASE_UPPER) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 : int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 : float data -- +array(3) { + [10]=> + string(8) "positive" + [-10]=> + string(8) "negative" + [0]=> + string(4) "half" +} + +-- Iteration 3 : extreme floats data -- +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} + +-- Iteration 4 : null uppercase data -- +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 : null lowercase data -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 : bool lowercase data -- +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} + +-- Iteration 7 : bool uppercase data -- +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} + +-- Iteration 8 : empty double quotes data -- +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 : empty single quotes data -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 : string data -- +array(3) { + ["STRINGD"]=> + string(7) "stringd" + ["STRINGS"]=> + string(7) "strings" + ["HELLO WORLD"]=> + string(7) "stringh" +} + +-- Iteration 11 : undefined data -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 : unset data -- +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation4.phpt b/ext/standard/tests/array/array_change_key_case_variation4.phpt new file mode 100644 index 000000000..ad9ad75a3 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation4.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different int values for $case +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different integer values as $case argument to array_change_key_case() to test behaviour + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('One' => 'un', 'TWO' => 'deux', 'three' => 'trois'); +for ($i = -5; $i <=5; $i += 1){ + echo "\n-- \$sort argument is $i --\n"; + $temp = $input; + var_dump(array_change_key_case($temp, $i)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $sort argument is -5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 0 -- +array(3) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["three"]=> + string(5) "trois" +} + +-- $sort argument is 1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation5.phpt b/ext/standard/tests/array/array_change_key_case_variation5.phpt new file mode 100644 index 000000000..aa3852a41 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation5.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_change_key_case() function : usage variations - position of internal pointer +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling the function + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_change_key_case() --\n"; +var_dump($result = array_change_key_case($input, CASE_UPPER)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Call array_change_key_case() -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +ONE => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation6.phpt b/ext/standard/tests/array/array_change_key_case_variation6.phpt new file mode 100644 index 000000000..d4371d345 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_change_key_case() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test how array_change_key_case() converts keys in multi-dimensional arrays + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('English' => array('one' => 1, 'two' => 2, 'three' => 3), + 'French' => array('un' => 1, 'deux' => 2, 'trois' => 3), + 'German' => array('eins' => 1, 'zwei' => 2, 'drei' => 3)); + +echo "\n-- Pass a two-dimensional array as \$input argument --\n"; +var_dump(array_change_key_case($input, CASE_UPPER)); + +echo "\n-- Pass a sub-arry as \$input argument --\n"; +var_dump(array_change_key_case($input['English'], CASE_UPPER)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Pass a two-dimensional array as $input argument -- +array(3) { + ["ENGLISH"]=> + array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + } + ["FRENCH"]=> + array(3) { + ["un"]=> + int(1) + ["deux"]=> + int(2) + ["trois"]=> + int(3) + } + ["GERMAN"]=> + array(3) { + ["eins"]=> + int(1) + ["zwei"]=> + int(2) + ["drei"]=> + int(3) + } +} + +-- Pass a sub-arry as $input argument -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation7.phpt b/ext/standard/tests/array/array_change_key_case_variation7.phpt new file mode 100644 index 000000000..173a7ec4d --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation7.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_change_key_case() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test array_change_key_case() when: + * 1. Passed a referenced variable + * 2. Passed an argument by reference + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('one' => 1, 'two' => 2, 'ABC' => 'xyz'); + +echo "\n-- \$input argument is a reference to array --\n"; +$new_input = &$input; +echo "Result:\n"; +var_dump(array_change_key_case($new_input, CASE_UPPER)); +echo "Original:\n"; +var_dump($input); +echo "Referenced:\n"; +var_dump($new_input); + +echo "\n-- \$input is an array passed by reference --\n"; +echo "Result:\n"; +var_dump(array_change_key_case(&$input, CASE_UPPER)); +echo "Original:\n"; +var_dump($input); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $input argument is a reference to array -- +Result: +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Original: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Referenced: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} + +-- $input is an array passed by reference -- +Result: +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Original: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Done diff --git a/ext/standard/tests/array/array_change_key_case_variation8.phpt b/ext/standard/tests/array/array_change_key_case_variation8.phpt new file mode 100644 index 000000000..f9893da79 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation8.phpt @@ -0,0 +1,128 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Different strings as keys +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test how array_change_key_case() behaves with different strings + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$inputs = array ( + // group of escape sequences + array(null => 1, NULL => 2, "\a" => 3, "\cx" => 4, "\e" => 5, "\f" => 6, "\n" => 7, "\t" => 8, "\xhh" => 9, "\ddd" => 10, "\v" => 11), + + // array contains combination of capital/small letters + array("lemoN" => 1, "Orange" => 2, "banana" => 3, "apple" => 4, "Test" => 5, "TTTT" => 6, "ttt" => 7, "ww" => 8, "x" => 9, "X" => 10, "oraNGe" => 11, "BANANA" => 12) +); + +foreach($inputs as $input) { + echo "\n-- \$case = default --\n"; + var_dump(array_change_key_case($input)); + echo "-- \$case = upper --\n"; + var_dump(array_change_key_case($input, CASE_UPPER)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $case = default -- +array(10) { + [""]=> + int(2) + ["\a"]=> + int(3) + ["\cx"]=> + int(4) + ["\e"]=> + int(5) + [""]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\xhh"]=> + int(9) + ["\ddd"]=> + int(10) + [""]=> + int(11) +} +-- $case = upper -- +array(10) { + [""]=> + int(2) + ["\A"]=> + int(3) + ["\CX"]=> + int(4) + ["\E"]=> + int(5) + [""]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\XHH"]=> + int(9) + ["\DDD"]=> + int(10) + [""]=> + int(11) +} + +-- $case = default -- +array(9) { + ["lemon"]=> + int(1) + ["orange"]=> + int(11) + ["banana"]=> + int(12) + ["apple"]=> + int(4) + ["test"]=> + int(5) + ["tttt"]=> + int(6) + ["ttt"]=> + int(7) + ["ww"]=> + int(8) + ["x"]=> + int(10) +} +-- $case = upper -- +array(9) { + ["LEMON"]=> + int(1) + ["ORANGE"]=> + int(11) + ["BANANA"]=> + int(12) + ["APPLE"]=> + int(4) + ["TEST"]=> + int(5) + ["TTTT"]=> + int(6) + ["TTT"]=> + int(7) + ["WW"]=> + int(8) + ["X"]=> + int(10) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_chunk_basic1.phpt b/ext/standard/tests/array/array_chunk_basic1.phpt new file mode 100644 index 000000000..56a90f479 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic1.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_chunk() function : basic functionality - defualt 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array ( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/witout keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) + +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_basic2.phpt b/ext/standard/tests/array/array_chunk_basic2.phpt new file mode 100644 index 000000000..f96d863e1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic2.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test array_chunk() function : basic functionality - 'preserve_keys' as true/false +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/without keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(1) { + [4]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [2]=> + string(6) "value3" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + ["key1"]=> + int(1) + ["key2"]=> + int(2) + } + [1]=> + array(1) { + ["key3"]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(1) { + [3]=> + string(5) "three" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(2) { + [3]=> + string(5) "three" + [4]=> + int(4) + } + [2]=> + array(1) { + ["five"]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_error.phpt b/ext/standard/tests/array/array_chunk_error.phpt new file mode 100644 index 000000000..519794599 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_chunk() function : error conditions +--FILE-- +<?php +/* Prototype : array array_chunk(array input, int size [, bool preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_chunk() function with zero arguments --\n"; +var_dump( array_chunk() ); + +echo "\n-- Testing array_chunk() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$size = 10; +$preserve_keys = true; +$extra_arg = 10; +var_dump( array_chunk($input,$size,$preserve_keys, $extra_arg) ); + +echo "\n-- Testing array_chunk() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +var_dump( array_chunk($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : error conditions *** + +-- Testing array_chunk() function with zero arguments -- + +Warning: array_chunk() expects at least 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_chunk() function with more than expected no. of arguments -- + +Warning: array_chunk() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing array_chunk() function with less than expected no. of arguments -- + +Warning: array_chunk() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation1.phpt b/ext/standard/tests/array/array_chunk_variation1.phpt new file mode 100644 index 000000000..caaf274dd --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation1.phpt @@ -0,0 +1,325 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : proto array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'array' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// Initialise function arguments +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new stdclass(), + + // undefined data +/*21*/ @undefined_var, + + // unset data +/*22*/ @unset_var + +); + +$count = 1; +// loop through each element of the array for input +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($value, $size) ); + var_dump( array_chunk($value, $size, true) ); + var_dump( array_chunk($value, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation2.phpt b/ext/standard/tests/array/array_chunk_variation2.phpt new file mode 100644 index 000000000..8cfe99440 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation2.phpt @@ -0,0 +1,427 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'size' argument +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'size' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array ( + + // float data +/*1*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new stdclass(), + + // undefined data +/*22*/ @undefined_var, + + // unset data +/*23*/ @unset_var + +); + +// loop through each element of the array for size +$count = 1; +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $value) ); + var_dump( array_chunk($input, $value, true) ); + var_dump( array_chunk($input, $value, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 13 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 14 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 15 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation3.phpt b/ext/standard/tests/array/array_chunk_variation3.phpt new file mode 100644 index 000000000..452006a44 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation3.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'preserve_keys' +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // empty data +/*12*/ "", + '', + + // string data +/*14*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var + +); + +$count = 1; + +// loop through each element of the array for preserve_keys +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $size, $value) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 5 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 6 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 7 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 8 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 10 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 11 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 12 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 13 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 14 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 15 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 3 to be boolean, object given in %s on line %d +NULL + +-- Iteration 17 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 18 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation4.phpt b/ext/standard/tests/array/array_chunk_variation4.phpt new file mode 100644 index 000000000..7f04f51bf --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation4.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_chunk() function : usage variations - array with diff. sub arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function - input array containing different sub arrays +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +// input array +$input_array = array ( + "array1" => array(), + "array2" => array(1, 2, 3), + "array3" => array(1) +); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt --\n"; +var_dump( array_chunk($input_array, $size) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true --\n"; +var_dump( array_chunk($input_array, $size, true) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false --\n"; +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true -- +array(2) { + [0]=> + array(2) { + ["array1"]=> + array(0) { + } + ["array2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + ["array3"]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation5.phpt b/ext/standard/tests/array/array_chunk_variation5.phpt new file mode 100644 index 000000000..8d3609282 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation5.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_chunk() function : usage variations - different 'size' values +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. -ve size value + * 2. size value is more than the no. of elements in the input array + * 3. size value is zero + * 4. Decimal size value +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_array = array(1, 2, 3); + +// different magnitude's +$sizes = array(-1, count($input_array) + 1, 0, 1.5); + +// loop through the array for size argument +foreach ($sizes as $size){ + echo "\n-- Testing array_chunk() when size = $size --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); +} +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() when size = -1 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 4 -- +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Testing array_chunk() when size = 0 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 1.5 -- +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation6.phpt b/ext/standard/tests/array/array_chunk_variation6.phpt new file mode 100644 index 000000000..f44eb3960 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation6.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test array_chunk() function : usage variations - different arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. array without elements + * 2. associative array with duplicate keys + * 3. array with one element +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_arrays = array ( + + // array without elements + "array1" => array(), + + // array with one element + "array2" => array(1), + + // associative array with duplicate keys + "array3" => array("a" => 1, "b" => 2, "c" => 3, "a" => 4, "d" => 5) + +); + +$size = 2; +$count = 1; + +echo "\n-- Testing array_chunk() by supplying various arrays --\n"; + +// loop through the array for 'array' argument +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying various arrays -- + +-- Iteration 1 -- +array(0) { +} +array(0) { +} +array(0) { +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + ["a"]=> + int(4) + ["b"]=> + int(2) + } + [1]=> + array(2) { + ["c"]=> + int(3) + ["d"]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation7.phpt b/ext/standard/tests/array/array_chunk_variation7.phpt new file mode 100644 index 000000000..c8a71964f --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation7.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test array_chunk() function : usage variations - references +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. input array containing references +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +echo "\n-- Testing array_chunk(), input array containing references \n"; + +$numbers=array(1, 2, 3, 4); +// reference array +$input_array = array ( + "one" => &$numbers[0], + "two" => &$numbers[1], + "three" => &$numbers[2], + "four" => &$numbers[3] +); + +var_dump( array_chunk($input_array, $size) ); +var_dump( array_chunk($input_array, $size, true) ); +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk(), input array containing references +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + ["one"]=> + &int(1) + ["two"]=> + &int(2) + } + [1]=> + array(2) { + ["three"]=> + &int(3) + ["four"]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +Done diff --git a/ext/standard/tests/array/array_combine_basic.phpt b/ext/standard/tests/array/array_combine_basic.phpt new file mode 100644 index 000000000..5d855cfec --- /dev/null +++ b/ext/standard/tests/array/array_combine_basic.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_combine() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : basic functionality ***\n"; + +/* Different arrays for $keys and $values arguments */ + +// array with default keys for $keys and $values arguments +$keys_array = array(1, 2); +$values_array = array(3,4); +var_dump( array_combine($keys_array, $values_array) ); + +// associative arrays for $keys and $values arguments +$keys_array = array(1 => "a", 2 => 'b'); +$values_array = array(3 => 'c', 4 => "d"); +var_dump( array_combine($keys_array, $values_array) ); + +// mixed array for $keys and $values arguments +$keys_array = array(1, 2 => "b"); +$values_array = array(3 => 'c', 4); +var_dump( array_combine($keys_array, $values_array) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : basic functionality *** +array(2) { + [1]=> + int(3) + [2]=> + int(4) +} +array(2) { + ["a"]=> + string(1) "c" + ["b"]=> + string(1) "d" +} +array(2) { + [1]=> + string(1) "c" + ["b"]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_combine_error1.phpt b/ext/standard/tests/array/array_combine_error1.phpt new file mode 100644 index 000000000..aa5a1afe1 --- /dev/null +++ b/ext/standard/tests/array/array_combine_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_combine() function : error conditions +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_combine() function with Zero arguments --\n"; +var_dump( array_combine() ); + +//Test array_combine with one more than the expected number of arguments +echo "\n-- Testing array_combine() function with more than expected no. of arguments --\n"; +$keys = array(1, 2); +$values = array(1, 2); +$extra_arg = 10; +var_dump( array_combine($keys,$values, $extra_arg) ); + +// Testing array_combine with one less than the expected number of arguments +echo "\n-- Testing array_combine() function with less than expected no. of arguments --\n"; +$keys = array(1, 2); +var_dump( array_combine($keys) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : error conditions *** + +-- Testing array_combine() function with Zero arguments -- + +Warning: array_combine() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_combine() function with more than expected no. of arguments -- + +Warning: array_combine() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +-- Testing array_combine() function with less than expected no. of arguments -- + +Warning: array_combine() expects exactly 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_error2.phpt b/ext/standard/tests/array/array_combine_error2.phpt new file mode 100644 index 000000000..c06fdb490 --- /dev/null +++ b/ext/standard/tests/array/array_combine_error2.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_combine() function : error conditions - empty array +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : error conditions specific to array_combine() ***\n"; + +// Testing array_combine by passing empty arrays to $keys and $values arguments +echo "\n-- Testing array_combine() function with empty arrays --\n"; +var_dump( array_combine(array(), array()) ); + +// Testing array_combine by passing empty array to $keys +echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n"; +var_dump( array_combine(array(), array(1, 2)) ); + +// Testing array_combine by passing empty array to $values +echo "\n-- Testing array_combine() function with empty array for \$values argument --\n"; +var_dump( array_combine(array(1, 2), array()) ); + +// Testing array_combine with arrays having unequal number of elements +echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n"; +var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : error conditions specific to array_combine() *** + +-- Testing array_combine() function with empty arrays -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) + +-- Testing array_combine() function with empty array for $keys argument -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) + +-- Testing array_combine() function with empty array for $values argument -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) + +-- Testing array_combine() function by passing array with unequal number of elements -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_combine_variation1.phpt b/ext/standard/tests/array/array_combine_variation1.phpt new file mode 100644 index 000000000..c69d4ebaf --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation1.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test array_combine() function : usage variations - unexpected values for 'keys' argument +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_combine() function by passing values to $keys argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $values argument passed is a fixed array. +*/ + +echo "*** Testing array_combine() : Passing non-array values to \$keys argument ***\n"; + +// Initialise $values argument +$values = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $keys argument +$keys_passed = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element within $keys_passed to check the behavior of array_combine() +$iterator = 1; +foreach($keys_passed as $keys) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($keys,$values) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing non-array values to $keys argument *** +-- Iteration 1 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_combine() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_combine() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_variation2.phpt b/ext/standard/tests/array/array_combine_variation2.phpt new file mode 100644 index 000000000..e58893bae --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation2.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test array_combine() function : usage variations - unexpected values for 'values' argument +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_combine() function by passing values to $values argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $keys argument passed is a fixed array. +*/ + +echo "*** Testing array_combine() : Passing non-array values to \$values argument ***\n"; + +// Initialize $keys array +$keys = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $values argument +$values_passed = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element within $values_passed to check the behavior of array_combine() +$iterator = 1; +foreach($values_passed as $values) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($keys,$values) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing non-array values to $values argument *** +-- Iteration 1 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_combine() expects parameter 2 to be array, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_combine() expects parameter 2 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_variation3.phpt b/ext/standard/tests/array/array_combine_variation3.phpt new file mode 100644 index 000000000..51d8462d5 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation3.phpt @@ -0,0 +1,279 @@ +--TEST-- +Test array_combine() function : usage variations - different arrays(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to both $keys and $values arguments and testing whether +* array_combine() behaves in an expected way with the arguments passed to the function +*/ + +echo "*** Testing array_combine() : Passing different types of arrays to both \$keys and \$values argument ***\n"; +/* Different heredoc strings passed as argument to arrays */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $keys argument +$arrays = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrays to check the behavior of array_combine() +// same arrays are passed to both $keys and $values +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing different types of arrays to both $keys and $values argument *** +-- Iteration 1 -- +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +-- Iteration 2 -- +array(2) { + ["1.1"]=> + float(1.1) + ["2.2"]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- Iteration 5 -- +array(1) { + [""]=> + NULL +} +-- Iteration 6 -- +array(6) { + ["a"]=> + string(3) "a" + ["aaaa
"]=> + string(5) "aaaa
" + ["b"]=> + string(1) "b" + ["b bbb"]=> + string(5) "b bbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#$\%\^\&\*\(\)\{\}"]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + ["a\v\f"]=> + string(5) "a\v\f" + ["aaaa\r"]=> + string(6) "aaaa\r" + ["b"]=> + string(1) "b" + ["b\tbbb"]=> + string(6) "b\tbbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#\$\%\^\&\*\(\)\{\}"]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(4) { + [" +"]=> + string(1) " +" + ["hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + ["11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +"]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + string(3) "one" + ["two"]=> + string(3) "two" + ["three"]=> + string(5) "three" +} +-- Iteration 10 -- +array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +-- Iteration 11 -- +array(4) { + [10]=> + int(10) + [20]=> + int(20) + [40]=> + int(40) + [30]=> + int(30) +} +-- Iteration 12 -- +array(3) { + ["ten"]=> + string(3) "ten" + ["twenty"]=> + string(6) "twenty" + ["thirty"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(3) { + [1]=> + int(1) + ["two"]=> + string(3) "two" + ["four"]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + ["null"]=> + string(4) "null" + [""]=> + NULL +} +-- Iteration 15 -- +array(4) { + ["true"]=> + string(4) "true" + ["false"]=> + string(5) "false" + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + ["emptys"]=> + string(6) "emptys" + [""]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) +} +-- Iteration 19 -- +array(3) { + [10]=> + int(10) + [20]=> + int(20) + [3]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_combine_variation4.phpt b/ext/standard/tests/array/array_combine_variation4.phpt new file mode 100644 index 000000000..02ec6efd2 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation4.phpt @@ -0,0 +1,192 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different keys(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_combine() by passing different + * associative arrays having different possible keys to $keys argument and + * associative arrays having different possible keys to $values argument. +*/ + +echo "*** Testing array_combine() : assoc array with diff keys to both \$keys and \$values argument ***\n"; +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable +/*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed keys +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr2 argument +$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, new classA() => 11, 133 => "int"); + +// loop through each sub-array within $arrays to check the behavior of array_combine() +// same arrays are passed to both $keys and $values +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff keys to both $keys and $values argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(1) { + ["float"]=> + string(5) "float" +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + string(2) "f1" + ["f2"]=> + string(2) "f2" + ["f3"]=> + string(2) "f3" + ["f4"]=> + string(2) "f4" +} +-- Iteration 7 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 9 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["string"]=> + string(6) "string" +} +-- Iteration 10 -- +array(1) { + ["hello"]=> + string(5) "hello" +} +-- Iteration 11 -- +array(6) { + [1]=> + int(1) + ["2.2"]=> + float(2.2) + ["int"]=> + string(3) "int" + ["float"]=> + string(5) "float" + ["unset"]=> + string(5) "unset" + ["heredoc"]=> + string(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_combine_variation5.phpt b/ext/standard/tests/array/array_combine_variation5.phpt new file mode 100644 index 000000000..c3d1d57aa --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation5.phpt @@ -0,0 +1,186 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different values(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing the functionality of array_combine() by passing various +* associative arrays having different possible values to $keys argument and +* associative arrays having different possible values to $values argument. +*/ + +echo "*** Testing array_combine() : assoc array with diff values to both \$keys and \$values argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ +public function __toString(){ +return "Class A object"; +} +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + + +// loop through each sub-array within $arrays to check the behavior of array_combine() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff values to both $keys and $values argument *** +-- Iteration 1 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["2.3333"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["1.2"]=> + float(1.2) + ["3.33"]=> + float(3.33) + ["4.8999992284"]=> + float(4.8999992284) + ["33333333.333"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(4) { + [" Hello"]=> + string(6) " Hello" + ["col or"]=> + string(6) "col or" + ["world"]=> + string(7) "world" + ["pen +"]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + ["\tHello"]=> + string(7) "\tHello" + ["col\tor"]=> + string(7) "col\tor" + ["\v\fworld"]=> + string(9) "\v\fworld" + ["pen\n"]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["Hello world"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + ["Class A object"]=> + object(classA)#%d (0) { + } + [""]=> + NULL + ["Resource id #%d"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + ["hello"]=> + string(5) "hello" + ["Class A object"]=> + object(classA)#%d (0) { + } + ["fruit"]=> + string(5) "fruit" + ["Resource id #%d"]=> + resource(%d) of type (stream) + [133]=> + int(133) + ["444.432"]=> + float(444.432) + [""]=> + NULL + ["Hello world"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_combine_variation6.phpt b/ext/standard/tests/array/array_combine_variation6.phpt new file mode 100644 index 000000000..94c7b4d66 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_combine() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_combine() by passing array with +* binary values for $keys and $values argument. +*/ + +echo "*** Testing array_combine() : binary safe checking ***\n"; + +// array with binary values +$arr_binary = array(b"hello", b"world"); +$arr_normal = array("hello", "world"); + +// array with binary value for $keys and $values argument +var_dump( array_combine($arr_binary, $arr_binary) ); + +// array with binary value for $values argument +var_dump( array_combine($arr_normal, $arr_binary) ); + +// array with binary value for $keys argument +var_dump( array_combine($arr_binary, $arr_normal) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : binary safe checking *** +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_basic.phpt b/ext/standard/tests/array/array_diff_assoc_basic.phpt new file mode 100644 index 000000000..c6b3aef00 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_basic.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_diff_assoc() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_diff_assoc + */ + +echo "*** Testing array_diff_assoc() : basic functionality ***\n"; +$array_default_key = array('one', 2, 'three', '4'); +$array_numeric_key = array(1 => 'one', 2=> 'two', 3 => 4); +$array_string_key = array('one' => 1, 'two' => '2', '3' => 'three'); + + + +echo "-- Compare Default keys to numeric keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare Default keys to string keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare numeric keys to string keys --\n"; +var_dump(array_diff_assoc($array_numeric_key, $array_string_key)); +var_dump(array_diff_assoc($array_string_key, $array_numeric_key)); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : basic functionality *** +-- Compare Default keys to numeric keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare Default keys to string keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare numeric keys to string keys -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(4) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_error.phpt b/ext/standard/tests/array/array_diff_assoc_error.phpt new file mode 100644 index 000000000..0c9da2f2c --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_diff_assoc() function : error conditions - pass array_diff_assoc() too few/zero arguments +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test errors for array_diff with too few\zero arguments + */ + +echo "*** Testing array_diff_assoc() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_diff() function with zero arguments --\n"; +var_dump( array_diff_assoc() ); + +// Testing array_diff_assoc with one less than the expected number of arguments +echo "\n-- Testing array_diff_assoc() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_diff_assoc($arr1) ); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : error conditions *** + +-- Testing array_diff() function with zero arguments -- + +Warning: Wrong parameter count for array_diff_assoc() in %s on line %d +NULL + +-- Testing array_diff_assoc() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_diff_assoc() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation1.phpt b/ext/standard/tests/array/array_diff_assoc_variation1.phpt new file mode 100644 index 000000000..b6c63794b --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation1.phpt @@ -0,0 +1,234 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Pass array_diff_assoc arguments that are not arrays in place of $arr1 + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//array of unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp, +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation10.phpt b/ext/standard/tests/array/array_diff_assoc_variation10.phpt new file mode 100644 index 000000000..0687ed8a5 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation10.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - binary safe check +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares binary data + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array1 = array( b"1", + b"hello", + "world", + "str1" => "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** +array(3) { + [0]=> + string(1) "1" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +array(2) { + [3]=> + string(5) "hello" + [4]=> + string(4) "test" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation2.phpt b/ext/standard/tests/array/array_diff_assoc_variation2.phpt new file mode 100644 index 000000000..5de94424e --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation2.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * pass array_diff_assoc arguments which are not arrays in place of $arr2 + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//array of unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp, +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($array, $input)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation3.phpt b/ext/standard/tests/array/array_diff_assoc_variation3.phpt new file mode 100644 index 000000000..1d4aaf2e4 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation3.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test array_diff_assoc() function : variation - array containing different data types +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares indexed arrays containing different data types + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of different data types to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ +'int' => array( + 0, + 1, + 12345, + -2345), + + // float data +/*2*/ +'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + + // null data +/*3*/ +'null' => array( + NULL, + null), + + // boolean data +/*4*/ +'bool' => array( + true, + false, + TRUE, + FALSE), + + // empty data +/*5*/ +'empty' => array( + "", + ''), + + // string data +/*6*/ +'string' => array( + "string", + 'string', + $heredoc), + + // binary data +/*7*/ +'binary' => array( + b"binary", + (binary)"binary"), + + // object data +/*8*/ +'object' => array( + new classA()), + + // undefined data +/*9*/ +'undefined' => array( + @$undefined_var), + + // unset data +/*10*/ +'unset' => array( + @$unset_var), +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2 -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4 -- +array(3) { + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6 -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + +-- Iteration 8 -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +array(1) { + [0]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation4.phpt b/ext/standard/tests/array/array_diff_assoc_variation4.phpt new file mode 100644 index 000000000..34e979ab2 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation4.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays with different data types as keys +--FILE-- + +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares arrays containing different data types + * as keys + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//Different data types as keys to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ +'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative'), + + // float data +/*2*/ +'float' => array( + 10.5 => 'float 1', + -10.5 => 'float 2', + .5 => 'float 3'), + + // null data +/*3*/ +'null' => array( + NULL => 'null 1', + null => 'null 2'), + + // boolean data +/*4*/ +'bool' => array( + true => 'boolt', + false => 'boolf', + TRUE => 'boolT', + FALSE => 'boolF'), + + // empty data +/*5*/ +'empty' => array( + "" => 'emptyd', + '' => 'emptys'), + + // string data +/*6*/ +'string' => array( + "string" => 'stringd', + 'string' => 'strings', + $heredoc => 'stringh'), + + // binary data +/*7*/ +'binary' => array( + b"binary1" => 'binary 1', + (binary)"binary2" => 'binary 2'), + + // undefined data +/*8*/ +'undefined' => array( + @$undefined_var => 'undefined'), + + // unset data +/*9*/ +'unset' => array( + @$unset_var => 'unset'), + +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 -- +array(3) { + [10]=> + string(7) "float 1" + [-10]=> + string(7) "float 2" + [0]=> + string(7) "float 3" +} + +-- Iteration 3 -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 4 -- +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} + +-- Iteration 5 -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 6 -- +array(2) { + ["string"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 7 -- +array(2) { + ["binary1"]=> + string(8) "binary 1" + ["binary2"]=> + string(8) "binary 2" +} + +-- Iteration 8 -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 9 -- +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation5.phpt b/ext/standard/tests/array/array_diff_assoc_variation5.phpt new file mode 100644 index 000000000..c89c65642 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation5.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare integers, floats and strings +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc compares integers, floats and string + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; +$arr_default_int = array(1, 2, 3, 'a'); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00, 'b'); +$arr_string = array('1', '2', '3', 'c'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00', '2.00' => '3.00', 'd'); + +echo "-- Result of comparing integers and floating point numbers: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float)); +var_dump(array_diff_assoc($arr_float, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing an integers : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_default_int)); + +echo "-- Result of comparing floating points and strings containing integers : --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_float)); + +echo "-- Result of comparing floating points and strings containing floating point: --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_float)); + +echo "-- Result of comparing strings containing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_string, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_string)); + +echo "-- Result of comparing more than two arrays: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float, $arr_string, $arr_string_float)); + +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** +-- Result of comparing integers and floating point numbers: -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "b" +} +-- Result of comparing integers and strings containing an integers : -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing integers and strings containing floating points : -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(1) "a" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing floating points and strings containing integers : -- +array(1) { + [3]=> + string(1) "b" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing floating points and strings containing floating point: -- +array(4) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) + [3]=> + string(1) "b" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing strings containing integers and strings containing floating points : -- +array(4) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "c" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing more than two arrays: -- +array(1) { + [3]=> + string(1) "a" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation6.phpt b/ext/standard/tests/array/array_diff_assoc_variation6.phpt new file mode 100644 index 000000000..d6190b658 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation6.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - strict string comparison check +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc behaves + * 1. When comparing an array that has similar elements + * but has been created in a different order + * 2. When doing a strict comparison of string representation + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array ('zero', + 1 => 1, + 'two' => 2.00000000000001); + +$inputs = array ( + +//default keys => string values +/*1*/ array('2.00000000000001', '1', 'zero', 'a'), + +//numeric keys => string values +/*2*/ array(2 => '2.00000000000001', + 1 => '1', + 0 => 'zero', + 3 => 'a'), + +//string keys => string values +/*3*/ array('2' => '2.00000000000001', + '1' => '1', + '0' => 'zero', + '3' => 'a') , + +//default keys => numeric values +/*4*/ array(2, 1, 0), + +//numeric keys => numeric values +/*5*/ array(2 => 2, + 1 => 1, + 0 => 0), + +//string keys => numeric values +/*6*/ array('two' => 2, + '1' => 1, + '0' => 0), + +//defualt keys => float values +/*7*/ array(2.00000000000001, 1.00, 0.01E-9), + +//numeric keys => float values +/*8*/ array(2 => 2.00000000000001, + 1 => 1.00, + 0 => 0.01E-9), + +//string keys => float values +/*9*/ array ('two' => 2.00000000000001, + '1' => 1.00, + '0' =>0.01E-9) +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(array_diff_assoc($array, $input)); + var_dump(array_diff_assoc($input, $array)); + $iterator++; +}; +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(3) { + [0]=> + string(16) "2.00000000000001" + [2]=> + string(4) "zero" + [3]=> + string(1) "a" +} + +-- Iteration 2 -- +array(1) { + ["two"]=> + float(2) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 3 -- +array(1) { + ["two"]=> + float(2) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 4 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [0]=> + int(2) + [2]=> + int(0) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [2]=> + int(2) + [0]=> + int(0) +} + +-- Iteration 6 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + int(0) +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [0]=> + float(2) + [2]=> + float(1.0E-11) +} + +-- Iteration 8 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [2]=> + float(2) + [0]=> + float(1.0E-11) +} + +-- Iteration 9 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + float(1.0E-11) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation7.phpt b/ext/standard/tests/array/array_diff_assoc_variation7.phpt new file mode 100644 index 000000000..6fab0aebf --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation7.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays containing referenced variables +--FILE-- + +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Tests how array_diff_assoc compares + * 1. Referenced variables + * 2. Arrays that have been referenced to each other + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$a = 'a'; + +$arr1 = array('a', 'b', 'c', $a); +$arr2 = array('a' => 1, 'b' => 2, 'c' => 3, &$a); + +echo "-- Results when \$a = $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$a = 4; + +echo "-- Results when \$a has been changed to $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr2 = &$arr1; + +echo "-- Results when \$arr2 is referenced to \$arr1 --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z'); + +echo "-- Results when \$arr1 is changed --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** +-- Results when $a = a: -- +array(3) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +-- Results when $a has been changed to 4: -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(4) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + &int(4) +} +-- Results when $arr2 is referenced to $arr1 -- +array(0) { +} +array(0) { +} +-- Results when $arr1 is changed -- +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation8.phpt b/ext/standard/tests/array/array_diff_assoc_variation8.phpt new file mode 100644 index 000000000..3189c11f2 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation8.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - array containing duplicate keys and values +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() behaves when comparing: + * 1. the order of the array + * 2. duplicate values + * 3. duplicate key names + */ + +echo "*** Testing array_diff_assoc() : variation ***\n"; + +$array_index = array('a', 'b', 'c', 0 => 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff_assoc($array_index, $array_assoc)); +var_dump(array_diff_assoc($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : variation *** +array(2) { + [0]=> + string(1) "d" + [3]=> + string(1) "b" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation9.phpt b/ext/standard/tests/array/array_diff_assoc_variation9.phpt new file mode 100644 index 000000000..5ab623265 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation9.phpt @@ -0,0 +1,141 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc behaves when comparing + * multi-dimensional arrays + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array1 = array('sub_array1' => array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff_assoc($array2['sub_arraya'], $array1['sub_array1'])); +var_dump(array_diff_assoc($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff_assoc($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2)); +var_dump(array_diff_assoc($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** +-- Compare two 2-D arrays -- +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +array(2) { + ["sub_arraya"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(3) + [2]=> + int(5) + } + ["sub_arrayb"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" + } +} + +-- Compare subarrays from two 2-D arrays -- +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [1]=> + int(3) + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_basic.phpt b/ext/standard/tests/array/array_diff_basic.phpt new file mode 100644 index 000000000..30aead657 --- /dev/null +++ b/ext/standard/tests/array/array_diff_basic.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test array_diff() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not present + * in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_diff + */ + +echo "*** Testing array_diff() : basic functionality ***\n"; + +//Test indexed array with integers as elements +$array_int1 = array (1, 2, 3, 4); +$array_int2 = array (3, 4, 5, 6); + +echo "-- Test indexed array with integers as elements --\n"; +var_dump(array_diff($array_int1, $array_int2)); +var_dump(array_diff($array_int2, $array_int1)); + + +//Test indexed array with strings as elements +$array_string1 = array ('one', 'two', 'three', 'four'); +$array_string2 = array ('three', 'four', 'five', 'six'); + +echo "-- Test indexed array with strings as elements --\n"; +var_dump(array_diff($array_string1, $array_string2)); +var_dump(array_diff($array_string2, $array_string1)); + +//Test associative array with strings as keys and integers as elements +$array_assoc_int1 = array ('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4); +$array_assoc_int2 = array ('three' => 3, 'four' => 4, 'five' => 5, 'six' => 6); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_int1, $array_assoc_int2)); +var_dump(array_diff($array_assoc_int2, $array_assoc_int1)); + +//Test associative array with strings as keys and elements +$array_assoc_str1 = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois', 'four' => 'quatre'); +$array_assoc_str2 = array ('three' => 'trois', 'four' => 'quatre', 'five' => 'cinq', 'six' => 'six'); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_str1, $array_assoc_str2)); +var_dump(array_diff($array_assoc_str2, $array_assoc_str1)); + +echo "-- Test array_diff with more than 2 arguments --\n"; +var_dump(array_diff($array_int1, $array_int2, $array_string1, $array_string2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : basic functionality *** +-- Test indexed array with integers as elements -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [2]=> + int(5) + [3]=> + int(6) +} +-- Test indexed array with strings as elements -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [2]=> + string(4) "five" + [3]=> + string(3) "six" +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["five"]=> + int(5) + ["six"]=> + int(6) +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +array(2) { + ["five"]=> + string(4) "cinq" + ["six"]=> + string(3) "six" +} +-- Test array_diff with more than 2 arguments -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_diff_error.phpt b/ext/standard/tests/array/array_diff_error.phpt new file mode 100644 index 000000000..2e4e86f08 --- /dev/null +++ b/ext/standard/tests/array/array_diff_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff() function : error conditions - too few arguments passed to function +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff with less than the expected number of arguments + */ + +echo "*** Testing array_diff() : error conditions ***\n"; +// Zero arguments +echo "\n-- Testing array_diff() function with zero arguments --\n"; +var_dump( array_diff() ); + + +// Testing array_diff with one less than the expected number of arguments +echo "\n-- Testing array_diff() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_diff($arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : error conditions *** + +-- Testing array_diff() function with zero arguments -- + +Warning: Wrong parameter count for array_diff() in %s on line %d +NULL + +-- Testing array_diff() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_diff() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_basic.phpt b/ext/standard/tests/array/array_diff_key_basic.phpt new file mode 100644 index 000000000..6f6fcb9a4 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test array_diff_key() : basic functionality +--FILE-- +<?php +/* +* proto array array_diff_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation1.phpt b/ext/standard/tests/array/array_diff_key_variation1.phpt new file mode 100644 index 000000000..00da7afa9 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation1.phpt @@ -0,0 +1,89 @@ +--TEST-- +array_diff_key() : type variations +--FILE-- +<?php +/* +* proto array array_diff_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +/* +* Testing how array_diff_key treats keys that are numbers, floating point numbers or strings. +*/ +$arr1 = array(1 => 'a', 2 => 'b', 3 => 'c', 'key1' => 'value'); +$arr2 = array(1.00 => 'a', 2.00 => 'b', 3.00 => 'c', 'key2' => 'value'); +$arr3 = array('1' => 'a', '2' => 'b', '3' => 'c', 'key3' => 'value'); +$arr4 = array('1.00' => 'a', '2.00' => 'b', '3.00' => 'c', 'key4' => 'value'); //$arr4 looks different to the other three arrays. +print "Result of comparing integers and floating point value:\n"; //1 and 1.00 are treated as the same thing +print_r(array_diff_key($arr1, $arr2)); +print_r(array_diff_key($arr2, $arr1)); +print "Result of comparing integers and strings containing an integers:\n"; //1 and the string 1 are treated as the same thing +print_r(array_diff_key($arr1, $arr3)); +print_r(array_diff_key($arr3, $arr1)); +print "Result of comparing integers and strings containing floating points:\n"; //1 and the string 1.00 are not treated as the same thing +print_r(array_diff_key($arr1, $arr4)); +print_r(array_diff_key($arr4, $arr1)); +print "Result of comparing floating points and strings containing integers:\n"; +print_r(array_diff_key($arr2, $arr3)); //1.00 and the string 1 are treated as the same thing +print_r(array_diff_key($arr3, $arr2)); +print "Result of comparing strings containing integers and strings containing floating points:\n"; //the strings 1 and 1.00 are not treated as the same thing. +print_r(array_diff_key($arr3, $arr4)); +print_r(array_diff_key($arr4, $arr3)); +?> +--EXPECTF-- +Result of comparing integers and floating point value: +Array +( + [key1] => value +) +Array +( + [key2] => value +) +Result of comparing integers and strings containing an integers: +Array +( + [key1] => value +) +Array +( + [key3] => value +) +Result of comparing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key1] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) +Result of comparing floating points and strings containing integers: +Array +( + [key2] => value +) +Array +( + [key3] => value +) +Result of comparing strings containing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key3] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) diff --git a/ext/standard/tests/array/array_diff_uassoc_basic.phpt b/ext/standard/tests/array/array_diff_uassoc_basic.phpt new file mode 100644 index 000000000..6a96be6b7 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +array_diff_uassoc(): Basic test +--FILE-- +<?php +/* +* array array_diff_uassoc ( array $array1, array $array2 [, array $..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(3) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + [0]=> + string(3) "red" +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_ukey_basic.phpt b/ext/standard/tests/array/array_diff_ukey_basic.phpt new file mode 100644 index 000000000..7ac309a01 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_diff_ukey() : Basic test. +--FILE-- +<?php +/* +* proto array array_diff_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($key1, $key2) { + if ($key1 == $key2) return 0; + else if ($key1 > $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} diff --git a/ext/standard/tests/array/array_diff_variation1.phpt b/ext/standard/tests/array/array_diff_variation1.phpt new file mode 100644 index 000000000..f9a34b0a5 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation1.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff by passing non array values in place of $arr1 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_diff +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_diff($input, $array)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 26 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation10.phpt b/ext/standard/tests/array/array_diff_variation10.phpt new file mode 100644 index 000000000..9442b946d --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation10.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_diff() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test behaviour of array_diff() function with binary input + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + + +$array1 = array( b"1", + b"hello", + "world", + "str1" => "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "1" +} +array(1) { + [4]=> + string(4) "test" +} +Done diff --git a/ext/standard/tests/array/array_diff_variation2.phpt b/ext/standard/tests/array/array_diff_variation2.phpt new file mode 100644 index 000000000..be68c40c2 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation2.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff by passing non array values in place of $arr2 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_diff +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_diff($array, $input)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 26 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation3.phpt b/ext/standard/tests/array/array_diff_variation3.phpt new file mode 100644 index 000000000..84f73fd28 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation3.phpt @@ -0,0 +1,190 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares indexed arrays containing different + * data types as values in place of $arr1 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$array = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get heredoc +$heredoc = <<<END +This is a heredoc +END; + +//array of values to iterate over +$values = array( + +/*1*/"empty array" => array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for arr1 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($value, $array) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(0) { +} + + Iteration: 2 +array(3) { + [0]=> + int(0) + [2]=> + int(12345) + [3]=> + int(-2345) +} + + Iteration: 3 +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + + Iteration: 4 +array(2) { + [0]=> + NULL + [1]=> + NULL +} + + Iteration: 5 +array(2) { + [1]=> + bool(false) + [3]=> + bool(false) +} + + Iteration: 6 +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + + Iteration: 7 +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(17) "This is a heredoc" +} + + Iteration: 8 +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + + Iteration: 9 +array(1) { + [0]=> + NULL +} + + Iteration: 10 +array(1) { + [0]=> + NULL +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation4.phpt b/ext/standard/tests/array/array_diff_variation4.phpt new file mode 100644 index 000000000..75b01adaa --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation4.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares indexed arrays containing different + * data types as values in place of $arr2 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$array = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get heredoc +$heredoc = <<<END +This is a heredoc +END; + +//array of values to iterate over +$values = array( + +/*1*/"empty array" => array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for $arr2 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($array, $value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 2 +array(1) { + [1]=> + int(2) +} + + Iteration: 3 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 4 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 5 +array(1) { + [1]=> + int(2) +} + + Iteration: 6 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 7 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 8 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 9 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 10 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation5.phpt b/ext/standard/tests/array/array_diff_variation5.phpt new file mode 100644 index 000000000..cb6b5d3da --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation5.phpt @@ -0,0 +1,119 @@ +--TEST-- +Test array_diff() function : usage variations - comparing integers, float +and string array values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff compares integers, floats and strings + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$arr_int = array(1, 2, 3); +$arr_float = array(1.00, 2.00, 3.00); +$arr_int_str = array('1', '2', '3'); +$arr_float_str = array('1.00', '2.00', '3.00'); + +print "-- Compare integers and floats: --\n"; +var_dump(array_diff($arr_int, $arr_float)); +var_dump(array_diff($arr_float, $arr_int)); + + +print "-- Compare integers and strings containing an integers: --\n"; +var_dump(array_diff($arr_int, $arr_int_str)); +var_dump(array_diff($arr_int_str, $arr_int)); + +print "-- Compare integers and strings containing floats: --\n"; +var_dump(array_diff($arr_int, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_int)); + +print "-- Compare floats and strings containing integers: --\n"; + +var_dump(array_diff($arr_float, $arr_int_str)); +var_dump(array_diff($arr_int_str, $arr_float)); + +print "-- Compare floats and strings containing floats: --\n"; +var_dump(array_diff($arr_float, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_float)); + +print "-- Compare strings containing integers and strings containing floats: --\n"; +var_dump(array_diff($arr_int_str, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_int_str)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Compare integers and floats: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing an integers: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing floats: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare floats and strings containing integers: -- +array(0) { +} +array(0) { +} +-- Compare floats and strings containing floats: -- +array(3) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare strings containing integers and strings containing floats: -- +array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation6.phpt b/ext/standard/tests/array/array_diff_variation6.phpt new file mode 100644 index 000000000..8ea84bb9d --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation6.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_diff() function : usage variations - array containing duplicate keys and values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test that array_diff behaves as expected for comparing: + * 1. the order of the array + * 2. duplicate values + * 3. duplicate key names + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array_index = array('a', 'b', 'c', 0 => 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff($array_index, $array_assoc)); +var_dump(array_diff($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "d" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation7.phpt b/ext/standard/tests/array/array_diff_variation7.phpt new file mode 100644 index 000000000..c53cbb3d1 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation7.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test array_diff() function : usage variations - arrays containing referenced variables +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff compares arrays that + * 1. Contain referenced variables + * 2. Have been referenced to each other + */ + +echo "*** Testing array_diff() : usage variations ***\n"; +$a = 'a'; + +$arr1 = array ("&$a", 'b', 'c'); +$arr2 = array (1, 2, 3); +echo "-- Basic Comparison --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + +$a = 1; + +echo "-- \$a changed --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +$arr2 = &$arr1; +echo "-- Arrays referenced to each other --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +$arr1 = array('x', 'y', 'z'); +echo "-- \$arr1 changed --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff() : usage variations *** +-- Basic Comparison -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- $a changed -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- Arrays referenced to each other -- +array(0) { +} +array(0) { +} +-- $arr1 changed -- +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation8.phpt b/ext/standard/tests/array/array_diff_variation8.phpt new file mode 100644 index 000000000..99f9614d7 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation8.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_diff() function : usage variations - associative arrays contianing different data types +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff() with associative arrays containing different data types as values + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array('a' => '1', 'b' => '2', 'c' => '3'); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// associative arrays with different values +$inputs = array ( + // arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + + // arrays with string values +/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_diff($array, $input) ); + var_dump( array_diff($input, $array) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Iteration 1 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- Iteration 2 -- +array(1) { + ["c"]=> + string(1) "3" +} +array(0) { +} +-- Iteration 3 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + ["float1"]=> + float(2.3333) + ["float2"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(1.2) +} +-- Iteration 5 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" + [3]=> + string(6) " Hello" +} +-- Iteration 6 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(7) "\tHello" +} +-- Iteration 7 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(3) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" + [2]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(5) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [12]=> + object(classA)#%d (0) { + } + [13]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_diff_variation9.phpt b/ext/standard/tests/array/array_diff_variation9.phpt new file mode 100644 index 000000000..58d9c201b --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation9.phpt @@ -0,0 +1,100 @@ +--TEST-- +Test array_diff() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares multidimensional arrays + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array1 = array('sub_array1' => array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1'])); + +var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff($array1['sub_array1'], $array2)); +var_dump(array_diff($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Compare two 2-D arrays -- +array(0) { +} +array(0) { +} + +-- Compare subarrays from two 2-D arrays -- +array(1) { + [1]=> + int(2) +} +array(1) { + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_key_basic.phpt b/ext/standard/tests/array/array_intersect_key_basic.phpt new file mode 100644 index 000000000..fc6e177f5 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +array_intersect_key(): Basic Test +--FILE-- +<?php +/* +* proto array array_intersect_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_uassoc_basic.phpt b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt new file mode 100644 index 000000000..1a2d57ec3 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_uassoc(): Basic test +--FILE-- +<?php +/* +* array array_intersect_uassoc ( array $array1, array $array2 [, array $..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_intersect_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(1) { + ["a"]=> + string(5) "green" +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_basic.phpt b/ext/standard/tests/array/array_intersect_ukey_basic.phpt new file mode 100644 index 000000000..db21b9b01 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_ukey(): Basic test. +--FILE-- +<?php +/* +* proto array array_intersect_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($key1, $key2) { + if ($key1 == $key2) return 0; + else if ($key1 > $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/ext/standard/tests/array/array_key_exists_basic.phpt b/ext/standard/tests/array/array_key_exists_basic.phpt new file mode 100644 index 000000000..6fbd415dc --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_key_exists() function : basic functionality +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test basic functionality of array_key_exists() + */ + +echo "*** Testing array_key_exists() : basic functionality ***\n"; + +$key1 = 'key'; +$key2 = 'val'; +$search = array('one', 'key' => 'value', 'val'); +var_dump(array_key_exists($key1, $search)); +var_dump(array_key_exists($key2, $search)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_key_exists() : basic functionality *** +bool(true) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_error.phpt b/ext/standard/tests/array/array_key_exists_error.phpt new file mode 100644 index 000000000..f87d2199e --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_key_exists() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass incorrect number of arguments to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : error conditions ***\n"; + +//Test array_key_exists with one more than the expected number of arguments +echo "\n-- Testing array_key_exists() function with more than expected no. of arguments --\n"; +$key = 1; +$search = array(1, 2); +$extra_arg = 10; +var_dump( array_key_exists($key, $search, $extra_arg) ); + +// Testing array_key_exists with one less than the expected number of arguments +echo "\n-- Testing array_key_exists() function with less than expected no. of arguments --\n"; +$key = 1; +var_dump( array_key_exists($key) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : error conditions *** + +-- Testing array_key_exists() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_key_exists() in %s on line %d +NULL + +-- Testing array_key_exists() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_key_exists() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_object1.phpt b/ext/standard/tests/array/array_key_exists_object1.phpt new file mode 100644 index 000000000..6c85f5389 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_object1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_key_exists() function : object functionality +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test basic functionality of array_key_exists() with objects + */ + +echo "*** Testing array_key_exists() : object functionality ***\n"; + +class myClass { + var $var1; + var $var2; + var $var3; + + function __construct($a, $b, $c = null) { + $this->var1 = $a; + $this->var2 = $b; + if (!is_null($c)) { + $this->var3 = $c; + } + } +} + +echo "\n-- Do not assign a value to \$class1->var3 --\n"; +$class1 = new myClass ('a', 'b'); +echo "\$key = var1:\n"; +var_dump(array_key_exists('var1', $class1)); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class1)); +echo "\$class1:\n"; +var_dump($class1); + +echo "\n-- Assign a value to \$class2->var3 --\n"; +$class2 = new myClass('x', 'y', 'z'); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class2)); +echo "\$class2:\n"; +var_dump($class2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : object functionality *** + +-- Do not assign a value to $class1->var3 -- +$key = var1: +bool(true) +$key = var3: +bool(true) +$class1: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "a" + ["var2"]=> + string(1) "b" + ["var3"]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(true) +$class2: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "x" + ["var2"]=> + string(1) "y" + ["var3"]=> + string(1) "z" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_object2.phpt b/ext/standard/tests/array/array_key_exists_object2.phpt new file mode 100644 index 000000000..07c93b2f8 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_object2.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test array_key_exists() function : object functionality - different visibilities +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass array_key_exists() an object with private and protected properties + */ + +echo "*** Testing array_key_exists() : object functionality ***\n"; + +class myClass { + public $var1; + protected $var2; + private $var3; + + function __construct($a, $b, $c = null) { + $this->var1 = $a; + $this->var2 = $b; + if (!is_null($c)) { + $this->var3 = $c; + } + } +} + +echo "\n-- Do not assign a value to \$class1->var3 --\n"; +$class1 = new myClass ('a', 'b'); +echo "\$key = var1:\n"; +var_dump(array_key_exists('var1', $class1)); +echo "\$key = var2:\n"; +var_dump(array_key_exists('var2', $class1)); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class1)); +echo "\$class1:\n"; +var_dump($class1); + +echo "\n-- Assign a value to \$class2->var3 --\n"; +$class2 = new myClass('x', 'y', 'z'); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class2)); +echo "\$class2:\n"; +var_dump($class2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : object functionality *** + +-- Do not assign a value to $class1->var3 -- +$key = var1: +bool(true) +$key = var2: +bool(false) +$key = var3: +bool(false) +$class1: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "a" + ["var2:protected"]=> + string(1) "b" + ["var3:private"]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(false) +$class2: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "x" + ["var2:protected"]=> + string(1) "y" + ["var3:private"]=> + string(1) "z" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt new file mode 100644 index 000000000..2f50d3e86 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -0,0 +1,203 @@ +--TEST-- +Test array_key_exists() function : usage variations - Pass different data types as $key arg +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass different data types as $key argument to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$search = array ('zero', 'key' => 'val', 'two'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "key"; + } +} + +// heredoc string +$heredoc = <<<EOT +key +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $key argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "key", + 'key', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_key_exists($input, $search) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +bool(true) + +-- Iteration 2 -- +bool(true) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 19 -- +bool(true) + +-- Iteration 20 -- +bool(true) + +-- Iteration 21 -- +bool(true) + +-- Iteration 22 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- +bool(false) + +-- Iteration 25 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation2.phpt b/ext/standard/tests/array/array_key_exists_variation2.phpt new file mode 100644 index 000000000..0804006f6 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation2.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test array_key_exists() function : usage variations - Pass differnt data types to $search arg +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass different data types as $search argument to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$key = 'val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $search argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_key_exists($key, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation3.phpt b/ext/standard/tests/array/array_key_exists_variation3.phpt new file mode 100644 index 000000000..e8a52a705 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation3.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_key_exists() function : usage variations - floats and casting to ints +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass floats as $key argument, then cast float values + * to integers and pass as $key argument + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$keys = array(1.2345678900E-10, 1.00000000000001, 1.99999999999999); + +$search = array ('zero', 'one', 'two'); + +$iterator = 1; +foreach($keys as $key) { + echo "\n-- Iteration $iterator --\n"; + echo "Pass float as \$key:\n"; + var_dump(array_key_exists($key, $search)); + echo "Cast float to int:\n"; + var_dump(array_key_exists((int)$key, $search)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation4.phpt b/ext/standard/tests/array/array_key_exists_variation4.phpt new file mode 100644 index 000000000..edc39269a --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation4.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_key_exists() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass referenced variables as arguments to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$array = array('one' => 1, 'two' => 2, 'three' => 3); + +echo "\n-- \$search is a reference to \$array --\n"; +$search = &$array; +var_dump(array_key_exists('one', $search)); + +echo "\n-- \$key is a referenced variable --\n"; +$key = 'two'; +var_dump(array_key_exists(&$key, $array)); + +echo "\n-- Both arguments are referenced variables --\n"; +var_dump(array_key_exists(&$key, &$array)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- $search is a reference to $array -- +bool(true) + +-- $key is a referenced variable -- +bool(true) + +-- Both arguments are referenced variables -- +bool(true) +Done diff --git a/ext/standard/tests/array/array_key_exists_variation5.phpt b/ext/standard/tests/array/array_key_exists_variation5.phpt new file mode 100644 index 000000000..9c15759fc --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation5.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_key_exists() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test how array_key_exists() behaves with multi-dimensional arrays + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$multi_array = array ('zero' => 'val1', + 'one' => 'val2', + 'sub1' => array (1, 2, 3)); + +echo "\n-- Attempt to match key in sub-array --\n"; +// this key is in the sub-array +var_dump(array_key_exists(0, $multi_array)); + +echo "\n-- \$search arg points to sub-array --\n"; +var_dump(array_key_exists(0, $multi_array['sub1'])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Attempt to match key in sub-array -- +bool(false) + +-- $search arg points to sub-array -- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation6.phpt b/ext/standard/tests/array/array_key_exists_variation6.phpt new file mode 100644 index 000000000..d19e58e76 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation6.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test array_key_exists() function : usage variations - equality test for certain data types +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass certain data types that can be taken as a key in an array + * and test whether array_key_exists(() thinks they are equal and therefore + * returns true when searching for them + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$unset = 10; +unset($unset); +$array = array ('null' => null, + 'NULL' => NULL, + 'empty single quoted string' => '', + "empty double quoted string" => "", + 'undefined variable' => @$undefined, + 'unset variable' => @$unset); + +//iterate through original array +foreach($array as $name => $input) { + $iterator = 1; + echo "\n-- Key in \$search array is : $name --\n"; + $search[$input] = 'test'; + + //iterate through array again to see which values are considered equal + foreach($array as $key) { + echo "Iteration $iterator: "; + var_dump(array_key_exists($key, $search)); + $iterator++; + } + $search = null; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Key in $search array is : null -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : NULL -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty single quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty double quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : undefined variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : unset variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation7.phpt b/ext/standard/tests/array/array_key_exists_variation7.phpt new file mode 100644 index 000000000..845c1e54b --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation7.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_exists() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Check the position of the internal array pointer after calling array_key_exists() + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_key_exists() --\n"; +var_dump($result = array_key_exists('one', $input)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Call array_key_exists() -- +bool(true) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation8.phpt b/ext/standard/tests/array/array_key_exists_variation8.phpt new file mode 100644 index 000000000..d5bad62e2 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation8.phpt @@ -0,0 +1,547 @@ +--TEST-- +Test array_key_exists() function : usage variations - array keys are different data types +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass an array where the keys are different data types as the $search argument + * then pass many different data types as $key argument to test where array_key_exist() + * returns true. + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +string +EOT; + +// different data types to be iterated over +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator: $type data --\n"; + + //iterate over again to get all different key values + foreach ($inputs as $new_type => $new_input) { + echo "-- \$key arguments are $new_type data:\n"; + foreach ($new_input as $key => $search) { + var_dump(array_key_exists($key, $input)); + } + } + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1: int data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(true) +bool(true) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 2: float data -- +-- $key arguments are int data: +bool(true) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(true) +bool(true) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(true) +-- $key arguments are bool uppercase data: +bool(false) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 3: extreme floats data -- +-- $key arguments are int data: +bool(true) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(true) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(true) +-- $key arguments are bool uppercase data: +bool(false) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 4: null uppercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 5: null lowercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 6: bool lowercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 7: bool uppercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 8: empty double quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 9: empty single quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 10: string data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(true) +bool(true) +bool(true) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 11: undefined data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 12: unset data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_map.phpt b/ext/standard/tests/array/array_map.phpt deleted file mode 100644 index 78815e083..000000000 --- a/ext/standard/tests/array/array_map.phpt +++ /dev/null @@ -1,423 +0,0 @@ ---TEST-- -Test array_map() function ---FILE-- -<?php -/* Prototype: array array_map ( callback $callback, array $arr1 [, array $...] ); - Description: array_map() returns an array containing all the elements of arr1 - after applying the callback function to each one. The number of - parameters that the callback function accepts should match the - number of arrays passed to the array_map() -*/ - -echo "*** Testing basic operations ***\n"; -/* array_map with null as function and different arrays */ -var_dump( array_map(NULL, array()) ); -var_dump( array_map(NULL, array(), array()) ); -var_dump( array_map(NULL, array(1,2,3), array(1,2,3)) ); -var_dump( array_map(NULL, array(1,2), array(1,2,3,4)) ); -var_dump( array_map(NULL, array("Jan", "Feb", "March"), array("31","28","31")) ); -var_dump( array_map(NULL, array("Text", "Words", "Lineup"), array(4, 5, 6)) ); -var_dump( array_map(NULL, array("a", "ab", "abc", "abcd"), array()) ); -var_dump( array_map(NULL, - array("Jan"=>"01", "Feb"=>"02", "March"=>"03"), - array("31"=>"Jan", "28"=>"Feb", "031"=>"March") - ) - ); - -/* using key as "string" where no.of arguments passed to array_map() is 2 */ -var_dump( array_map( create_function('$n', 'return $n*$n;'), - array("key1"=>1, "key2"=>2, "key3"=>3) - ) - ); - -echo "\n*** Testing possible variations ***\n"; -/* anonymous callback function */ -var_dump( array_map( create_function('$a,$b', 'return $a+$b;'), - array(1,2,3), - array(5,6,7,8,9) - ) - ); - -/* anonymous callback function with reference */ -var_dump( array_map( create_function('&$a, $b', 'return array($a,$b);'), - array("Hello","Good"), - array("World","Day") - ) - ); - -/* callback function with reference */ -$a = array(1,2,3); -function square(&$var) { - return( $var * $var ); -} -print_r( array_map('square', $a) ); - -/* array_map in recursion */ -function square_recur($var) { - if (is_array($var)) - return array_map('square_recur', $var); - return $var * $var; -} -$rec_array = array(1, 2, array(3, 4, array(5, 2), array() ) ); -var_dump( array_map('square_recur', $rec_array) ); - -/* callback function as string variable containing the function name */ -$string_var = "square"; -var_dump( array_map("square", $a) ); -var_dump( array_map($string_var, $a) ); - -echo "\n*** Testing error conditions ***\n"; -/* arguments of non array type */ -$int_var=10; -$float_var = 10.5; -var_dump( array_map('square', $int_var) ); -var_dump( array_map('square', $float_var) ); -var_dump( array_map('square', $string_var) ); - -/* Zero argument */ -var_dump( array_map() ); - -/* use array(), echo(), empty(), eval(), exit(), isset(), list(), print() - and unset() as callback, failure expected */ -var_dump( array_map( 'echo', array(1) ) ); -var_dump( array_map( 'array', array(1) ) ); -var_dump( array_map( 'empty', array(1) ) ); -var_dump( array_map( 'eval', array(1) ) ); -var_dump( array_map( 'exit', array(1) ) ); -var_dump( array_map( 'isset', array(1) ) ); -var_dump( array_map( 'list', array(1) ) ); -var_dump( array_map( 'print', array(1) ) ); - - -echo "\n*** Testing operation on objects ***\n"; -/* array_map with class object */ -class check_array_map { - public static function helloWorld() { - return "Static_Function_helloWorld(): Hello World"; - } - public function Message($v) { - return $v; - } - - public static function Square( $n ) { - return $n * $n; - } -} -/* call static member function */ -var_dump( array_map( array('check_array_map', 'Square'), array(1,2,3)) ); - -/* call non static member function - notice should be issues*/ -var_dump( array_map( array('check_array_map', 'Message'), array(1)) ); - -/* call function using object */ -$obj = new check_array_map(); -var_dump( array_map( array($obj, 'helloWorld' ) ) ); // not enough args warning -var_dump( array_map( array($obj, 'helloWorld'), array(1) ) ); - -echo "Done\n"; -?> ---EXPECTF-- -*** Testing basic operations *** -array(0) { -} -array(0) { -} -array(3) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(2) - } - [2]=> - array(2) { - [0]=> - int(3) - [1]=> - int(3) - } -} -array(4) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(2) - } - [2]=> - array(2) { - [0]=> - NULL - [1]=> - int(3) - } - [3]=> - array(2) { - [0]=> - NULL - [1]=> - int(4) - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(3) "Jan" - [1]=> - string(2) "31" - } - [1]=> - array(2) { - [0]=> - string(3) "Feb" - [1]=> - string(2) "28" - } - [2]=> - array(2) { - [0]=> - string(5) "March" - [1]=> - string(2) "31" - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(4) "Text" - [1]=> - int(4) - } - [1]=> - array(2) { - [0]=> - string(5) "Words" - [1]=> - int(5) - } - [2]=> - array(2) { - [0]=> - string(6) "Lineup" - [1]=> - int(6) - } -} -array(4) { - [0]=> - array(2) { - [0]=> - string(1) "a" - [1]=> - NULL - } - [1]=> - array(2) { - [0]=> - string(2) "ab" - [1]=> - NULL - } - [2]=> - array(2) { - [0]=> - string(3) "abc" - [1]=> - NULL - } - [3]=> - array(2) { - [0]=> - string(4) "abcd" - [1]=> - NULL - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(2) "01" - [1]=> - string(3) "Jan" - } - [1]=> - array(2) { - [0]=> - string(2) "02" - [1]=> - string(3) "Feb" - } - [2]=> - array(2) { - [0]=> - string(2) "03" - [1]=> - string(5) "March" - } -} -array(3) { - ["key1"]=> - int(1) - ["key2"]=> - int(4) - ["key3"]=> - int(9) -} - -*** Testing possible variations *** -array(5) { - [0]=> - int(6) - [1]=> - int(8) - [2]=> - int(10) - [3]=> - int(8) - [4]=> - int(9) -} -array(2) { - [0]=> - array(2) { - [0]=> - string(5) "Hello" - [1]=> - string(5) "World" - } - [1]=> - array(2) { - [0]=> - string(4) "Good" - [1]=> - string(3) "Day" - } -} -Array -( - [0] => 1 - [1] => 4 - [2] => 9 -) -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - array(4) { - [0]=> - int(9) - [1]=> - int(16) - [2]=> - array(2) { - [0]=> - int(25) - [1]=> - int(4) - } - [3]=> - array(0) { - } - } -} -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} - -*** Testing error conditions *** - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: Wrong parameter count for array_map() %s on line %d -NULL - -Warning: array_map(): The first argument, 'echo', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'array', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'empty', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'eval', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'exit', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'isset', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'list', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'print', should be either NULL or a valid callback in %s on line %d -NULL - -*** Testing operation on objects *** -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} - -Strict Standards: Non-static method check_array_map::Message() cannot be called statically in %s on line %d - -Strict Standards: Non-static method check_array_map::Message() cannot be called statically in %s on line %d -array(1) { - [0]=> - int(1) -} - -Warning: Wrong parameter count for array_map() in %s on line %d -NULL -array(1) { - [0]=> - string(41) "Static_Function_helloWorld(): Hello World" -} -Done diff --git a/ext/standard/tests/array/array_map_basic.phpt b/ext/standard/tests/array/array_map_basic.phpt new file mode 100644 index 000000000..53a7bb4e2 --- /dev/null +++ b/ext/standard/tests/array/array_map_basic.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_map() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_map() : basic functionality ***\n"; + +function multiply($p, $q) { + return ($p * $q); +} + +function square($p) { + return ($p * $p); +} + +function concatenate($a, $b) { + return "$a = $b"; +} + +// integer array +$arr1 = array(1, 2, 3); +$arr2 = array(4, 5, 6); + +echo "-- With two integer array --\n"; +var_dump( array_map('multiply', $arr1, $arr2) ); + +echo "-- With single integer array --\n"; +var_dump( array_map('square', $arr1) ); + +// string array +$arr1 = array("one", "two"); +$arr2 = array("single", "double"); + +echo "-- With string array --\n"; +var_dump( array_map('concatenate', $arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : basic functionality *** +-- With two integer array -- +array(3) { + [0]=> + int(4) + [1]=> + int(10) + [2]=> + int(18) +} +-- With single integer array -- +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} +-- With string array -- +array(2) { + [0]=> + string(12) "one = single" + [1]=> + string(12) "two = double" +} +Done diff --git a/ext/standard/tests/array/array_map_error.phpt b/ext/standard/tests/array/array_map_error.phpt new file mode 100644 index 000000000..a1c93d0fc --- /dev/null +++ b/ext/standard/tests/array/array_map_error.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : error conditions +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_map() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_map() function with Zero arguments --\n"; +var_dump( array_map() ); + +// Testing array_map with one less than the expected number of arguments +echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n"; +function callback1() { + return 1; +} +var_dump( array_map('callback1') ); + +echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n"; +$arr1 = array(1, 2); +function callback2($p, $q) { + return $p * $q; +} +var_dump( array_map('callback2', $arr1) ); + +echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n"; +$arr2 = array(3, 4); +$arr3 = array(5, 6); +var_dump( array_map('callback2', $arr1, $arr2, $arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : error conditions *** + +-- Testing array_map() function with Zero arguments -- + +Warning: Wrong parameter count for array_map() in %s on line %d +NULL + +-- Testing array_map() function with one less than expected no. of arguments -- + +Warning: Wrong parameter count for array_map() in %s on line %d +NULL + +-- Testing array_map() function with less no. of arrays than callback function arguments -- + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: q in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: q in %s on line %d +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} + +-- Testing array_map() function with more no. of arrays than callback function arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(8) +} +Done diff --git a/ext/standard/tests/array/array_map_object1.phpt b/ext/standard/tests/array/array_map_object1.phpt new file mode 100644 index 000000000..1265e3a74 --- /dev/null +++ b/ext/standard/tests/array/array_map_object1.phpt @@ -0,0 +1,200 @@ +--TEST-- +Test array_map() function : usage variations - object functionality +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for object functionalities: + * 1) simple class with variable and method + * 2) class without members + * 3) class with only one method and no variable + * 4) abstract and child class + * 5) class with static and final members + * 6) interface and implemented class + */ +echo "*** Testing array_map() : object functionality ***\n"; + +echo "-- simple class with public variable and method --\n"; +class SimpleClass +{ + public $var1 = 1; + public function square($n) { + return $n * $n; + } +} +var_dump( array_map(array('SimpleClass', 'square'), array(1, 2)) ); + +echo "\n-- simple class with private variable and method --\n"; +class SimpleClassPri +{ + private $var1 = 10; + private function add($n) { + return $var + $n; + } +} +var_dump( array_map(array('SimpleClassPri', 'add'), array(1)) ); + +echo "\n-- simple class with protected variable and method --\n"; +class SimpleClassPro +{ + protected $var1 = 5; + protected function mul($n) { + return $var1 * $n; + } +} +var_dump( array_map(array('SimpleClassPro', 'mul'), array(2)) ); + +echo "\n-- class without members --"; +class EmptyClass +{ +} +var_dump( array_map(array('EmptyClass'), array(1, 2)) ); + +echo "\n-- abstract class --"; +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyFunction(); +} + +// class deriving the above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyFunction() { + echo "defined in child"; + } +} +var_dump( array_map(array('ChildClass', 'emptyFunction'), array(1, 2)) ); + +echo "\n-- class with final method --"; +class FinalClass +{ + private $var4; + final function finalMethod() { + echo "This function can't be overloaded"; + } +} +var_dump( array_map(array('FinalClass', 'finalMethod'), array(1, 2)) ); + +echo "\n-- class with static members --\n"; +class StaticClass +{ + static $var5 = 2; + public static function square($n) { + return ($n * $n); + } + private static function cube($n) { + return ($n * $n * $n); + } + protected static function retVal($n) { + return array($n); + } +} +var_dump( array_map(array('StaticClass', 'square'), array(1, 2)) ); +var_dump( array_map(array('StaticClass', 'cube'), array(2)) ); +var_dump( array_map(array('StaticClass', 'retVal'), array(3, 4)) ); + +echo "-- class implementing an interface --\n"; +interface myInterface +{ + public function toImplement(); +} +class InterClass implements myInterface +{ + public static function square($n) { + return ($n * $n); + } + public function toImplement() { + return 1; + } +} +var_dump( array_map(array('InterClass', 'square'), array(1, 2))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : object functionality *** +-- simple class with public variable and method -- + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +-- simple class with private variable and method -- + +Strict Standards: Non-static method SimpleClassPri::add() cannot be called statically in %s on line %d + +Warning: array_map(): The first argument, 'SimpleClassPri::add', should be either NULL or a valid callback in %s on line %d +NULL + +-- simple class with protected variable and method -- + +Strict Standards: Non-static method SimpleClassPro::mul() cannot be called statically in %s on line %d + +Warning: array_map(): The first argument, 'SimpleClassPro::mul', should be either NULL or a valid callback in %s on line %d +NULL + +-- class without members -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- abstract class -- +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d + +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d +defined in child +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d +defined in childarray(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with final method -- +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d + +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d +This function can't be overloaded +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d +This function can't be overloadedarray(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with static members -- +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +Warning: array_map(): The first argument, 'StaticClass::cube', should be either NULL or a valid callback in %s on line %d +NULL + +Warning: array_map(): The first argument, 'StaticClass::retVal', should be either NULL or a valid callback in %s on line %d +NULL +-- class implementing an interface -- +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_map_object2.phpt b/ext/standard/tests/array/array_map_object2.phpt new file mode 100644 index 000000000..91f713018 --- /dev/null +++ b/ext/standard/tests/array/array_map_object2.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_map() function : object functionality - with non-existent class and method +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for following object functionalities: + * 1) non-existent class + * 2) existent class and non-existent function + */ +echo "*** Testing array_map() : with non-existent class and method ***\n"; + +class SimpleClass +{ + public $var1 = 1; + public function square($n) { + return $n * $n; + } + public static function cube($n) { + return $n * $n * $n; + } +} + +echo "-- with non-existent class --\n"; +var_dump( array_map(array('non-existent', 'square'), array(1, 2)) ); + +echo "-- with existent class and non-existent method --\n"; +var_dump( array_map(array('SimpleClass', 'non-existent'), array(1, 2)) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : with non-existent class and method *** +-- with non-existent class -- + +Warning: array_map(): The first argument, 'non-existent::square', should be either NULL or a valid callback in %s on line %d +NULL +-- with existent class and non-existent method -- + +Warning: array_map(): The first argument, 'SimpleClass::non-existent', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_object3.phpt b/ext/standard/tests/array/array_map_object3.phpt new file mode 100644 index 000000000..56296a0b8 --- /dev/null +++ b/ext/standard/tests/array/array_map_object3.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_map() function : object functionality - class methods as callback function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for object functionality with following callback function variations: + * 1) child class method using parent object + * 2) parent class method using child object + * 3) child class method using parent class + * 4) parent class method using child class + */ +echo "*** Testing array_map() : class methods as callback function ***\n"; + +$arr1 = array(1, 5, 7); + +class ParentClass +{ + public $var1 = 10; + public static function staticParent1($n) { + return $n; + } + private static function staticParent2($n) { + return $n; + } +} +class ChildClass extends ParentClass +{ + var $parent_obj; + public function __construct ( ) { + $this->parent_obj = new ParentClass(); + } + public $var2 = 5; + public static function staticChild($n) { + return $n; + } + public function nonstaticChild($n) { + return $n; + } +} + +$childobj = new ChildClass(); +$parentobj = new ParentClass(); + +echo "-- accessing parent method from child class --\n"; +var_dump( array_map(array('ChildClass', 'staticParent1'), $arr1) ); + +echo "-- accessing child method from parent class --\n"; +var_dump( array_map(array('ParentClass', 'staticChild'), $arr1) ); + +echo "-- accessing parent method using child class object --\n"; +var_dump( array_map(array($childobj, 'staticParent1'), $arr1) ); + +echo "-- accessing child method using parent class object --\n"; +var_dump( array_map(array($parentobj, 'staticChild'), $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : class methods as callback function *** +-- accessing parent method from child class -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method from parent class -- + +Warning: array_map(): The first argument, 'ParentClass::staticChild', should be either NULL or a valid callback in %s on line %d +NULL +-- accessing parent method using child class object -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method using parent class object -- + +Warning: array_map(): The first argument, 'ParentClass::staticChild', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation1.phpt b/ext/standard/tests/array/array_map_variation1.phpt new file mode 100644 index 000000000..cd09be7ba --- /dev/null +++ b/ext/standard/tests/array/array_map_variation1.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_map() function : usage variations - string keys +--FILE-- +<?php + +/* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...]) + * Description: Applies the callback to the elements in given arrays. + * Source code: ext/standard/array.c +*/ + + + +echo "*** Testing array_map() : string keys ***\n"; + +$arr = array("stringkey" => "value"); +function cb1 ($a) {return array ($a);}; +function cb2 ($a,$b) {return array ($a,$b);}; +var_dump( array_map("cb1", $arr)); +var_dump( array_map("cb2", $arr,$arr)); +var_dump( array_map(null, $arr)); +var_dump( array_map(null, $arr, $arr)); +echo "Done"; +?> + +--EXPECT-- +*** Testing array_map() : string keys *** +array(1) { + ["stringkey"]=> + array(1) { + [0]=> + string(5) "value" + } +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +array(1) { + ["stringkey"]=> + string(5) "value" +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_map_variation10.phpt b/ext/standard/tests/array/array_map_variation10.phpt new file mode 100644 index 000000000..cc7543699 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation10.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_map() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing anoymous callback function with following variations + */ + +echo "*** Testing array_map() : anonymous callback function ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- anonymous function with all parameters and body --\n"; +var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1, $array2)); + +echo "-- anonymous function with two parameters and passing one array --\n"; +var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1)); + +echo "-- anonymous function with NULL parameter --\n"; +var_dump( array_map( create_function(NULL, 'return NULL;'), $array1)); + +echo "-- anonymous function with NULL body --\n"; +var_dump( array_map( create_function('$a', NULL), $array1)); + +echo "-- passing NULL as 'arr1' --\n"; +var_dump( array_map( create_function('$a', 'return array($a);'), NULL)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : anonymous callback function *** +-- anonymous function with all parameters and body -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(3) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +-- anonymous function with two parameters and passing one array -- + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + NULL + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + NULL + } +} +-- anonymous function with NULL parameter -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- anonymous function with NULL body -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- passing NULL as 'arr1' -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation11.phpt b/ext/standard/tests/array/array_map_variation11.phpt new file mode 100644 index 000000000..9cad3668d --- /dev/null +++ b/ext/standard/tests/array/array_map_variation11.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_map() function : usage variations - with recursive callback +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing subarrays and recursive callback function + */ + +echo "*** Testing array_map() : recursive callback function ***\n"; + +// callback function +function square_recur_single_array($var) { + if (is_array($var)) + return array_map('square_recur_single_array', $var); + return $var * $var; +} + +$array1 = array(1, array(2, 3, array(5)), array(4)); + +var_dump( array_map('square_recur_single_array', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : recursive callback function *** +array(3) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(9) + [2]=> + array(1) { + [0]=> + int(25) + } + } + [2]=> + array(1) { + [0]=> + int(16) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation12.phpt b/ext/standard/tests/array/array_map_variation12.phpt new file mode 100644 index 000000000..e599ed5a5 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation12.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_map() function : usage variations - built-in function as callback +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing buit-in function as callback function + */ + +echo "*** Testing array_map() : built-in function ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- with built-in function 'pow' and two parameters --\n"; +var_dump( array_map('pow', $array1, $array2)); + +echo "-- with built-in function 'pow' and one parameter --\n"; +var_dump( array_map('pow', $array1)); + +echo "-- with language construct --\n"; +var_dump( array_map('echo', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : built-in function *** +-- with built-in function 'pow' and two parameters -- +array(3) { + [0]=> + int(1) + [1]=> + int(16) + [2]=> + int(243) +} +-- with built-in function 'pow' and one parameter -- + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with language construct -- + +Warning: array_map(): The first argument, 'echo', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation13.phpt b/ext/standard/tests/array/array_map_variation13.phpt new file mode 100644 index 000000000..94babdf96 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation13.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test array_map() function : usage variations - callback function with different return types +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different callback function returning: + * int, string, bool, null values + */ + +echo "*** Testing array_map() : callback with diff return value ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- with integer return value --\n"; +function callback_int($a, $b) +{ + return $a + $b; +} +var_dump( array_map('callback_int', $array1, $array2)); + +echo "-- with string return value --\n"; +function callback_string($a, $b) +{ + return "$a"."$b"; +} +var_dump( array_map('callback_string', $array1, $array2)); + +echo "-- with bool return value --\n"; +function callback_bool($a, $b) +{ + return TRUE; +} +var_dump( array_map('callback_bool', $array1, $array2)); + +echo "-- with null return value --\n"; +function callback_null($array1) +{ + return NULL; +} +var_dump( array_map('callback_null', $array1)); + +echo "-- with no return value --\n"; +function callback_without_ret($arr1) +{ + echo "callback_without_ret called\n"; +} +var_dump( array_map('callback_without_ret', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : callback with diff return value *** +-- with integer return value -- +array(3) { + [0]=> + int(4) + [1]=> + int(6) + [2]=> + int(8) +} +-- with string return value -- +array(3) { + [0]=> + string(2) "13" + [1]=> + string(2) "24" + [2]=> + string(2) "35" +} +-- with bool return value -- +array(3) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(true) +} +-- with null return value -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with no return value -- +callback_without_ret called +callback_without_ret called +callback_without_ret called +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_map_variation14.phpt b/ext/standard/tests/array/array_map_variation14.phpt new file mode 100644 index 000000000..baa1f7753 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation14.phpt @@ -0,0 +1,125 @@ +--TEST-- +Test array_map() function : usage variations - null value for 'callback' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing null values for $callback argument and testing whether shortest + * array will be extended with empty elements + */ + +echo "*** Testing array_map() : null value for 'callback' argument ***\n"; + +// arrays to be passed as arguments +$arr1 = array(1, 2); +$arr2 = array("one", "two"); +$arr3 = array(1.1, 2.2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +/* calling array_map() with null callback */ + +echo "-- with null --\n"; +var_dump( array_map(null, $arr1, $arr2, $arr3) ); +var_dump( array_map(NULL, $arr1, $arr2, $arr3) ); + +echo "-- with unset variable --\n"; +var_dump( array_map(@$unset_var, $arr1, $arr2, $arr3) ); + +echo "-- with undefined variable --\n"; +var_dump( array_map(@$undefined_var, $arr1) ); + +echo "-- with empty string --\n"; +var_dump( array_map("", $arr1, $arr2) ); + +echo "-- with empty array --\n"; +var_dump( array_map(array(), $arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : null value for 'callback' argument *** +-- with null -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with unset variable -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with undefined variable -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- with empty string -- + +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s line %d +NULL +-- with empty array -- + +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation15.phpt b/ext/standard/tests/array/array_map_variation15.phpt new file mode 100644 index 000000000..9844d4c8c --- /dev/null +++ b/ext/standard/tests/array/array_map_variation15.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_map() function : usage variations - non existent 'callback' function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non existent function for $callback argument + */ + +echo "*** Testing array_map() : non existent 'callback' function ***\n"; + +// arrays to be passed as arguments +$arr1 = array(1, 2); +$arr2 = array("one", "two"); +$arr3 = array(1.1, 2.2); + +var_dump( array_map('non_existent', $arr1, $arr2, $arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : non existent 'callback' function *** + +Warning: array_map(): The first argument, 'non_existent', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation16.phpt b/ext/standard/tests/array/array_map_variation16.phpt new file mode 100644 index 000000000..e6972972d --- /dev/null +++ b/ext/standard/tests/array/array_map_variation16.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : usage variations - failing built-in functions & language constructs +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non-permmited built-in functions and language constructs i.e. + * echo(), array(), empty(), eval(), exit(), isset(), list(), print() + */ + +echo "*** Testing array_map() : non-permmited built-in functions ***\n"; + +// array to be passed as arguments +$arr1 = array(1, 2); + +// built-in functions & language constructs +$callback_names = array( +/*1*/ 'echo', + 'array', + 'empty', +/*4*/ 'eval', + 'exit', + 'isset', + 'list', +/*8*/ 'print' +); +for($count = 0; $count < count($callback_names); $count++) +{ + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_map($callback_names[$count], $arr1) ); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : non-permmited built-in functions *** +-- Iteration 1 -- + +Warning: array_map(): The first argument, 'echo', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_map(): The first argument, 'array', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_map(): The first argument, 'empty', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_map(): The first argument, 'eval', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_map(): The first argument, 'exit', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_map(): The first argument, 'isset', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_map(): The first argument, 'list', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_map(): The first argument, 'print', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation17.phpt b/ext/standard/tests/array/array_map_variation17.phpt new file mode 100644 index 000000000..4c96af230 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation17.phpt @@ -0,0 +1,158 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'callback' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different scalar/nonscalar values in place of $callback + */ + +echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n"; + +$arr1 = array(1, 2, 3); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$unexpected_callbacks = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // boolean data +/*10*/ true, + false, + TRUE, + FALSE, + + // empty data +/*14*/ "", + '', + + // array data +/*16*/ array(), + array(1, 2), + array(1, array(2)), + + // object data +/*19*/ new classA(), + + // resource variable +/*20*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_map +for($count = 0; $count < count($unexpected_callbacks); $count++) { + echo "\n-- Iteration ".($count + 1)." --"; + var_dump( array_map($unexpected_callbacks[$count], $arr1)); +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : unexpected values for 'callback' argument *** + +-- Iteration 1 -- +Warning: array_map(): The first argument, '0', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_map(): The first argument, '12345', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_map(): The first argument, '-2345', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_map(): The first argument, '10.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_map(): The first argument, '-10.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_map(): The first argument, '123456789000', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_map(): The first argument, '1.23456789E-9', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_map(): The first argument, '0.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_map(): The first argument, 'Class A object', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_map(): The first argument, 'Resource id #%d', should be either NULL or a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation18.phpt b/ext/standard/tests/array/array_map_variation18.phpt new file mode 100644 index 000000000..8170fb846 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation18.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non array values in place of $arr1 + */ + +echo "*** Testing array_map() : unexpected values for 'arr1' ***\n"; + +function callback($a) +{ + return $a; +} + +//get an unset array variable +$unset_var1 = array(1, 2); +unset ($unset_var1); + +// get an unset variable +$unset_var2 = 10; +unset ($unset_var2); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// different scalar/non-scalar values for array input +$unexpected_inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var1, + @$unset_var2, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $unexpected_inputs to check the behavior of array_map +for($count = 0; $count < count($unexpected_inputs); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_map('callback', $unexpected_inputs[$count])); +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : unexpected values for 'arr1' *** +-- Iteration 1 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 25 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation2.phpt b/ext/standard/tests/array/array_map_variation2.phpt new file mode 100644 index 000000000..6cd0096b6 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation2.phpt @@ -0,0 +1,276 @@ +--TEST-- +Test array_map() function : usage variations - references +--FILE-- +<?php + +/* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...]) + * Description: Applies the callback to the elements in given arrays. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_map() : references ***\n"; +$arr = array("k1" => "v1","k2"=>"v2"); +$arr[]=&$arr["k1"]; +$arr[]=&$arr; +function cb1 ($a) {var_dump ($a);return array ($a);}; +function cb2 (&$a) {var_dump ($a);return array (&$a);}; +var_dump( array_map("cb1", $arr)); +var_dump( array_map("cb2", $arr,$arr)); +var_dump( array_map(null, $arr)); +var_dump( array_map(null, $arr, $arr)); + +// Break cycles +$arr[0] = null; +$arr[1] = null; + +echo "Done"; +?> + +--EXPECT-- +*** Testing array_map() : references *** +string(2) "v1" +string(2) "v2" +string(2) "v1" +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +array(4) { + ["k1"]=> + array(1) { + [0]=> + string(2) "v1" + } + ["k2"]=> + array(1) { + [0]=> + string(2) "v2" + } + [0]=> + array(1) { + [0]=> + string(2) "v1" + } + [1]=> + array(1) { + [0]=> + array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } + } + } +} +string(2) "v1" +string(2) "v2" +string(2) "v1" +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +array(4) { + [0]=> + array(1) { + [0]=> + &string(2) "v1" + } + [1]=> + array(1) { + [0]=> + string(2) "v2" + } + [2]=> + array(1) { + [0]=> + &string(2) "v1" + } + [3]=> + array(1) { + [0]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } + } +} +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +array(4) { + [0]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [1]=> + array(2) { + [0]=> + string(2) "v2" + [1]=> + string(2) "v2" + } + [2]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [3]=> + array(2) { + [0]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation3.phpt b/ext/standard/tests/array/array_map_variation3.phpt new file mode 100644 index 000000000..a0715504e --- /dev/null +++ b/ext/standard/tests/array/array_map_variation3.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_map() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different arrays for $arr1 argument + */ + +echo "*** Testing array_map() : different arrays for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} + +// different arrays +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array( array(2), array(1)), // sub arrays + array(false,true), // array with default keys and boolean values + array(), // empty array + array(NULL), // array with NULL + array("a","aaaa","b","bbbb","c","ccccc"), + + // associative arrays +/*8*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : different arrays for 'arr1' argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 5 -- +array(0) { +} +-- Iteration 6 -- +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +array(6) { + [0]=> + string(1) "a" + [1]=> + string(4) "aaaa" + [2]=> + string(1) "b" + [3]=> + string(4) "bbbb" + [4]=> + string(1) "c" + [5]=> + string(5) "ccccc" +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +array(4) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) + [3]=> + int(30) +} +-- Iteration 11 -- +array(3) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 17 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- Iteration 18 -- +array(3) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_map_variation4.phpt b/ext/standard/tests/array/array_map_variation4.phpt new file mode 100644 index 000000000..2517d034e --- /dev/null +++ b/ext/standard/tests/array/array_map_variation4.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing associative array with different keys for $arr1 argument + */ + +echo "*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys +/*2*/ array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"), + + // arrays with string keys + array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33), +/*8*/ array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed values +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 6 -- +array(4) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +-- Iteration 7 -- +array(4) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +array(1) { + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +array(6) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [133]=> + string(3) "int" + [444]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_map_variation5.phpt b/ext/standard/tests/array/array_map_variation5.phpt new file mode 100644 index 000000000..55f156921 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation5.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing associative array with different values for $arr1 argument + */ + +echo "*** Testing array_map() : associative array with diff. values for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} +//get an unset variable +$unset_var = array(1, 2); +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333), + + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), +/*8*/ array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. values for 'arr1' argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(33333333.3333) +} +-- Iteration 7 -- +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" + [3]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_map_variation6.phpt b/ext/standard/tests/array/array_map_variation6.phpt new file mode 100644 index 000000000..2409a5763 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_map() function : usage variations - array having subarrays +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having different subarrays + */ + +echo "*** Testing array_map() : array having subarrays ***\n"; + +function callback($a) +{ + return $a; +} + +// different subarrays +$arr1 = array( + array(), + array(1, 2), + array('a', 'b'), + array(1, 2, 'a', 'b'), + array(1 => 'a', 'b' => 2) +); + +var_dump( array_map('callback', $arr1)); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array having subarrays *** +array(5) { + [0]=> + array(0) { + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [3]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(1) "a" + [3]=> + string(1) "b" + } + [4]=> + array(2) { + [1]=> + string(1) "a" + ["b"]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation7.phpt b/ext/standard/tests/array/array_map_variation7.phpt new file mode 100644 index 000000000..8f88a0f88 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation7.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test array_map() function : usage variations - arrays of different size +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having different size + * 1) first array as empty array + * 2) second array as empty array + * 3) second array shorter than first array + * 4) first array shorter than second array + * 5) one more array than callback function arguments + */ + +echo "*** Testing array_map() : arrays with diff. size ***\n"; + +function callback($a, $b) +{ + return array($a => $b); +} + +// calling array_map with different arrays +var_dump( array_map('callback', array(1, 2, 3), array()) ); +var_dump( array_map('callback', array(), array('a', 'b', 'c')) ); +var_dump( array_map('callback', array(1, 2, 3), array('a', 'b')) ); +var_dump( array_map('callback', array(012, 0x2F, 0X1A), array(2.3, 12.4e2)) ); +var_dump( array_map('callback', array(), array(1, 2, 3), array('a', 'b')) ); // passing more no. of arrays than callback function argument + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : arrays with diff. size *** +array(3) { + [0]=> + array(1) { + [1]=> + NULL + } + [1]=> + array(1) { + [2]=> + NULL + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + string(1) "a" + } + [1]=> + array(1) { + [""]=> + string(1) "b" + } + [2]=> + array(1) { + [""]=> + string(1) "c" + } +} +array(3) { + [0]=> + array(1) { + [1]=> + string(1) "a" + } + [1]=> + array(1) { + [2]=> + string(1) "b" + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [10]=> + float(2.3) + } + [1]=> + array(1) { + [47]=> + float(1240) + } + [2]=> + array(1) { + [26]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + int(1) + } + [1]=> + array(1) { + [""]=> + int(2) + } + [2]=> + array(1) { + [""]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation8.phpt b/ext/standard/tests/array/array_map_variation8.phpt new file mode 100644 index 000000000..5672e6cd9 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation8.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_map() function : usage variations - array with references +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having reference values for $arr1 argument + */ + +echo "*** Testing array_map() : array with references for 'arr1' argument ***\n"; + +function callback1($a) +{ + return ($a); +} + +function callback_cat($a, $b) +{ + return ($a . $b); +} + +// reference variables +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// array containing reference variables +$arr1 = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); +echo "-- with one array --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- with two arrays --\n"; +var_dump( array_map('callback_cat', $arr1, $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with references for 'arr1' argument *** +-- with one array -- +array(6) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + int(0) + ["hello"]=> + string(5) "hello" +} +-- with two arrays -- +array(6) { + [0]=> + string(2) "00" + [1]=> + string(10) "hellohello" + [2]=> + string(10) "hellohello" + [3]=> + string(10) "hellohello" + [4]=> + string(2) "00" + [5]=> + string(10) "hellohello" +} +Done diff --git a/ext/standard/tests/array/array_map_variation9.phpt b/ext/standard/tests/array/array_map_variation9.phpt new file mode 100644 index 000000000..b4f69739d --- /dev/null +++ b/ext/standard/tests/array/array_map_variation9.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test array_map() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having binary values for $arr1 argument + */ + +echo "*** Testing array_map() : array with binary data for 'arr1' argument ***\n"; + +function callback1($a) +{ + return ($a); +} +function callback2($a, $b) +{ + return array($a => $b); +} + +// array with binary data +$arr1 = array(b"hello", b"world", "1", b"22.22"); + +echo "-- checking binary safe array with one parameter callback function --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- checking binary safe array with two parameter callback function --\n"; +var_dump( array_map(b"callback2", $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with binary data for 'arr1' argument *** +-- checking binary safe array with one parameter callback function -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "1" + [3]=> + string(5) "22.22" +} +-- checking binary safe array with two parameter callback function -- + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d +array(4) { + [0]=> + array(1) { + ["hello"]=> + NULL + } + [1]=> + array(1) { + ["world"]=> + NULL + } + [2]=> + array(1) { + [1]=> + NULL + } + [3]=> + array(1) { + ["22.22"]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/array_merge_basic.phpt b/ext/standard/tests/array/array_merge_basic.phpt new file mode 100644 index 000000000..c4dc69638 --- /dev/null +++ b/ext/standard/tests/array/array_merge_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_merge() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_merge() + */ + +echo "*** Testing array_merge() : basic functionality ***\n"; + +//indexed array +$array1 = array ('zero', 'one', 'two'); +//associative array +$array2 = array ('a' => 1, 'b' => 2, 'c' => 3); + +var_dump(array_merge($array1, $array2)); + +var_dump(array_merge($array2, $array1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : basic functionality *** +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_error.phpt b/ext/standard/tests/array/array_merge_error.phpt new file mode 100644 index 000000000..3a394bbb7 --- /dev/null +++ b/ext/standard/tests/array/array_merge_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_merge() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : error conditions ***\n"; + +// Testing array_merge with zero arguments +echo "\n-- Testing array_merge() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_merge() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : error conditions *** + +-- Testing array_merge() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_merge() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_recursive_basic1.phpt b/ext/standard/tests/array/array_merge_recursive_basic1.phpt new file mode 100644 index 000000000..a86a8510a --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_basic1.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - array with default keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_merge_recursive() : array with default keys ***\n"; + +// Initialise the arrays +$arr1 = array(1, array(1, 2)); +$arr2 = array(3, array("hello", 'world')); +$arr3 = array(array(6, 7), array("str1", 'str2')); + +// Calling array_merge_recursive() with default arguments +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +// Calling array_merge_recursive() with more arguments +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1,$arr2) ); +var_dump( array_merge_recursive($arr1,$arr2,$arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with default keys *** +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(6) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [5]=> + array(2) { + [0]=> + string(4) "str1" + [1]=> + string(4) "str2" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_basic2.phpt b/ext/standard/tests/array/array_merge_recursive_basic2.phpt new file mode 100644 index 000000000..3f8c62e7a --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_basic2.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - associative arrays +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_merge_recursive() : associative arrays ***\n"; + +// Initialise the arrays +$arr1 = array(1 => "one", 2 => array(1, 2)); +$arr2 = array(2 => 'three', "four" => array("hello", 'world')); +$arr3 = array(1 => array(6, 7), 'four' => array("str1", 'str2')); + +// Calling array_merge_recursive() with default arguments +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +// Calling array_merge_recursive() with more arguments +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1,$arr2) ); +var_dump( array_merge_recursive($arr1,$arr2,$arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : associative arrays *** +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(5) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(4) "str1" + [3]=> + string(4) "str2" + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_error.phpt b/ext/standard/tests/array/array_merge_recursive_error.phpt new file mode 100644 index 000000000..b2fb1fd6d --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test array_merge_recursive() function : error conditions +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_merge_recursive() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_merge_recursive() function with Zero arguments --\n"; +var_dump( array_merge_recursive() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : error conditions *** + +-- Testing array_merge_recursive() function with Zero arguments -- + +Warning: Wrong parameter count for array_merge_recursive() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation1.phpt b/ext/standard/tests/array/array_merge_recursive_variation1.phpt new file mode 100644 index 000000000..75e0c2086 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation1.phpt @@ -0,0 +1,303 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr1 argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'arr1' argument of array_merge_recursive() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_merge_recursive() : Passing non array values to \$arr1 argument ***\n"; + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +class A +{ +// public $var = 10; + public function __toString() { + return "object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$arrays = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, + + // resource variable +/*23*/ $fp, + + // object data +/*24*/ new A() +); + +// initialise the second argument +$arr2 = array(1, array("hello", 'world')); + +// loop through each element of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "\n-- Iteration $iterator --"; + + // with default argument + echo "\n-- With default argument --"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing non array values to $arr1 argument *** + +-- Iteration 1 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation10.phpt b/ext/standard/tests/array/array_merge_recursive_variation10.phpt new file mode 100644 index 000000000..42d315eb8 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation10.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - two dimensional arrays +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * two dimensional arrays for $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : two dimensional array for \$arr1 argument ***\n"; + +// initialize the 2-d array +$arr1 = array( + array(1, 2, 3, 1), + "array" => array("hello", "world", "str1" => "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +// initialize the second argument +$arr2 = array(1, "hello", "array" => array("hello", 'world')); + +echo "-- Passing the entire 2-d array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "-- Passing the sub-array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1["array"]) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1["array"], $arr2["array"]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : two dimensional array for $arr1 argument *** +-- Passing the entire 2-d array -- +-- With default argument -- +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +-- With more arguments -- +array(6) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + [3]=> + int(1) + [4]=> + string(5) "hello" +} +-- Passing the sub-array -- +-- With default argument -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation2.phpt b/ext/standard/tests/array/array_merge_recursive_variation2.phpt new file mode 100644 index 000000000..83f237474 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation2.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'arr2' argument of array_merge_recursive() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_merge_recursive() : Passing non array values to \$arr2 argument ***\n"; + +// initialise the first argument +$arr1 = array(1, array("hello", 'world')); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +class A +{ +// public $var = 10; + public function __toString() { + return "object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$arrays = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, + + // resource variable +/*23*/ $fp, + + // object data +/*24*/ new A() +); + +// loop through each element of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr2) { + echo "\n-- Iteration $iterator --"; + var_dump( array_merge_recursive($arr1, $arr2) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing non array values to $arr2 argument *** + +-- Iteration 1 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation3.phpt b/ext/standard/tests/array/array_merge_recursive_variation3.phpt new file mode 100644 index 000000000..722388a01 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation3.phpt @@ -0,0 +1,761 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $arr1 argument and testing whether +* array_merge_recursive() behaves in an expected way. +*/ + +echo "*** Testing array_merge_recursive() : Passing different arrays to \$arr1 argument ***\n"; + +/* Different heredoc strings */ + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2,), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false, true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array containing embedded arrays +/*15*/ array("str1", "array" => array("hello", 'world'), array(1, 2)) +); + +// initialise the second argument +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing different arrays to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- With more arguments -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- With more arguments -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- With more arguments -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(0) { +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(1) { + [0]=> + NULL +} +-- With more arguments -- +array(5) { + [0]=> + NULL + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 7 -- +-- With default argument -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- With more arguments -- +array(7) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 9 -- +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +-- With more arguments -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 10 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 11 -- +-- With default argument -- +array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) +} +-- With more arguments -- +array(7) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 12 -- +-- With default argument -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- With more arguments -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 13 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 14 -- +-- With default argument -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- With more arguments -- +array(7) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 15 -- +-- With default argument -- +array(4) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- With more arguments -- +array(8) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 16 -- +-- With default argument -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- With more arguments -- +array(7) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 17 -- +-- With default argument -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) +} +-- With more arguments -- +array(10) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) + [6]=> + string(3) "one" + [7]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 18 -- +-- With default argument -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- With more arguments -- +array(7) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 19 -- +-- With default argument -- +array(3) { + [0]=> + string(4) "str1" + ["array"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(6) { + [0]=> + string(4) "str1" + ["array"]=> + array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "a" + [3]=> + string(1) "b" + [4]=> + string(1) "c" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation4.phpt b/ext/standard/tests/array/array_merge_recursive_variation4.phpt new file mode 100644 index 000000000..bacfe3aff --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation4.phpt @@ -0,0 +1,424 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing different + * associative arrays having different keys to $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : assoc. array with diff. keys to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ // arrays with integer keys + array(0 => "0", 1 => array(1 => "one")), + array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")), + + // arrays with float keys +/*3*/ array(2.3333 => "float", 44.44 => array(1.1 => "float")), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => array(1.1 => "f1"), 3333333.333333 => "f4"), + + // arrays with string keys +/*5*/ array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => array("heredoc", 'string'), "string"), + + // array with object, unset variable and resource variable +/*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello") +); + +// initialise the second array +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(2) { + [0]=> + string(5) "float" + [1]=> + array(1) { + [1]=> + string(5) "float" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "float" + [1]=> + array(1) { + [1]=> + string(5) "float" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(4) { + [0]=> + string(2) "f1" + [1]=> + string(2) "f2" + [2]=> + array(1) { + [1]=> + string(2) "f1" + } + [3]=> + string(2) "f4" +} +-- With more arguments -- +array(8) { + [0]=> + string(2) "f1" + [1]=> + string(2) "f2" + [2]=> + array(1) { + [1]=> + string(2) "f1" + } + [3]=> + string(2) "f4" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(3) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) +} +-- With more arguments -- +array(7) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(3) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["world"]=> + float(2.2) + ["pen +"]=> + int(111) +} +-- With more arguments -- +array(7) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["world"]=> + float(2.2) + ["pen +"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 7 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" +} +-- With more arguments -- +array(7) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(3) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + int(11) + [1]=> + string(5) "hello" +} +-- With more arguments -- +array(7) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + int(11) + [1]=> + string(5) "hello" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation5.phpt b/ext/standard/tests/array/array_merge_recursive_variation5.phpt new file mode 100644 index 000000000..3b251220e --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation5.phpt @@ -0,0 +1,404 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing different + * associative arrays having different values to $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : assoc. array with diff. values to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $arr1 argument +$arrays = array ( +// arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("f1" => 2.3333, "f2" => 2.3333, "f3" => array(1.1, 2.22)), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => array(1.2, 'f4' => 1.2)), + + // arrays with string values +/*5*/ array(111 => "\tHello", "array" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', 'array' => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "string" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "string" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// initialise the second array +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. values to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- With more arguments -- +array(6) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) +} +-- With more arguments -- +array(8) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(3) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } +} +-- With more arguments -- +array(7) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.8999992284) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } +} +-- With more arguments -- +array(8) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.8999992284) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(4) { + [0]=> + string(6) " Hello" + ["array"]=> + string(6) "col or" + [1]=> + string(7) "world" + [2]=> + string(6) " Hello" +} +-- With more arguments -- +array(7) { + [0]=> + string(6) " Hello" + ["array"]=> + array(4) { + [0]=> + string(6) "col or" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(7) "world" + [2]=> + string(6) " Hello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(7) "\tHello" + ["array"]=> + string(7) "col\tor" + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" +} +-- With more arguments -- +array(7) { + [0]=> + string(7) "\tHello" + ["array"]=> + array(4) { + [0]=> + string(7) "col\tor" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 7 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["string"]=> + string(11) "Hello world" + [1]=> + string(11) "Hello world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + ["string"]=> + array(2) { + [0]=> + string(11) "Hello world" + [1]=> + string(5) "hello" + } + [1]=> + string(11) "Hello world" + [2]=> + string(3) "one" + [3]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) +} +-- With more arguments -- +array(8) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + array(2) { + [0]=> + NULL + [1]=> + string(5) "hello" + } + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) + [3]=> + string(3) "one" + [4]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation6.phpt b/ext/standard/tests/array/array_merge_recursive_variation6.phpt new file mode 100644 index 000000000..8e460ba36 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation6.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with duplicate keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * array having duplicate keys. +*/ + +echo "*** Testing array_merge_recursive() : array with duplicate keys for \$arr1 argument ***\n"; + +/* initialize the array having duplicate keys */ +// array with numeric keys +$arr1_numeric_key = array( 1 => "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings')); +// array with string keys +$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111); + +// initialize the second argument +$arr2 = array("one", "str1" => "two", array("one", "two")); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1_numeric_key) ); +var_dump( array_merge_recursive($arr1_string_key) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1_numeric_key, $arr2) ); +var_dump( array_merge_recursive($arr1_string_key, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument *** +-- With default argument -- +array(3) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" +} +array(2) { + ["str1"]=> + string(5) "world" + ["str2"]=> + float(111.111) +} +-- With more arguments -- +array(6) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + [3]=> + string(3) "one" + ["str1"]=> + string(3) "two" + [4]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +array(4) { + ["str1"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(3) "two" + } + ["str2"]=> + float(111.111) + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation7.phpt b/ext/standard/tests/array/array_merge_recursive_variation7.phpt new file mode 100644 index 000000000..b244e7d6b --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation7.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with reference variables +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * array having reference variables. +*/ + +echo "*** Testing array_merge_recursive() : array with reference variables for \$arr1 argument ***\n"; + +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// input array containing elements as reference variables +$arr1 = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); + +// initialize the second argument +$arr2 = array($value4 => "hello", &$value2); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with reference variables for $arr1 argument *** +-- With default argument -- +array(6) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + &string(5) "hello" +} +-- With more arguments -- +array(7) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + } + [5]=> + &string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation8.phpt b/ext/standard/tests/array/array_merge_recursive_variation8.phpt new file mode 100644 index 000000000..6ad2f6989 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation8.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing an array having binary values. +*/ + +echo "*** Testing array_merge_recursive() : array with binary data for \$arr1 argument ***\n"; + +// array with binary values +$arr1 = array(b"1", b"hello" => "hello", b"world", "str1" => b"hello", "str2" => "world"); + +// initialize the second argument +$arr2 = array(b"str1" => b"binary", b"hello" => "binary", b"str2" => b"binary"); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with binary data for $arr1 argument *** +-- With default argument -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + [1]=> + string(5) "world" + ["str1"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + ["str2"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(6) "binary" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation9.phpt b/ext/standard/tests/array/array_merge_recursive_variation9.phpt new file mode 100644 index 000000000..d51d2f890 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation9.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - common key and value(Bug#43559) +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * arrays having common key and value. +*/ + +echo "*** Testing array_merge_recursive() : arrays with common key and value ***\n"; + +/* initialize the array having duplicate values */ + +// integer values +$arr1 = array("a" => 1, "b" => 2); +$arr2 = array("b" => 2, "c" => 4); +echo "-- Integer values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// float values +$arr1 = array("a" => 1.1, "b" => 2.2); +$arr2 = array("b" => 2.2, "c" => 3.3); +echo "-- Float values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// string values +$arr1 = array("a" => "hello", "b" => "world"); +$arr2 = array("b" => "world", "c" => "string"); +echo "-- String values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// boolean values +$arr1 = array("a" => true, "b" => false); +$arr2 = array("b" => false); +echo "-- Boolean values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// null values +$arr1 = array( "a" => NULL); +$arr2 = array( "a" => NULL); +echo "-- Null values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : arrays with common key and value *** +-- Integer values -- +array(3) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + [0]=> + int(2) + [1]=> + int(2) + } + ["c"]=> + int(4) +} +-- Float values -- +array(3) { + ["a"]=> + float(1.1) + ["b"]=> + array(2) { + [0]=> + float(2.2) + [1]=> + float(2.2) + } + ["c"]=> + float(3.3) +} +-- String values -- +array(3) { + ["a"]=> + string(5) "hello" + ["b"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(5) "world" + } + ["c"]=> + string(6) "string" +} +-- Boolean values -- +array(2) { + ["a"]=> + bool(true) + ["b"]=> + array(2) { + [0]=> + bool(false) + [1]=> + bool(false) + } +} +-- Null values -- +array(1) { + ["a"]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/array_merge_variation1.phpt b/ext/standard/tests/array/array_merge_variation1.phpt new file mode 100644 index 000000000..1ce71debb --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation1.phpt @@ -0,0 +1,231 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types to $arr1 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr1 argument to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr2 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($input, $arr2) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation10.phpt b/ext/standard/tests/array/array_merge_variation10.phpt new file mode 100644 index 000000000..7f08a4bb7 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation10.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_merge() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling array_merge(). + * This test is also passing more than two arguments to array_merge(). + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array ('zero', 'one', 'two'); +$arr2 = array ('zero', 'un', 'deux'); +$arr3 = array ('null', 'eins', 'zwei'); + +echo "\n-- Call array_merge() --\n"; +var_dump($result = array_merge($arr1, $arr2, $arr3)); + +echo "\n-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo "\$arr1: "; +echo key($arr1) . " => " . current ($arr1) . "\n"; +echo "\$arr2: "; +echo key($arr2) . " => " . current ($arr2) . "\n"; +echo "\$arr3: "; +echo key($arr3) . " => " . current ($arr3) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Call array_merge() -- +array(9) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(4) "zero" + [4]=> + string(2) "un" + [5]=> + string(4) "deux" + [6]=> + string(4) "null" + [7]=> + string(4) "eins" + [8]=> + string(4) "zwei" +} + +-- Position of Internal Pointer in Result: -- +0 => zero + +-- Position of Internal Pointer in Original Array: -- +$arr1: 0 => zero +$arr2: 0 => zero +$arr3: 0 => null +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation2.phpt b/ext/standard/tests/array/array_merge_variation2.phpt new file mode 100644 index 000000000..4ebbeb92b --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation2.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types as $arr2 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr2 argument to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr1 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($arr1, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation3.phpt b/ext/standard/tests/array/array_merge_variation3.phpt new file mode 100644 index 000000000..717968adb --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation3.phpt @@ -0,0 +1,379 @@ +--TEST-- +Test array_merge() function : usage variations - arrays of diff. data types +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types to test how array_merge adds them + * onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_merge +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_merge($input, $arr) ); + var_dump( array_merge($arr, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(1) + [4]=> + int(12345) + [5]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(7) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) + [5]=> + int(1) + [6]=> + int(2) +} +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(-10.5) + [4]=> + float(123456789000) + [5]=> + float(1.23456789E-9) + [6]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} + +-- Iteration 4: bool data -- +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + bool(true) + [5]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 7: string data -- +array(5) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" + [3]=> + int(1) + [4]=> + int(2) +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" + [4]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(3) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 10: unset data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 11: resource data -- +array(3) { + [0]=> + resource(%d) of type (stream) + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation4.phpt b/ext/standard/tests/array/array_merge_variation4.phpt new file mode 100644 index 000000000..e4eb2570c --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation4.phpt @@ -0,0 +1,368 @@ +--TEST-- +Test array_merge() function : usage variations - Diff. data types as array keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass an array with different data types as keys to test how array_merge + * adds it onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array ('one' => 1, 'two' => 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays with keys as different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_merge +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_merge($input, $arr) ); + var_dump( array_merge($arr, $input) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: float data -- +array(5) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3: extreme floats data -- +array(4) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4: null uppercase data -- +array(3) { + [""]=> + string(6) "null 1" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 1" +} + +-- Iteration 5: null lowercase data -- +array(3) { + [""]=> + string(6) "null 2" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 2" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8: empty double quotes data -- +array(3) { + [""]=> + string(6) "emptyd" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptyd" +} + +-- Iteration 9: empty single quotes data -- +array(3) { + [""]=> + string(6) "emptys" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptys" +} + +-- Iteration 10: string data -- +array(5) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11: undefined data -- +array(3) { + [""]=> + string(9) "undefined" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(9) "undefined" +} + +-- Iteration 12: unset data -- +array(3) { + [""]=> + string(5) "unset" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation5.phpt b/ext/standard/tests/array/array_merge_variation5.phpt new file mode 100644 index 000000000..eca6078e6 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation5.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_merge() function : usage variations - numeric keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with only numeric keys to test behaviour. + * $arr2 contains a duplicate element to $arr1. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//numeric keys +$arr1 = array('zero', 'one', 'two', 'three'); +$arr2 = array(1 => 'one', 20 => 'twenty', 30 => 'thirty'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(3) "one" + [5]=> + string(6) "twenty" + [6]=> + string(6) "thirty" +} +array(7) { + [0]=> + string(3) "one" + [1]=> + string(6) "twenty" + [2]=> + string(6) "thirty" + [3]=> + string(4) "zero" + [4]=> + string(3) "one" + [5]=> + string(3) "two" + [6]=> + string(5) "three" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation6.phpt b/ext/standard/tests/array/array_merge_variation6.phpt new file mode 100644 index 000000000..13b346eb3 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_merge() function : usage variations - string keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge arrays with string keys to test behaviour. + * $arr2 has a duplicate key to $arr1 + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//string keys +$arr1 = array('zero' => 'zero', 'one' => 'un', 'two' => 'deux'); +$arr2 = array('zero' => 'zero', 'un' => 'eins', 'deux' => 'zwei'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(5) { + ["zero"]=> + string(4) "zero" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" +} +array(5) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation7.phpt b/ext/standard/tests/array/array_merge_variation7.phpt new file mode 100644 index 000000000..00943f3ea --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation7.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_merge() function : usage variations - Mixed keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with mixed keys to test how it attaches them to + * existing arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//mixed keys +$arr1 = array('zero', 20 => 'twenty', 'thirty' => 30, true => 'bool'); +$arr2 = array(0, 1, 2, null => 'null', 1.234E-10 => 'float'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(8) { + [0]=> + string(4) "zero" + [1]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [2]=> + string(4) "bool" + [3]=> + string(5) "float" + [4]=> + int(1) + [5]=> + int(2) + [""]=> + string(4) "null" +} +array(8) { + [0]=> + string(5) "float" + [1]=> + int(1) + [2]=> + int(2) + [""]=> + string(4) "null" + [3]=> + string(4) "zero" + [4]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [5]=> + string(4) "bool" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation8.phpt b/ext/standard/tests/array/array_merge_variation8.phpt new file mode 100644 index 000000000..a4cdea74f --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation8.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_merge() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test array_merge() with multi-dimensional arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array('zero', 'one', 'two', array(0)); +$arr2 = array(1, 2, 3); + +echo "\n-- Merge a two-dimensional and a one-dimensional array --\n"; +var_dump(array_merge($arr1, $arr2)); + +echo "\n-- Merge an array and a sub-array --\n"; +var_dump(array_merge($arr1[3], $arr2)); +var_dump(array_merge($arr2, $arr1[3])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Merge a two-dimensional and a one-dimensional array -- +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + array(1) { + [0]=> + int(0) + } + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) +} + +-- Merge an array and a sub-array -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation9.phpt b/ext/standard/tests/array/array_merge_variation9.phpt new file mode 100644 index 000000000..e42e29282 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation9.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test array_merge() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* Test array_merge() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array as the first argument and a reference to that array as the second. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$val1 = 'foo'; +$val2 = 'bar'; +$val3 = 'baz'; + +$arr1 = array(&$val1, &$val2, &$val3); +$arr2 = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); + +echo "\n-- Merge an array made up of referenced variables to an assoc. array --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +$val2 = 'hello world'; + +echo "\n-- Change \$val2 --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "\n-- Merge an array and a reference to the first array --\n"; +var_dump(array_merge($arr2, &$arr2)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Merge an array made up of referenced variables to an assoc. array -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" +} + +-- Change $val2 -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" +} + +-- Merge an array and a reference to the first array -- +array(3) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +Done diff --git a/ext/standard/tests/array/array_pad_basic.phpt b/ext/standard/tests/array/array_pad_basic.phpt new file mode 100644 index 000000000..1dfc71e01 --- /dev/null +++ b/ext/standard/tests/array/array_pad_basic.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test array_pad() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_pad() : basic functionality ***\n"; + +// Initialise $input and $pad_value arguments +$input = array(1, 2, 3); +$pad_value = -3; + +// positive $pad_size +echo "-- Positive pad_size --\n"; +var_dump( array_pad($input, 8, $pad_value) ); + +// negative $pad_size +echo "-- Negative pad_size --\n"; +var_dump( array_pad($input, -8, $pad_value) ); + +// $pad_size less than array size, no padding expected +echo "-- Pad_size lesser than array_size --\n"; +var_dump( array_pad($input, 2, $pad_value) ); + +// $pad_size equal to array size, no padding expected +echo "-- Pad_size equal to array_size --\n"; +var_dump( array_pad($input, 3, $pad_value) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : basic functionality *** +-- Positive pad_size -- +array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(-3) + [4]=> + int(-3) + [5]=> + int(-3) + [6]=> + int(-3) + [7]=> + int(-3) +} +-- Negative pad_size -- +array(8) { + [0]=> + int(-3) + [1]=> + int(-3) + [2]=> + int(-3) + [3]=> + int(-3) + [4]=> + int(-3) + [5]=> + int(1) + [6]=> + int(2) + [7]=> + int(3) +} +-- Pad_size lesser than array_size -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- Pad_size equal to array_size -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_error.phpt b/ext/standard/tests/array/array_pad_error.phpt new file mode 100644 index 000000000..49fa66e86 --- /dev/null +++ b/ext/standard/tests/array/array_pad_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_pad() function : error conditions +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_pad() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_pad() function with Zero arguments --\n"; +var_dump( array_pad() ); + +//Test array_pad with one more than the expected number of arguments +echo "\n-- Testing array_pad() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +$pad_value = 1; +$extra_arg = 10; +var_dump( array_pad($input, $pad_size, $pad_value, $extra_arg) ); + +// Testing array_pad with less than the expected number of arguments +echo "\n-- Testing array_pad() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +var_dump( array_pad($input, $pad_size) ); +var_dump( array_pad($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : error conditions *** + +-- Testing array_pad() function with Zero arguments -- + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL + +-- Testing array_pad() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL + +-- Testing array_pad() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation1.phpt b/ext/standard/tests/array/array_pad_variation1.phpt new file mode 100644 index 000000000..b92f36da7 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation1.phpt @@ -0,0 +1,270 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $input argument other than arrays +* and see that function outputs proper warning messages wherever expected. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non array values to \$input argument ***\n"; + +// Initialise $pad_size and $pad_value +$pad_size = 10; +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non array values to $input argument *** + +-- Iteration 1 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation2.phpt b/ext/standard/tests/array/array_pad_variation2.phpt new file mode 100644 index 000000000..0413b9ef2 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation2.phpt @@ -0,0 +1,288 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482) +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $pad_size argument other than integers +* and see that function outputs proper warning messages wherever expected. +* The $input and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n"; + +// Initialise $input and $pad_value arguments +$input = array(1, 2); +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +//array of values to iterate over +$pad_sizes = array( + + // float data +/*1*/ 10.5, + -10.5, + 12.3456789000e10, + -12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $pad_sizes to check the behavior of array_pad() +$iterator = 1; +foreach($pad_sizes as $pad_size) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non integer values to $pad_size argument *** +-- Iteration 1 -- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(1) +} +-- Iteration 2 -- +array(10) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(2) +} +-- Iteration 3 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 5 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 6 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 7 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 8 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 9 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 10 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 11 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 12 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 13 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 14 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 15 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 16 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 17 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 19 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 20 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 21 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 22 -- + +Notice: Object of class classA could not be converted to int in %s on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 23 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 24 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation3.phpt b/ext/standard/tests/array/array_pad_variation3.phpt new file mode 100644 index 000000000..75df11822 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation3.phpt @@ -0,0 +1,869 @@ +--TEST-- +Test array_pad() function : usage variations - possible values for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function for expected behavior by passing +* different possible values for $pad_value argument. +* $input and $pad_size arguments take fixed value. +*/ + +echo "*** Testing array_pad() : possible values for \$pad_value argument ***\n"; + +// Initialise $input and $pad_size argument +$input = array(1, 2); +$pad_size = 4; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a reference variable +$value = "hello"; +$reference = &$value; + +// different values to be passed to $pad_value argument +$pad_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // strings with different white spaces +/*26*/ "\v\fHello\t world!! \rstring\n", + '\v\fHello\t world!! \rstring\n', + + // object data +/*28*/ new classA(), + + // undefined data +/*29*/ @$undefined_var, + + // unset data +/*30*/ @$unset_var, + + // resource variable +/*31*/ $fp, + + // reference variable +/*32*/ $reference +); + +// loop through each element of $pad_values to check the behavior of array_pad() +$iterator = 1; +foreach($pad_values as $pad_value) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : possible values for $pad_value argument *** +-- Iteration 1 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(0) +} +array(4) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 2 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 3 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(12345) + [3]=> + int(12345) +} +array(4) { + [0]=> + int(12345) + [1]=> + int(12345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 4 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(-2345) + [3]=> + int(-2345) +} +array(4) { + [0]=> + int(-2345) + [1]=> + int(-2345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 5 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(10.5) +} +array(4) { + [0]=> + float(10.5) + [1]=> + float(10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 6 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(-10.5) + [3]=> + float(-10.5) +} +array(4) { + [0]=> + float(-10.5) + [1]=> + float(-10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 7 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(123456789000) + [3]=> + float(123456789000) +} +array(4) { + [0]=> + float(123456789000) + [1]=> + float(123456789000) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 8 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(1.23456789E-9) + [3]=> + float(1.23456789E-9) +} +array(4) { + [0]=> + float(1.23456789E-9) + [1]=> + float(1.23456789E-9) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 9 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(0.5) + [3]=> + float(0.5) +} +array(4) { + [0]=> + float(0.5) + [1]=> + float(0.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 10 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(0) { + } + [3]=> + array(0) { + } +} +array(4) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 11 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(0) + } + [3]=> + array(1) { + [0]=> + int(0) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(0) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 12 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(1) + } + [3]=> + array(1) { + [0]=> + int(1) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 13 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [3]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 14 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [3]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +array(4) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 15 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 16 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 17 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 18 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 19 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 20 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 21 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 22 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 23 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 24 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 25 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(11) "hello world" + [3]=> + string(11) "hello world" +} +array(4) { + [0]=> + string(11) "hello world" + [1]=> + string(11) "hello world" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 26 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(25) "Hello world!!
string +" + [3]=> + string(25) "Hello world!!
string +" +} +array(4) { + [0]=> + string(25) "Hello world!!
string +" + [1]=> + string(25) "Hello world!!
string +" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 27 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(30) "\v\fHello\t world!! \rstring\n" + [3]=> + string(30) "\v\fHello\t world!! \rstring\n" +} +array(4) { + [0]=> + string(30) "\v\fHello\t world!! \rstring\n" + [1]=> + string(30) "\v\fHello\t world!! \rstring\n" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 28 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } + [3]=> + object(classA)#%d (0) { + } +} +array(4) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + object(classA)#%d (0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 29 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 30 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 31 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) + [3]=> + resource(%d) of type (stream) +} +array(4) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 32 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" +} +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + int(1) + [3]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation4.phpt b/ext/standard/tests/array/array_pad_variation4.phpt new file mode 100644 index 000000000..83c1e8300 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_pad() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing binary values to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing binary values to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 6; + +// initialize $pad_value with reference variable +$binary = b"hello"; + +var_dump( array_pad($input, $pad_size, $binary) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $binary) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing binary values to $pad_value argument *** +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(5) "hello" + [4]=> + string(5) "hello" + [5]=> + string(5) "hello" +} +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + int(1) + [4]=> + int(2) + [5]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation5.phpt b/ext/standard/tests/array/array_pad_variation5.phpt new file mode 100644 index 000000000..4e8e0f113 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation5.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-d array to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 5; + +// initialize $pad_value +$pad_value = array ( + array(1), + array("hello", 'world'), + array("one" => 1, 'two' => 2) +); + +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_value' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_value' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-d array to $pad_value argument *** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [4]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } +} +array(5) { + [0]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [1]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [2]=> + int(1) + [3]=> + int(2) + [4]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation6.phpt b/ext/standard/tests/array/array_pad_variation6.phpt new file mode 100644 index 000000000..2f97e3ee5 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation6.phpt @@ -0,0 +1,668 @@ +--TEST-- +Test array_pad() function : usage variations - different arrays for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing different arrays to \$input argument ***\n"; + +/* Different heredoc strings */ + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// different arrays to be passed to $input argument +$inputs = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 6; +$pad_value = "HELLO"; + +// loop through each sub-array within $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + int(1) + [5]=> + int(2) +} +-- Iteration 2 -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + float(1.1) + [5]=> + float(2.2) +} +-- Iteration 3 -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + bool(false) + [5]=> + bool(true) +} +-- Iteration 4 -- +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +-- Iteration 5 -- +array(6) { + [0]=> + NULL + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + NULL +} +-- Iteration 6 -- +array(6) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(5) "b bbb" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(3) "a" + [3]=> + string(5) "aaaa
" + [4]=> + string(5) "b bbb" + [5]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(6) "b\tbbb" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "a\v\f" + [3]=> + string(6) "aaaa\r" + [4]=> + string(6) "b\tbbb" + [5]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(6) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [0]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [2]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 10 -- +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 11 -- +array(6) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + int(30) + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + int(10) + [3]=> + int(20) + [4]=> + int(40) + [5]=> + int(30) +} +-- Iteration 12 -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(6) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(6) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 15 -- +array(6) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(4) "true" + [3]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(6) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 18 -- +array(6) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 19 -- +array(6) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation7.phpt b/ext/standard/tests/array/array_pad_variation7.phpt new file mode 100644 index 000000000..887f35194 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation7.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-D array to \$input argument ***\n"; + +// initialize the 2-d array +$input = array ( + array(1, 2, 3), + array("hello", 'world'), + array("one" => 1, "two" => 2) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 5; +$pad_value = "HELLO"; + +// entire 2-d array +echo "-- Entire 2-d array for \$input argument --\n"; +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + +// sub array +echo "-- Sub array for \$input argument --\n"; +var_dump( array_pad($input[1], $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input[1], -$pad_size, $pad_value) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-D array to $input argument *** +-- Entire 2-d array for $input argument -- +array(5) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } +} +-- Sub array for $input argument -- +array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "hello" + [4]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_push_basic.phpt b/ext/standard/tests/array/array_push_basic.phpt new file mode 100644 index 000000000..5ccf037da --- /dev/null +++ b/ext/standard/tests/array/array_push_basic.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_push() function : basic functionality +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_push with indexed and associative arrays + */ + +echo "*** Testing array_push() : basic functionality ***\n"; + +$array = array ('zero', 'one', 'two'); +$var1 = 'three'; +$var2 = 'four'; + +echo "\n-- Push values onto an indexed array --\n"; +var_dump(array_push($array, $var1, $var2)); +var_dump($array); + +$array_assoc = array ('one' => 'un', 'two' => 'deux'); + +echo "\n-- Push values onto an associative array --\n"; +var_dump(array_push($array_assoc, $var1, $var2)); +var_dump($array_assoc); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : basic functionality *** + +-- Push values onto an indexed array -- +int(5) +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" +} + +-- Push values onto an associative array -- +int(4) +array(4) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + [0]=> + string(5) "three" + [1]=> + string(4) "four" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_error1.phpt b/ext/standard/tests/array/array_push_error1.phpt new file mode 100644 index 000000000..1b427ff93 --- /dev/null +++ b/ext/standard/tests/array/array_push_error1.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_push() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_push() to test behaviour + */ + +echo "*** Testing array_push() : error conditions ***\n"; + +// Testing array_push with one less than the expected number of arguments +echo "\n-- Testing array_push() function with less than expected no. of arguments --\n"; +$stack = array(1, 2); +var_dump( array_push($stack) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : error conditions *** + +-- Testing array_push() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_push() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_error2.phpt b/ext/standard/tests/array/array_push_error2.phpt new file mode 100644 index 000000000..86f8df78b --- /dev/null +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_push() function : error conditions - min and max int values as keys +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Use PHP's minimum and maximum integer values as array keys + * then try and push new elements onto the array + */ + +echo "*** Testing array_push() : error conditions ***\n"; + +$array = array(-PHP_INT_MAX => 'min', PHP_INT_MAX => 'max'); + +var_dump(array_push($array, 'new')); +var_dump($array); +var_dump(array_push($array, 'var')); +var_dump($array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : error conditions *** +int(3) +array(3) { + [-2147483647]=> + string(3) "min" + [2147483647]=> + string(3) "max" + [-2147483648]=> + string(3) "new" +} + +Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d +bool(false) +array(3) { + [-2147483647]=> + string(3) "min" + [2147483647]=> + string(3) "max" + [-2147483648]=> + string(3) "new" +} +Done diff --git a/ext/standard/tests/array/array_push_variation1.phpt b/ext/standard/tests/array/array_push_variation1.phpt new file mode 100644 index 000000000..c4451d9e4 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation1.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test array_push() function : usage variations - Pass different data types as $stack arg +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $stack argument to array_push() to test behaviour + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = 'value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_push($input, $var) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 18 -- +int(1) + +-- Iteration 19 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation2.phpt b/ext/standard/tests/array/array_push_variation2.phpt new file mode 100644 index 000000000..7fefcfa49 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation2.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test array_push() function : usage variations - Pass different data types as $var arg +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $var argument to array_push to test behaviour + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$stack = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $var argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + $temp_array = $stack; + var_dump( array_push($temp_array, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 -- +int(3) + +-- Iteration 2 -- +int(3) + +-- Iteration 3 -- +int(3) + +-- Iteration 4 -- +int(3) + +-- Iteration 5 -- +int(3) + +-- Iteration 6 -- +int(3) + +-- Iteration 7 -- +int(3) + +-- Iteration 8 -- +int(3) + +-- Iteration 9 -- +int(3) + +-- Iteration 10 -- +int(3) + +-- Iteration 11 -- +int(3) + +-- Iteration 12 -- +int(3) + +-- Iteration 13 -- +int(3) + +-- Iteration 14 -- +int(3) + +-- Iteration 15 -- +int(3) + +-- Iteration 16 -- +int(3) + +-- Iteration 17 -- +int(3) + +-- Iteration 18 -- +int(3) + +-- Iteration 19 -- +int(3) + +-- Iteration 20 -- +int(3) + +-- Iteration 21 -- +int(3) + +-- Iteration 22 -- +int(3) + +-- Iteration 23 -- +int(3) + +-- Iteration 24 -- +int(3) + +-- Iteration 25 -- +int(3) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation3.phpt b/ext/standard/tests/array/array_push_variation3.phpt new file mode 100644 index 000000000..2bc71a769 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation3.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_push() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Test array_push when passed: + * 1. an array as $var arg + * 2. as sub-array as $stack arg + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +echo "\n-- Pass array as \$var argument --\n"; +$array = array(1, 2, 3); +$sub_array = array('one', 'two'); +var_dump(array_push($array, $sub_array)); +var_dump($array); + +echo "\n-- Pass sub-array as \$stack argument --\n"; +var_dump(array_push($array[3], 'a')); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Pass array as $var argument -- +int(4) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} + +-- Pass sub-array as $stack argument -- +int(3) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(1) "a" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation4.phpt b/ext/standard/tests/array/array_push_variation4.phpt new file mode 100644 index 000000000..1048d80cf --- /dev/null +++ b/ext/standard/tests/array/array_push_variation4.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_push() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Test array_push when: + * 1. passed referenced variables as $var arguments + * 2. $var argument is a reference to $stack argument + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +$var1 = 'a'; +$var2 = 'b'; +$var3 = 'c'; +$var4 = 'x'; +$var5 = 'y'; +$var6 = 'z'; + +$array = array(1, 2, 3); + +echo "\n-- Pass array_push referenced varialbes as \$var arguments --\n"; +var_dump(array_push($array, &$var1, &$var2, &$var3, &$var4, &$var5, &$var6)); +var_dump($array); + +echo "\n-- Pass \$var argument which is a reference to \$stack argument --\n"; +var_dump(array_push($array, &$array)); +var_dump($array); + +/* break cycle */ +$array[9] = null; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Pass array_push referenced varialbes as $var arguments -- +int(9) +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" +} + +-- Pass $var argument which is a reference to $stack argument -- +int(10) +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + &array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + &array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + *RECURSION* + } + } +} +Done diff --git a/ext/standard/tests/array/array_push_variation5.phpt b/ext/standard/tests/array/array_push_variation5.phpt new file mode 100644 index 000000000..4b6f39975 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation5.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_push() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling array_push() + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +$stack = array ('one' => 'un', 'two' => 'deux'); +$var0 = 'zero'; + +echo "\n-- Call array_push() --\n"; +var_dump($result = array_push($stack, $var0)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_push() : usage variations *** + +-- Call array_push() -- +int(3) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/ext/standard/tests/array/array_push_variation6.phpt b/ext/standard/tests/array/array_push_variation6.phpt new file mode 100644 index 000000000..19afebb74 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation6.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test array_push() function : usage variations - array keys are different data types +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_push arrays where the keys are different data types. + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = 'value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types as keys to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + echo "Before : "; + var_dump(count($input)); + echo "After : "; + var_dump( array_push($input, $var) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 : int data -- +Before : int(4) +After : int(5) + +-- Iteration 2 : float data -- +Before : int(3) +After : int(4) + +-- Iteration 3 : extreme floats data -- +Before : int(2) +After : int(3) + +-- Iteration 4 : null uppercase data -- +Before : int(1) +After : int(2) + +-- Iteration 5 : null lowercase data -- +Before : int(1) +After : int(2) + +-- Iteration 6 : bool lowercase data -- +Before : int(2) +After : int(3) + +-- Iteration 7 : bool uppercase data -- +Before : int(2) +After : int(3) + +-- Iteration 8 : empty double quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 9 : empty single quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 10 : string data -- +Before : int(3) +After : int(4) + +-- Iteration 11 : undefined data -- +Before : int(1) +After : int(2) + +-- Iteration 12 : unset data -- +Before : int(1) +After : int(2) +Done diff --git a/ext/standard/tests/array/array_reverse_variation5.phpt b/ext/standard/tests/array/array_reverse_variation5.phpt index 2d22be035..6c4c95224 100644 --- a/ext/standard/tests/array/array_reverse_variation5.phpt +++ b/ext/standard/tests/array/array_reverse_variation5.phpt @@ -1,5 +1,7 @@ --TEST-- Test array_reverse() function : usage variations - assoc. array with diff. value for 'array' argument +--INI-- +precision=12 --FILE-- <?php /* Prototype : array array_reverse(array $array [, bool $preserve_keys]) @@ -179,7 +181,7 @@ array(1) { - default argument - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [0]=> float(4.8999992284) ["f2"]=> @@ -190,7 +192,7 @@ array(4) { - $preserve keys = true - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [3]=> float(4.8999992284) ["f2"]=> @@ -201,7 +203,7 @@ array(4) { - $preserve_keys = false - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [0]=> float(4.8999992284) ["f2"]=> diff --git a/ext/standard/tests/array/array_shift_basic.phpt b/ext/standard/tests/array/array_shift_basic.phpt new file mode 100644 index 000000000..2bb4ae93a --- /dev/null +++ b/ext/standard/tests/array/array_shift_basic.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_shift() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_shift() + */ + +echo "*** Testing array_shift() : basic functionality ***\n"; + +$array = array('zero', 'one', '3' => 'three', 'four' => 4); +echo "\n-- Before shift: --\n"; +var_dump($array); + +echo "\n-- After shift: --\n"; +echo "Returned value:\t"; +var_dump(array_shift($array)); +echo "New array:\n"; +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : basic functionality *** + +-- Before shift: -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [3]=> + string(5) "three" + ["four"]=> + int(4) +} + +-- After shift: -- +Returned value: string(4) "zero" +New array: +array(3) { + [0]=> + string(3) "one" + [1]=> + string(5) "three" + ["four"]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_error.phpt b/ext/standard/tests/array/array_shift_error.phpt new file mode 100644 index 000000000..bbf62de5b --- /dev/null +++ b/ext/standard/tests/array/array_shift_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_shift() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_shift() to test behaviour + */ + +echo "*** Testing array_shift() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_shift() function with Zero arguments --\n"; +var_dump( array_shift() ); + +//Test array_shift with one more than the expected number of arguments +echo "\n-- Testing array_shift() function with more than expected no. of arguments --\n"; +$stack = array(1, 2); +$extra_arg = 10; +var_dump( array_shift($stack, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : error conditions *** + +-- Testing array_shift() function with Zero arguments -- + +Warning: Wrong parameter count for array_shift() in %s on line %d +NULL + +-- Testing array_shift() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_shift() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation1.phpt b/ext/standard/tests/array/array_shift_variation1.phpt new file mode 100644 index 000000000..eafe7a90e --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test array_shift() function : usage variations - Pass different data types as $stack arg +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $stack argument to array_shift() to test behaviour + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_shift() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_shift($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation2.phpt b/ext/standard/tests/array/array_shift_variation2.phpt new file mode 100644 index 000000000..2b3adc605 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation2.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test array_shift() function : usage variations - Pass arrays of different data types +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where values are of one data type to test behaviour of array_shift() + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_shift +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_shift($input) ); + var_dump($input); + $iterator++; +}; + +fclose($fp); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1: int data -- +int(0) +array(3) { + [0]=> + int(1) + [1]=> + int(12345) + [2]=> + int(-2345) +} + +-- Iteration 2: float data -- +float(10.5) +array(4) { + [0]=> + float(-10.5) + [1]=> + float(123456789000) + [2]=> + float(1.23456789E-9) + [3]=> + float(0.5) +} + +-- Iteration 3: null data -- +NULL +array(1) { + [0]=> + NULL +} + +-- Iteration 4: bool data -- +bool(true) +array(3) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + bool(false) +} + +-- Iteration 5: empty string data -- +string(0) "" +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +NULL +array(0) { +} + +-- Iteration 7: string data -- +string(6) "string" +array(2) { + [0]=> + string(6) "string" + [1]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +object(classA)#%d (0) { +} +array(0) { +} + +-- Iteration 9: undefined data -- +NULL +array(0) { +} + +-- Iteration 10: unset data -- +NULL +array(0) { +} + +-- Iteration 11: resource data -- +resource(%d) of type (stream) +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation3.phpt b/ext/standard/tests/array/array_shift_variation3.phpt new file mode 100644 index 000000000..cc260c630 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation3.phpt @@ -0,0 +1,188 @@ +--TEST-- +Test array_shift() function : usage variations - Pass array with different data types as keys +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays with different data types as keys to test how array_shift() re-assigns keys + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_shift() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_shift($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1 : int data -- +string(4) "zero" +array(3) { + [0]=> + string(3) "one" + [1]=> + string(8) "positive" + [2]=> + string(8) "negative" +} + +-- Iteration 2 : float data -- +string(8) "positive" +array(2) { + [0]=> + string(8) "negative" + [1]=> + string(4) "half" +} + +-- Iteration 3 : extreme floats data -- +string(5) "large" +array(1) { + [0]=> + string(5) "small" +} + +-- Iteration 4 : null uppercase data -- +string(6) "null 1" +array(0) { +} + +-- Iteration 5 : null lowercase data -- +string(6) "null 2" +array(0) { +} + +-- Iteration 6 : bool lowercase data -- +string(6) "lowert" +array(1) { + [0]=> + string(6) "lowerf" +} + +-- Iteration 7 : bool uppercase data -- +string(6) "uppert" +array(1) { + [0]=> + string(6) "upperf" +} + +-- Iteration 8 : empty double quotes data -- +string(6) "emptyd" +array(0) { +} + +-- Iteration 9 : empty single quotes data -- +string(6) "emptys" +array(0) { +} + +-- Iteration 10 : string data -- +string(7) "stringd" +array(2) { + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11 : undefined data -- +string(9) "undefined" +array(0) { +} + +-- Iteration 12 : unset data -- +string(5) "unset" +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation4.phpt b/ext/standard/tests/array/array_shift_variation4.phpt new file mode 100644 index 000000000..f27681561 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation4.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_shift() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test popping elements from a sub-array and popping an array from an array + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack_first = array(array(1, 2, 3), 'one', 'two'); +$stack_last = array ('zero', 'one', array (1, 2, 3)); +echo "\n-- Before shift: --\n"; +echo "---- \$stack_first:\n"; +var_dump($stack_first); +echo "---- \$stack_last:\n"; +var_dump($stack_last); + +echo "\n-- After shift: --\n"; +echo "---- Pop array from array:\n"; +echo "Returned value:\t"; +var_dump(array_shift($stack_first)); +echo "New array:\n"; +var_dump($stack_first); + +echo "---- Pop element from array within array:\n"; +echo "Returned value:\t"; +var_dump(array_shift($stack_last[2])); +echo "New array:\n"; +var_dump($stack_last); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Before shift: -- +---- $stack_first: +array(3) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +---- $stack_last: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- After shift: -- +---- Pop array from array: +Returned value: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +New array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +---- Pop element from array within array: +Returned value: int(1) +New array: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation5.phpt b/ext/standard/tests/array/array_shift_variation5.phpt new file mode 100644 index 000000000..2ac15da6b --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation5.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_shift() function : usage variations - call recursively +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Use the result of one call to array_shift + * as the the $stack argument of another call to array_shift() + * When done in one statement causes strict error messages. + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack = array ( array ( array ('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei'); + +// not following strict standards +echo "\n-- Incorrect Method: --\n"; +var_dump(array_shift(array_shift(array_shift($stack)))); + +$stack = array (array( array('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei'); +// correct way of doing above: +echo "\n-- Correct Method: --\n"; +$result1 = array_shift($stack); +$result2 = array_shift($result1); +var_dump(array_shift($result2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Incorrect Method: -- + +Strict Standards: Only variables should be passed by reference in %s on line %d + +Strict Standards: Only variables should be passed by reference in %s on line %d +string(4) "zero" + +-- Correct Method: -- +string(4) "zero" +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation6.phpt b/ext/standard/tests/array/array_shift_variation6.phpt new file mode 100644 index 000000000..9033e7d17 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation6.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test array_shift() function : usage variations - Referenced arrays +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test how array_shift when passed: + * 1. a variable that is referenced to an array + * 2. an array that contains a referenced array + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +echo "\n-- Variable is referenced array --\n"; +$original_array = array('zero', 'one', 'two'); +$copied_array = &$original_array; + +echo "Result: "; +var_dump(array_shift($copied_array)); +echo "\n\$original_array:\n"; +var_dump($original_array); +echo "\n\$copied_array:\n"; +var_dump($copied_array); + +echo "\n-- Element is referenced array --\n"; +$new_array = array (&$copied_array, 1, 'two'); +echo "Result: "; +var_dump(array_shift($new_array[0])); +echo "\n\$new_array:\n"; +var_dump($new_array); +echo "\n\$copied_array\n"; +var_dump($copied_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Variable is referenced array -- +Result: string(4) "zero" + +$original_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +$copied_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +-- Element is referenced array -- +Result: string(3) "one" + +$new_array: +array(3) { + [0]=> + &array(1) { + [0]=> + string(3) "two" + } + [1]=> + int(1) + [2]=> + string(3) "two" +} + +$copied_array +array(1) { + [0]=> + string(3) "two" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation7.phpt b/ext/standard/tests/array/array_shift_variation7.phpt new file mode 100644 index 000000000..9367cacbc --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation7.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_shift() function : usage variations - position of internal pointer +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test that the internal pointer is reset after calling array_shift() + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack = array ('one' => 'un', 'two' => 'deux'); + +echo "\n-- Call array_shift() --\n"; +var_dump($result = array_shift($stack)); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Call array_shift() -- +string(2) "un" + +-- Position of Internal Pointer in Passed Array: -- +two => deux +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation8.phpt b/ext/standard/tests/array/array_shift_variation8.phpt new file mode 100644 index 000000000..717d98fad --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation8.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_shift() function : usage variations - maintaining referenced elements +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * From a comment left by Traps on 09-Jul-2007 on the array_shift documentation page: + * For those that may be trying to use array_shift() with an array containing references + * (e.g. working with linked node trees), beware that array_shift() may not work as you expect: + * it will return a *copy* of the first element of the array, + * and not the element itself, so your reference will be lost. + * The solution is to reference the first element before removing it with array_shift(): + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +// using only array_shift: +echo "\n-- Reference result of array_shift: --\n"; +$a = 1; +$array = array(&$a); +$b =& array_shift($array); +$b = 2; +echo "a = $a, b = $b\n"; + +// solution: referencing the first element first: +echo "\n-- Reference first element before array_shift: --\n"; +$a = 1; +$array = array(&$a); +$b =& $array[0]; +array_shift($array); +$b = 2; +echo "a = $a, b = $b\n"; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Reference result of array_shift: -- + +Strict Standards: Only variables should be assigned by reference in %s on line %d +a = 1, b = 2 + +-- Reference first element before array_shift: -- +a = 2, b = 2 +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shuffle_basic.phpt b/ext/standard/tests/array/array_shuffle_basic.phpt new file mode 100644 index 000000000..fdf932605 --- /dev/null +++ b/ext/standard/tests/array/array_shuffle_basic.phpt @@ -0,0 +1,99 @@ +--TEST-- +array_shuffle(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto bool shuffle ( array &$array ) +* Function is implemented in ext/standard/array.c +*/ +$numbers = range(1, 20); +echo "*** testing array_shuffle \n"; +$a = array(); +var_dump(shuffle($a)); +var_dump($a); +$a = array(1); +var_dump(shuffle($a)); +var_dump($a); +$a = array(2 => 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array("a" => 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array(array(1, 2, 3)); +var_dump(shuffle($a)); +var_dump($a); +$a = array(1, 1, 1, 1); +var_dump(shuffle($a)); +var_dump($a); +$arr1 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +$arr2 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +shuffle($arr1); +echo "this should be 0->...." . count(array_diff($arr1, $arr2)) . "\n"; +echo "this should be 4->...." . count(array_intersect($arr1, $arr2)) . "\n"; +$bigarray = range(1, 400); +shuffle($bigarray); +echo "this should be 400->...." . count($bigarray) . "\n"; +echo "*** testing pass by reference \n"; +$original = $bigarray; +shuffle($bigarray); +$diffarray = array_diff_assoc($original, $bigarray); +if (count($diffarray) < 350) { + // with 400 entries, the probability that 50 entries or more get the same + // key-> value association should be so close to zero it wont happen in the lifetime of the + // universe. + echo "shuffled array seems to be similar to original\n"; + var_dump($original); + var_dump($bigarray); +} else { + echo "test passed \n"; +} +?> +--EXPECT-- +*** testing array_shuffle +bool(true) +array(0) { +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) +} +this should be 0->....0 +this should be 4->....4 +this should be 400->....400 +*** testing pass by reference +test passed
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_basic.phpt b/ext/standard/tests/array/array_slice_basic.phpt new file mode 100644 index 000000000..a4cbe4675 --- /dev/null +++ b/ext/standard/tests/array/array_slice_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_slice() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_slice() + */ + +echo "*** Testing array_slice() : basic functionality ***\n"; + + +$input = array('one' => 1, 'two' => 2, 3, 23 => 4); +$offset = 2; +$length = 2; +$preserve_keys = true; + +// Calling array_slice() with all possible arguments +echo "\n-- All arguments --\n"; +var_dump( array_slice($input, $offset, $length, $preserve_keys) ); + +// Calling array_slice() with mandatory arguments +echo "\n-- Mandatory arguments --\n"; +var_dump( array_slice($input, $offset) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : basic functionality *** + +-- All arguments -- +array(2) { + [0]=> + int(3) + [23]=> + int(4) +} + +-- Mandatory arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_error.phpt b/ext/standard/tests/array/array_slice_error.phpt new file mode 100644 index 000000000..0e8f1c757 --- /dev/null +++ b/ext/standard/tests/array/array_slice_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_slice() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass an incorrect number of arguments to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : error conditions ***\n"; + +//Test array_slice with one more than the expected number of arguments +echo "\n-- Testing array_slice() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$offset = 10; +$length = 10; +$preserve_keys = true; +$extra_arg = 10; +var_dump( array_slice($input, $offset, $length, $preserve_keys, $extra_arg) ); + +// Testing array_slice with one less than the expected number of arguments +echo "\n-- Testing array_slice() function with less than expected no. of arguments --\n"; +var_dump( array_slice($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_slice() : error conditions *** + +-- Testing array_slice() function with more than expected no. of arguments -- + +Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d +NULL + +-- Testing array_slice() function with less than expected no. of arguments -- + +Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation1.phpt b/ext/standard/tests/array/array_slice_variation1.phpt new file mode 100644 index 000000000..4c7a148c8 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation1.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different arguments as $input argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$offset = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input, $offset) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_slice() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation10.phpt b/ext/standard/tests/array/array_slice_variation10.phpt new file mode 100644 index 000000000..85c521d6d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation10.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_slice() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Check position of internal array pointer after calling array_slice() + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero'); + +echo "\n-- Call array_slice() --\n"; +var_dump($result = array_slice($input, 2)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Call array_slice() -- +array(2) { + [0]=> + string(12) "twenty-three" + [1]=> + string(4) "zero" +} +-- Position of Internal Pointer in Result: -- +0 => twenty-three + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation2.phpt b/ext/standard/tests/array/array_slice_variation2.phpt new file mode 100644 index 000000000..d293ce58d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation2.phpt @@ -0,0 +1,309 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $offset arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $offset argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 'three' => 3, 4); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $offset argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 2 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 3 -- +array(0) { +} + +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 5 -- +array(0) { +} + +-- Iteration 6 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 7 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 8 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 9 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 10 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 11 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 12 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 13 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 14 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 15 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 22 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 23 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation3.phpt b/ext/standard/tests/array/array_slice_variation3.phpt new file mode 100644 index 000000000..0aafa645e --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation3.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $length arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $length argument to array_slice to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 'three' => 3, 4); +$offset = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $length argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $offset, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(0) { +} + +-- Iteration 2 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 3 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 4 -- +array(0) { +} + +-- Iteration 5 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 6 -- +array(0) { +} + +-- Iteration 7 -- +array(0) { +} + +-- Iteration 8 -- +array(0) { +} + +-- Iteration 9 -- +array(0) { +} + +-- Iteration 10 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 11 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 12 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 13 -- +array(0) { +} + +-- Iteration 14 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 15 -- +array(0) { +} + +-- Iteration 16 -- +array(0) { +} + +-- Iteration 17 -- +array(0) { +} + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- +array(0) { +} + +-- Iteration 20 -- +array(0) { +} + +-- Iteration 21 -- +array(0) { +} + +-- Iteration 22 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 23 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation4.phpt b/ext/standard/tests/array/array_slice_variation4.phpt new file mode 100644 index 000000000..f093d2db8 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation4.phpt @@ -0,0 +1,327 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $preserve_keys arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $preserve_keys argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 99 => 3, 4); +$offset = 0; +$length = 3; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $preserve_keys argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $offset, $length, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 2 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 3 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 4 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 5 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 6 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 7 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 8 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 15 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 16 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 17 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 4 to be boolean, array given in %s on line %d +NULL + +-- Iteration 19 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 20 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 21 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 4 to be boolean, object given in %s on line %d +NULL + +-- Iteration 23 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 24 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation5.phpt b/ext/standard/tests/array/array_slice_variation5.phpt new file mode 100644 index 000000000..ed5c82f18 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation5.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different integers as $offset argument +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different integers as $offset argument to test how array_slice() behaves + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); + +for ($i = -7; $i <= 7; $i++) { + echo "\n-- \$offset is $i --\n"; + var_dump(array_slice($input, $i)); +} +echo "\n-- \$offset is maximum integer value --\n"; +var_dump(array_slice($input, PHP_INT_MAX)); + +echo "\n-- \$offset is minimum integer value --\n"; +var_dump(array_slice($input, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $offset is -7 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -6 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -5 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -3 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -2 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -1 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 0 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 1 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 2 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 3 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 4 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 5 -- +array(0) { +} + +-- $offset is 6 -- +array(0) { +} + +-- $offset is 7 -- +array(0) { +} + +-- $offset is maximum integer value -- +array(0) { +} + +-- $offset is minimum integer value -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation6.phpt b/ext/standard/tests/array/array_slice_variation6.phpt new file mode 100644 index 000000000..e210b4dd2 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation6.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test array_slice() function : usage variations - pass different int values as $length arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different integer values as $length argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); +$offset = 1; + +for ($i = -6; $i <= 6; $i++) { + echo "\n-- \$length is $i --\n"; + var_dump(array_slice($input, $offset, $i)); +} +echo "\n-- \$length is maximum integer value --\n"; +var_dump(array_slice($input, $offset, PHP_INT_MAX)); + +echo "\n-- \$length is minimum integer value --\n"; +var_dump(array_slice($input, $offset, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $length is -6 -- +array(0) { +} + +-- $length is -5 -- +array(0) { +} + +-- $length is -4 -- +array(0) { +} + +-- $length is -3 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is -2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is -1 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 0 -- +array(0) { +} + +-- $length is 1 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is 2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is 3 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 5 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 6 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is maximum integer value -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is minimum integer value -- +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation7.phpt b/ext/standard/tests/array/array_slice_variation7.phpt new file mode 100644 index 000000000..abf517d1f --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation7.phpt @@ -0,0 +1,300 @@ +--TEST-- +Test array_slice() function : usage variations - different data types as keys in an array +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as keys in an array to array_slice() + * to test how $preserve_keys treats them + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$offset = 0; +$length = 10; // to ensure all elements are displayed + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator : key type is $type --\n"; + echo "\$preserve_keys = TRUE\n"; + var_dump( array_slice($input, $offset, $length, true) ); + echo "\$preserve_keys = FALSE\n"; + var_dump( array_slice($input, $offset, $length, false) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 : key type is int -- +$preserve_keys = TRUE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} +$preserve_keys = FALSE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2 : key type is float -- +$preserve_keys = TRUE +array(3) { + [10]=> + string(8) "positive" + [-10]=> + string(8) "negative" + [0]=> + string(4) "half" +} +$preserve_keys = FALSE +array(3) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3 : key type is extreme floats -- +$preserve_keys = TRUE +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4 : key type is null uppercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 1" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 : key type is null lowercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 2" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 : key type is bool lowercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7 : key type is bool uppercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8 : key type is empty double quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptyd" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 : key type is empty single quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptys" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 : key type is string -- +$preserve_keys = TRUE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} +$preserve_keys = FALSE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11 : key type is undefined -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(9) "undefined" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 : key type is unset -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(5) "unset" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation8.phpt b/ext/standard/tests/array/array_slice_variation8.phpt new file mode 100644 index 000000000..aece410c0 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation8.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_slice() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test array_slice when passed + * 1. a two-dimensional array as $input argument + * 2. a sub-array as $input argument + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('zero', 'one', array('zero', 'un', 'deux'), 9 => 'nine'); + +echo "\n-- Slice a two-dimensional array --\n"; +var_dump(array_slice($input, 1, 3)); + +echo "\n-- \$input is a sub-array --\n"; +var_dump(array_slice($input[2], 1, 2)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Slice a two-dimensional array -- +array(3) { + [0]=> + string(3) "one" + [1]=> + array(3) { + [0]=> + string(4) "zero" + [1]=> + string(2) "un" + [2]=> + string(4) "deux" + } + [2]=> + string(4) "nine" +} + +-- $input is a sub-array -- +array(2) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation9.phpt b/ext/standard/tests/array/array_slice_variation9.phpt new file mode 100644 index 000000000..030d4bd73 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation9.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_slice() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test array_slice() when: + * 1. Passed an array of referenced variables + * 2. $input argument is passed by reference + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$val1 = 'one'; +$val2 = 'two'; +$val3 = 'three'; + +echo "\n-- Array of referenced variables (\$preserve_keys = default) --\n"; +$input = array(3 => &$val1, 2 => &$val2, 1 => &$val3); +var_dump(array_slice($input, 1, 2)); + +echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; +$val2 = 'hello, world'; +var_dump(array_slice($input, 1, 2, true)); + +echo "\n-- Pass array by reference --\n"; +$new_input = array (1, 2, 3); +var_dump(array_slice(&$new_input, 1)); +echo "-- Check passed array: --\n"; +var_dump($new_input); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Array of referenced variables ($preserve_keys = default) -- +array(2) { + [0]=> + &string(3) "two" + [1]=> + &string(5) "three" +} +-- Change $val2 ($preserve_keys = TRUE) -- +array(2) { + [2]=> + &string(12) "hello, world" + [1]=> + &string(5) "three" +} + +-- Pass array by reference -- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +-- Check passed array: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_sum_basic.phpt b/ext/standard/tests/array/array_sum_basic.phpt new file mode 100644 index 000000000..c178853d7 --- /dev/null +++ b/ext/standard/tests/array/array_sum_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_sum() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : basic functionality ***\n"; + +// array with integer values +$input = array(1, 2, 3, 4, 5); +echo "-- array_sum() with integer array entries --\n"; +var_dump( array_sum($input) ); + +// array with float values +$input = array(1.0, 2.2, 3.4, 4.6); +echo "-- array_sum() with float array entries --\n"; +var_dump( array_sum($input) ); + +// array with integer and float values +$input = array(1, 2.3, 4, 0.6, 10); +echo "-- array_sum() with integer/float array entries --\n"; +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : basic functionality *** +-- array_sum() with integer array entries -- +int(15) +-- array_sum() with float array entries -- +float(11.2) +-- array_sum() with integer/float array entries -- +float(17.9) +Done diff --git a/ext/standard/tests/array/array_sum_error.phpt b/ext/standard/tests/array/array_sum_error.phpt new file mode 100644 index 000000000..ffa7e5b6d --- /dev/null +++ b/ext/standard/tests/array/array_sum_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_sum() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_sum() function with zero arguments --\n"; +var_dump( array_sum() ); + +// One more than the expected number of arguments +echo "-- Testing array_sum() function with more than expected no. of arguments --\n"; +$input = array(1, 2, 3, 4); +$extra_arg = 10; +var_dump( array_sum($input, $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : error conditions *** +-- Testing array_sum() function with zero arguments -- + +Warning: Wrong parameter count for array_sum() in %s on line %d +NULL +-- Testing array_sum() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_sum() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation1.phpt b/ext/standard/tests/array/array_sum_variation1.phpt new file mode 100644 index 000000000..df6238670 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation1.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_sum() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Passing different scalar/nonscalar values as 'input' argument to array_sum() +*/ + +echo "*** Testing array_sum() : unexpected values for 'input' ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Class definition +class MyClass +{ + public function __toString() + { + return "object"; + } +} + +// different scalar/non scalar values for 'input' argument +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new MyClass(), + + // resource data +/*21*/ $fp = fopen(__FILE__,'r'), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of the array for input +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_sum($input_values[$count]) ); +}; + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation2.phpt b/ext/standard/tests/array/array_sum_variation2.phpt new file mode 100644 index 000000000..a697a15fc --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_sum() function : usage variations - array with different integer value +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with different types of integer arrays containing data of following type: +* integer, octal, hexadecimal, maximum and minimum integer values & mixed of all integers +*/ + +echo "*** Testing array_sum() : different integer array ***\n"; + +// Int array +$int_values = array(3, 2, 100, 150, 25, 350, 0, -3, -1200); +echo "-- Sum of Integer array --\n"; +var_dump( array_sum($int_values) ); + +// Octal array +$octal_values = array(056, 023, 090, 015, -045, 01, -078); +echo "-- Sum of Octal array --\n"; +var_dump( array_sum($octal_values) ); + +// Hexadecimal array +$hex_values = array(0xAE, 0x2B, 0X10, -0xCF, 0X12, -0XF2); +echo "-- Sum of Hex array --\n"; +var_dump( array_sum($hex_values) ); + +// Mixed values int, octal & hex +$mixed_int_value = array(2, 5, -1, 054, 0X3E, 0, -014, -0x2A); +echo "-- Sum of mixed integer values --\n"; +var_dump( array_sum($mixed_int_value) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : different integer array *** +-- Sum of Integer array -- +int(-573) +-- Sum of Octal array -- +int(35) +-- Sum of Hex array -- +int(-198) +-- Sum of mixed integer values -- +int(58) +Done diff --git a/ext/standard/tests/array/array_sum_variation3.phpt b/ext/standard/tests/array/array_sum_variation3.phpt new file mode 100644 index 000000000..9d32c2c38 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation3.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_sum() function : usage variations - array with different float values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* + * sum of array containing different float values +*/ + +echo "*** Testing array_sum() : array with different float values ***\n"; + +// Simple float array +$float_input = array( 1.1, 2.3, 0.0, 0.5, -2.3, -0.8, .5); +echo "-- simple float array --\n"; +var_dump( array_sum($float_input) ); + +// float array with scientific notations +$float_input = array( 1.2e2, 23.4e3, -4.1e2, 0.2e2, 2.1e-2, .5e3); +echo "-- float array with scientific notations e and E --\n"; +var_dump( array_sum($float_input) ); +$float_input = array( 1.2E2, 23.4E3, -4.1E2, 0.2E2, 2.1E-2, .5E3); +var_dump( array_sum($float_input) ); + +// Mixed float array +$float_input = array( + 1.2, + 0.5 + -5.8, + 6.334, + -0.65, + 1.2e3, + -2.3e2, + 5.56E3, + -3.82E-2 +); +echo "-- Mixed float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with different float values *** +-- simple float array -- +float(1.3) +-- float array with scientific notations e and E -- +float(23630.021) +float(23630.021) +-- Mixed float array -- +float(6531.5458) +Done diff --git a/ext/standard/tests/array/array_sum_variation4.phpt b/ext/standard/tests/array/array_sum_variation4.phpt new file mode 100644 index 000000000..4959deee7 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation4.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_sum() function : usage variations - array with duplicate values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Checking array_sum() with integer and float array containing duplicate values +*/ + +echo "*** Testing array_sum() : array with duplicate values ***\n"; + +// integer array with duplicate values +$int_input = array( 2, 5, 7, 5, 0, -4, 2, 100); +echo "-- With integer array --\n"; +var_dump( array_sum($int_input) ); + +// float array with duplicate values +$float_input = array( 2.3, 1.9, -4.1, 0.5, 1.9, -4.1, 3.6, 0.5); +echo "-- With float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with duplicate values *** +-- With integer array -- +int(117) +-- With float array -- +float(2.5) +Done diff --git a/ext/standard/tests/array/array_sum_variation5.phpt b/ext/standard/tests/array/array_sum_variation5.phpt new file mode 100644 index 000000000..9068c4565 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation5.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_sum() function : usage variations - array with reference variables as elements +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with 'input' having reference variables as elements +*/ + +echo "*** Testing array_sum() : array with elements as reference ***\n"; + +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// input array containing elements as reference variables +$input = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with elements as reference *** +int(305) +Done diff --git a/ext/standard/tests/array/array_sum_variation6.phpt b/ext/standard/tests/array/array_sum_variation6.phpt new file mode 100644 index 000000000..ba67cfd49 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation6.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_sum() function : usage variations - associative array +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with associative array as 'input' argument +*/ + +echo "*** Testing array_sum() : with associative array ***\n"; + +// array with numeric keys +$input = array(0 => 1, 1 => 10, 2 => 0, 3 => -2, 4 => 23.56); +echo "-- with numeric keys --\n"; +var_dump( array_sum($input) ); + +// array with string keys +$input = array('a' => 20, "b" => 50, 'c' => 0, 'd' => -30, "e" => 100); +echo "-- with string keys --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : with associative array *** +-- with numeric keys -- +float(32.56) +-- with string keys -- +int(140) +Done diff --git a/ext/standard/tests/array/array_sum_variation7.phpt b/ext/standard/tests/array/array_sum_variation7.phpt new file mode 100644 index 000000000..d30987535 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation7.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test array_sum() function : usage variations - 'input' array with unexpected values as array element +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with array having other than numeric entries +* strings, bool, null, subarrays & objects +*/ + +echo "*** Testing array_sum() : array with unexpected entries ***\n"; + +// empty array +$input = array(); +echo "-- empty array --\n"; +var_dump( array_sum($input) ); + +// string array +$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange'); +echo "-- array with string values --\n"; +var_dump( array_sum($input) ); + +// bool array +$input = array( true, true, false, true, false); +echo "-- array with bool values --\n"; +var_dump( array_sum($input) ); + +// array with null entry +$input = array(null, NULL); +echo "-- array with null values --\n"; +var_dump( array_sum($input) ); + +// array with subarray +$input = array( + array(1, 2), + array(), + array(0) +); +echo "-- array with subarrays --\n"; +var_dump( array_sum($input) ); + +class MyClass +{ + public $value; + public function __construct($value) + { + $this->value = $value; + } +} +// array of objects +$input = array( + new MyClass(2), + new MyClass(5), + new MyClass(10), + new MyClass(0) +); +echo "-- array with object values --\n"; +var_dump( array_sum($input) ); + +// Mixed values +$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array())); +echo "-- array with mixed values --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with unexpected entries *** +-- empty array -- +int(0) +-- array with string values -- +int(0) +-- array with bool values -- +int(3) +-- array with null values -- +int(0) +-- array with subarrays -- +int(0) +-- array with object values -- +int(0) +-- array with mixed values -- +float(14) +Done diff --git a/ext/standard/tests/array/array_udiff_assoc_basic.phpt b/ext/standard/tests/array/array_udiff_assoc_basic.phpt new file mode 100644 index 000000000..9670eef5d --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_udiff_assoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_basic.phpt b/ext/standard/tests/array/array_udiff_basic.phpt new file mode 100644 index 000000000..636e3abf3 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_udiff():Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_uassoc_basic.phpt b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt new file mode 100644 index 000000000..0e6d6154d --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +array_udiff_uassoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_assoc_basic.phpt b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt new file mode 100644 index 000000000..644109ab6 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_uintersect_assoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_basic.phpt b/ext/standard/tests/array/array_uintersect_basic.phpt new file mode 100644 index 000000000..1c80a959b --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_uintersect(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt new file mode 100644 index 000000000..a0bd055e8 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +array_uintersect_uassoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_unique_basic.phpt b/ext/standard/tests/array/array_unique_basic.phpt new file mode 100644 index 000000000..58d3acf1b --- /dev/null +++ b/ext/standard/tests/array/array_unique_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_unique() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_unique() : basic functionality ***\n"; + +// array with default keys +$input = array(1, 2, "1", '2'); +var_dump( array_unique($input) ); + +// associative array +$input = array("1" => "one", 1 => "one", 2 => "two", '2' => "two"); +var_dump( array_unique($input) ); + +// mixed array +$input = array("1" => "one", "two", "one", 2 => "two", "three"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : basic functionality *** +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [4]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_error.phpt b/ext/standard/tests/array/array_unique_error.phpt new file mode 100644 index 000000000..59d458a2a --- /dev/null +++ b/ext/standard/tests/array/array_unique_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_unique() function : error conditions +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_unique() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_unique() function with zero arguments --\n"; +var_dump( array_unique() ); + +//Test array_unique with one more than the expected number of arguments +echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$extra_arg = 10; +var_dump( array_unique($input, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : error conditions *** + +-- Testing array_unique() function with zero arguments -- + +Warning: Wrong parameter count for array_unique() in %s on line %d +NULL + +-- Testing array_unique() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_unique() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unique_variation1.phpt b/ext/standard/tests/array/array_unique_variation1.phpt new file mode 100644 index 000000000..3a9ae10dd --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation1.phpt @@ -0,0 +1,194 @@ +--TEST-- +Test array_unique() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'input' argument of array_unique() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n"; + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs and check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : Passing non array values to $input argument *** +-- Iteration 1 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- +array(0) { +} +-- Iteration 22 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_unique_variation2.phpt b/ext/standard/tests/array/array_unique_variation2.phpt new file mode 100644 index 000000000..5cdb43a8e --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation2.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test array_unique() function : usage variations - different arrays for 'input' argument +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $input argument and testing whether +* array_unique() behaves in an expected way. +*/ + +echo "*** Testing array_unique() : Passing different arrays to \$input argument ***\n"; + +/* Different heredoc strings passed as argument to arrays */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $input argument +$inputs = array ( +/*1*/ array(1, 2, 2, 1), // with default keys and numeric values + array(1.1, 2.2, 1.1), // with default keys & float values + array(false, true, false), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL, null), // with NULL + array("a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $blank_line), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 5 => 10), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "10" => "ten"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), +/*18*/ array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [0]=> + NULL +} +-- Iteration 6 -- +array(4) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [4]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [4]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(87) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iteration 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(3) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) +} +-- Iteration 12 -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL +} +-- Iteration 15 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [1]=> + string(0) "" + [6]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation3.phpt b/ext/standard/tests/array/array_unique_variation3.phpt new file mode 100644 index 000000000..49103c815 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation3.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing different + * associative arrays having different keys to $input argument. +*/ + +echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $input argument +$inputs = array ( +/*1*/ // arrays with integer keys + array(0 => "0", 1 => "0"), + array(1 => "1", 2 => "2", 3 => 1, 4 => "4"), + + // arrays with float keys +/*3*/ array(2.3333 => "float", 44.44 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"), + + // arrays with string keys +/*5*/ array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => "string", "string"), + + // array with object, unset variable and resource variable +/*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. keys passed to $input argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 2 -- +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [4]=> + string(1) "4" +} +-- Iteration 3 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 4 -- +array(3) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [3333333]=> + string(2) "f4" +} +-- Iteration 5 -- +array(3) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iteration 6 -- +array(3) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(2) { + [""]=> + string(5) "hello" + [0]=> + int(11) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation4.phpt b/ext/standard/tests/array/array_unique_variation4.phpt new file mode 100644 index 000000000..a1fc13e94 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation4.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing different + * associative arrays having different values to $input argument. +*/ + +echo "*** Testing array_unique() : assoc. array with diff. values to \$input argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// associative arrays with different values +$inputs = array ( + // arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + + // arrays with string values +/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. values to $input argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 2 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 3 -- +array(1) { + ["float1"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) +} +-- Iteration 5 -- +array(3) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" +} +-- Iteration 6 -- +array(3) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" +} +-- Iteration 7 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation5.phpt b/ext/standard/tests/array/array_unique_variation5.phpt new file mode 100644 index 000000000..5e3f7c36d --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation5.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - array with duplicate keys +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * array having duplicate keys as values. +*/ + +echo "*** Testing array_unique() : array with duplicate keys for \$input argument ***\n"; + +// initialize the array having duplicate keys +$input = array( 1 => "one", 2 => "two", 2 => "2", 3 => "three", 1 => "1", "1", "2"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with duplicate keys for $input argument *** +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation6.phpt b/ext/standard/tests/array/array_unique_variation6.phpt new file mode 100644 index 000000000..fd8b226fa --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation6.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_unique() function : usage variations - array with reference variables +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * array having reference variables as values. +*/ + +echo "*** Testing array_unique() : array with reference variables for \$input argument ***\n"; + +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// input array containing elements as reference variables +$input = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + 5 => $value4 +); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with reference variables for $input argument *** +array(2) { + [0]=> + int(0) + [1]=> + &string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation7.phpt b/ext/standard/tests/array/array_unique_variation7.phpt new file mode 100644 index 000000000..e998a73c6 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation7.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing an array having binary values. +*/ + +echo "*** Testing array_unique() : array with binary data for \$input argument ***\n"; + +// array with binary values +$input = array( b"1", b"hello", "world", "str1" => "hello", "str2" => "world"); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with binary data for $input argument *** +array(3) { + [0]=> + string(1) "1" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation8.phpt b/ext/standard/tests/array/array_unique_variation8.phpt new file mode 100644 index 000000000..ae6e8bb5c --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation8.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_unique() function : usage variations - two dimensional arrays +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * two dimensional arrays for $input argument. +*/ + +echo "*** Testing array_unique() : two dimensional array for \$input argument ***\n"; + +// initialize the 2-d array +$input = array( + array(1, 2, 3, 1), + array("hello", "world", "str1" => "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : two dimensional array for $input argument *** +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation5.phpt b/ext/standard/tests/array/array_unshift_variation5.phpt index ff6bf28f8..7f083694a 100644 --- a/ext/standard/tests/array/array_unshift_variation5.phpt +++ b/ext/standard/tests/array/array_unshift_variation5.phpt @@ -1,5 +1,7 @@ --TEST-- Test array_unshift() function : usage variations - assoc. array with diff values for 'array' argument +--INI-- +precision=12 --FILE-- <?php /* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) @@ -209,7 +211,7 @@ array(5) { [1]=> float(4.8999992284) ["f4"]=> - float(33333333.333333) + float(33333333.3333) } int(7) array(7) { @@ -226,7 +228,7 @@ array(7) { [3]=> float(4.8999992284) ["f4"]=> - float(33333333.333333) + float(33333333.3333) } -- Iteration 7 -- int(5) diff --git a/ext/standard/tests/array/array_values_basic.phpt b/ext/standard/tests/array/array_values_basic.phpt new file mode 100644 index 000000000..9cbdf07b8 --- /dev/null +++ b/ext/standard/tests/array/array_values_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_values() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_values() + */ + +echo "*** Testing array_values() : basic functionality ***\n"; + + +// Initialise all required variables +$input = array('zero', 'one', 'two', 'three' => 3, 10 => 'ten'); + +// Calling array_values() with all possible arguments +var_dump( array_values($input) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : basic functionality *** +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(3) + [4]=> + string(3) "ten" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation1.phpt b/ext/standard/tests/array/array_values_variation1.phpt new file mode 100644 index 000000000..efe08c72b --- /dev/null +++ b/ext/standard/tests/array/array_values_variation1.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test array_values() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $input argument to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_values($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation2.phpt b/ext/standard/tests/array/array_values_variation2.phpt new file mode 100644 index 000000000..c7e9ad3f7 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation2.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test array_values() function : usage variations - arrays of different data types +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types as $input argument to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_values($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4: bool data -- +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(0) { +} + +-- Iteration 7: string data -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10: unset data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 11: resource data -- +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation3.phpt b/ext/standard/tests/array/array_values_variation3.phpt new file mode 100644 index 000000000..5c74c0d47 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation3.phpt @@ -0,0 +1,200 @@ +--TEST-- +Test array_values() function : usage variations - array keys different data types +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where the keys are different data types as $input argument + * to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_values($input) ); + $iterator++; +}; +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: float data -- +array(3) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3: extreme floats data -- +array(2) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4: null uppercase data -- +array(1) { + [0]=> + string(6) "null 1" +} + +-- Iteration 5: null lowercase data -- +array(1) { + [0]=> + string(6) "null 2" +} + +-- Iteration 6: bool lowercase data -- +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7: bool uppercase data -- +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8: empty double quotes data -- +array(1) { + [0]=> + string(6) "emptyd" +} + +-- Iteration 9: empty single quotes data -- +array(1) { + [0]=> + string(6) "emptys" +} + +-- Iteration 10: string data -- +array(3) { + [0]=> + string(7) "stringd" + [1]=> + string(7) "strings" + [2]=> + string(7) "stringh" +} + +-- Iteration 11: undefined data -- +array(1) { + [0]=> + string(9) "undefined" +} + +-- Iteration 12: unset data -- +array(1) { + [0]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation4.phpt b/ext/standard/tests/array/array_values_variation4.phpt new file mode 100644 index 000000000..199d23dc9 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation4.phpt @@ -0,0 +1,118 @@ +--TEST-- +Test array_values() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test array_values when: + * 1. Passed a two-dimensional array as $input argument + * 2. Passed a sub-array as $input argument + * 3. Passed an infinitely recursive multi-dimensional array + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$input = array ('zero' => 'zero', 'un' => 'one', 'sub' => array (1, 2, 3)); + +echo "\n-- Array values of a two-dimensional array --\n"; +var_dump(array_values($input)); + +echo "\n-- Array values of a sub-array --\n"; +var_dump(array_values($input['sub'])); + +// get an infinitely recursive array +$input[] = &$input; +echo "\n-- Array values of an infinitely recursive array --\n"; +var_dump(array_values($input)); + +// break cycle +$input[0] = null; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Array values of a two-dimensional array -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Array values of a sub-array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Array values of an infinitely recursive array -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + &array(4) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(3) "one" + ["sub"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + &array(4) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(3) "one" + ["sub"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + *RECURSION* + } + } +} +Done diff --git a/ext/standard/tests/array/array_values_variation5.phpt b/ext/standard/tests/array/array_values_variation5.phpt new file mode 100644 index 000000000..d65b4674d --- /dev/null +++ b/ext/standard/tests/array/array_values_variation5.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_values() function : usage variations - internal array pointer +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test the position of the internal array pointer after a call to array_values + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_values() --\n"; +var_dump($result = array_values($input)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Call array_values() -- +array(3) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" + [2]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +0 => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation6.phpt b/ext/standard/tests/array/array_values_variation6.phpt new file mode 100644 index 000000000..e56515076 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation6.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_values() function : usage variations - Referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test array_values() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array by reference + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$val1 = 'one'; +$val2 = 'two'; +$val3 = 'three'; + +echo "\n-- \$input is an array made up of referenced variables: --\n"; +$input = array(&$val1, &$val2, &$val3); +var_dump($result1 = array_values($input)); + +echo "Change \$val2 and check result of array_values():\n"; +$val2 = 'deux'; +var_dump($result1); + +echo "\n-- Pass \$input argument by reference --\n"; +$array = array(1, 2, 3); +var_dump($result2 = array_values(&$array)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- $input is an array made up of referenced variables: -- +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(3) "two" + [2]=> + &string(5) "three" +} +Change $val2 and check result of array_values(): +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(4) "deux" + [2]=> + &string(5) "three" +} + +-- Pass $input argument by reference -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_values_variation7.phpt b/ext/standard/tests/array/array_values_variation7.phpt new file mode 100644 index 000000000..b71306456 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation7.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_values() function : usage variations - Internal order check +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Check that array_values is re-assigning keys according to the internal order of the array, + * and is not dependant on the \$input argument's keys + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +// populate array with 'default' keys in reverse order +$input = array(3 => 'three', 2 => 'two', 1 => 'one', 0 => 'zero'); + +echo "\n-- \$input argument: --\n"; +var_dump($input); + +echo "\n-- Result of array_values() --\n"; +var_dump(array_values($input)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- $input argument: -- +array(4) { + [3]=> + string(5) "three" + [2]=> + string(3) "two" + [1]=> + string(3) "one" + [0]=> + string(4) "zero" +} + +-- Result of array_values() -- +array(4) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + string(4) "zero" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_walk_basic1.phpt b/ext/standard/tests/array/array_walk_basic1.phpt new file mode 100644 index 000000000..34e8e88c7 --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk() function : basic functionality - regular array +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk() : basic functionality ***\n"; + +// regular array +$fruits = array("lemon", "orange", "banana", "apple"); + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - item in key/item pair + * key - key in key/item pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} +function with_userdata($item, $key, $user_data) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($user_data); // user supplied data + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk() with default parameters to show array contents --\n"; +var_dump( array_walk($fruits, 'test_print')); + +echo "-- Using array_walk() with all parameters --\n"; +var_dump( array_walk($fruits, 'with_userdata', "Added")); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(1) + +string(6) "banana" +int(2) + +string(5) "apple" +int(3) + +bool(true) +-- Using array_walk() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(1) +string(5) "Added" + +string(6) "banana" +int(2) +string(5) "Added" + +string(5) "apple" +int(3) +string(5) "Added" + +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_walk_basic2.phpt b/ext/standard/tests/array/array_walk_basic2.phpt new file mode 100644 index 000000000..e856b580b --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk() function : basic functionality - associative array +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk() : basic functionality ***\n"; + +// associative array +$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); + +// User defined callback functions +/* Prototype : test_alter(mixed $item, mixed $key, string $prefix) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * prefix - string to be added + * Description : alters the array values by appending prefix string + */ +function test_alter(&$item, $key, $prefix) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($prefix); // additional agument passed to callback function + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk with default parameters to show array contents --\n"; +var_dump(array_walk($fruits, 'test_print')); + +echo "-- Using array_walk with one optional parameter to modify contents --\n"; +var_dump (array_walk($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk with default parameters to show modified array contents --\n"; +var_dump (array_walk($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk with default parameters to show array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +-- Using array_walk with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "d" +string(5) "fruit" + +string(6) "orange" +string(1) "a" +string(5) "fruit" + +string(6) "banana" +string(1) "b" +string(5) "fruit" + +string(5) "apple" +string(1) "c" +string(5) "fruit" + +bool(true) +-- Using array_walk with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_error1.phpt b/ext/standard/tests/array/array_walk_error1.phpt new file mode 100644 index 000000000..014885a94 --- /dev/null +++ b/ext/standard/tests/array/array_walk_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_walk() function : error conditions +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +$input = array(1, 2); + +/* Prototype : callback(mixed value, mixed key, mixed user_data) + * Parameters : value - value in key/value pair + * key - key in key/value pair + * user_data - extra parameter + */ +function callback ($value, $key, $user_data) { + echo "\ncallback() invoked \n"; +} + +echo "*** Testing array_walk() : error conditions ***\n"; + +echo "-- Testing array_walk() function with zero arguments --\n"; +var_dump( array_walk() ); + +echo "-- Testing array_walk() function with one argument --\n"; +var_dump( array_walk($input) ); + +echo "-- Testing array_walk() function with non existent callback function --\n"; +var_dump( array_walk($input, "non_existent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk() : error conditions *** +-- Testing array_walk() function with zero arguments -- + +Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk() function with one argument -- + +Warning: array_walk() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk() function with non existent callback function -- + +Warning: array_walk(): Unable to call non_existent() - function does not exist in %s on line %d +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_error2.phpt b/ext/standard/tests/array/array_walk_error2.phpt new file mode 100644 index 000000000..654637ab5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk() function : error conditions - callback parameters +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() by passing more number of parameters to callback function + */ +$input = array(1); + +function callback1($value, $key, $user_data ) { + echo "\ncallback1() invoked \n"; +} + +function callback2($value, $key, $user_data1, $user_data2) { + echo "\ncallback2() invoked \n"; +} +echo "*** Testing array_walk() : error conditions - callback parameters ***\n"; + +// expected: Missing argument Warning +var_dump( array_walk($input, "callback1") ); +var_dump( array_walk($input, "callback2", 4) ); + +// expected: Warning is supressed +var_dump( @array_walk($input, "callback1") ); +var_dump( @array_walk($input, "callback2", 4) ); + +echo "-- Testing array_walk() function with too many callback parameters --\n"; +var_dump( array_walk($input, "callback1", 20, 10) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk() : error conditions - callback parameters *** + +Warning: Missing argument 3 for callback1() in %s on line %d + +callback1() invoked +bool(true) + +Warning: Missing argument 4 for callback2() in %s on line %d + +callback2() invoked +bool(true) + +callback1() invoked +bool(true) + +callback2() invoked +bool(true) +-- Testing array_walk() function with too many callback parameters -- + +Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_object1.phpt b/ext/standard/tests/array/array_walk_object1.phpt Binary files differnew file mode 100644 index 000000000..632b651c0 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object1.phpt diff --git a/ext/standard/tests/array/array_walk_object2.phpt b/ext/standard/tests/array/array_walk_object2.phpt new file mode 100644 index 000000000..61d052975 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object2.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test array_walk() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_walk() with an array of objects +*/ + +echo "*** Testing array_walk() : array of objects ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ +function callback_private($value, $key, $addValue) +{ + echo "value : "; + var_dump($value->getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +// array containing objects of MyClass +$input = array ( + new MyClass(3), + new MyClass(10), + new MyClass(20), + new MyClass(-10) +); + +echo "-- For private member --\n"; +var_dump( array_walk($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(2) +value : int(-10) +key : int(3) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_basic1.phpt b/ext/standard/tests/array/array_walk_recursive_basic1.phpt new file mode 100644 index 000000000..df192b6a7 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - regular array +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk_recursive() : basic functionality ***\n"; + +// regular array +$fruits = array("lemon", array("orange", "banana"), array("apple")); + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - item in key/item pair + * key - key in key/item pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} +function with_userdata($item, $key, $user_data) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($user_data); // user supplied data + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk_recursive() with default parameters to show array contents --\n"; +var_dump( array_walk_recursive($fruits, 'test_print')); + +echo "-- Using array_walk_recursive() with all parameters --\n"; +var_dump( array_walk_recursive($fruits, 'with_userdata', "Added")); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(0) + +string(6) "banana" +int(1) + +string(5) "apple" +int(0) + +bool(true) +-- Using array_walk_recursive() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(0) +string(5) "Added" + +string(6) "banana" +int(1) +string(5) "Added" + +string(5) "apple" +int(0) +string(5) "Added" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_basic2.phpt b/ext/standard/tests/array/array_walk_recursive_basic2.phpt new file mode 100644 index 000000000..c71d92b45 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - associative array +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk_recursive() : basic functionality ***\n"; + +// associative array +$fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple")); + +// User defined callback functions +/* Prototype : test_alter(mixed $item, mixed $key, string $prefix) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * prefix - string to be added + * Description : alters the array values by appending prefix string + */ +function test_alter(&$item, $key, $prefix) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($prefix); // additional agument passed to callback function + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk_recursive with default parameters to show array contents --\n"; +var_dump(array_walk_recursive($fruits, 'test_print')); + +echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive with default parameters to show array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +-- Using array_walk_recursive with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "a" +string(5) "fruit" + +string(6) "orange" +string(1) "c" +string(5) "fruit" + +string(6) "banana" +string(1) "d" +string(5) "fruit" + +string(5) "apple" +string(1) "f" +string(5) "fruit" + +bool(true) +-- Using array_walk_recursive with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error1.phpt b/ext/standard/tests/array/array_walk_recursive_error1.phpt new file mode 100644 index 000000000..df7092c02 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_walk_recursive() function : error conditions +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +$input = array(1, 2); + +/* Prototype : callback(mixed value, mixed key, mixed user_data) + * Parameters : value - value in key/value pair + * key - key in key/value pair + * user_data - extra parameter + */ +function callback ($value, $key, $user_data) { + echo "\ncallback() invoked \n"; +} + +echo "*** Testing array_walk_recursive() : error conditions ***\n"; + +echo "-- Testing array_walk_recursive() function with zero arguments --\n"; +var_dump( array_walk_recursive() ); + +echo "-- Testing array_walk_recursive() function with one argument --\n"; +var_dump( array_walk_recursive($input) ); + +echo "-- Testing array_walk_recursive() function with non existent callback function --\n"; +var_dump( array_walk_recursive($input, "non_existent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions *** +-- Testing array_walk_recursive() function with zero arguments -- + +Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with one argument -- + +Warning: array_walk_recursive() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with non existent callback function -- + +Warning: array_walk_recursive(): Unable to call non_existent() - function does not exist in %s on line %d +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error2.phpt b/ext/standard/tests/array/array_walk_recursive_error2.phpt new file mode 100644 index 000000000..d628e9327 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk_recursive() function : error conditions - callback parameters +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() by passing more number of parameters to callback function + */ +$input = array(1); + +function callback1($value, $key, $user_data ) { + echo "\ncallback1() invoked \n"; +} + +function callback2($value, $key, $user_data1, $user_data2) { + echo "\ncallback2() invoked \n"; +} +echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n"; + +// expected: Missing argument Warning +var_dump( array_walk_recursive($input, "callback1") ); +var_dump( array_walk_recursive($input, "callback2", 4) ); + +// expected: Warning is supressed +var_dump( @array_walk_recursive($input, "callback1") ); +var_dump( @array_walk_recursive($input, "callback2", 4) ); + +echo "-- Testing array_walk_recursive() function with too many callback parameters --\n"; +var_dump( array_walk_recursive($input, "callback1", 20, 10) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions - callback parameters *** + +Warning: Missing argument 3 for callback1() in %s on line %d + +callback1() invoked +bool(true) + +Warning: Missing argument 4 for callback2() in %s on line %d + +callback2() invoked +bool(true) + +callback1() invoked +bool(true) + +callback2() invoked +bool(true) +-- Testing array_walk_recursive() function with too many callback parameters -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_object1.phpt b/ext/standard/tests/array/array_walk_recursive_object1.phpt Binary files differnew file mode 100644 index 000000000..30d03a70a --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_object1.phpt diff --git a/ext/standard/tests/array/array_walk_recursive_object2.phpt b/ext/standard/tests/array/array_walk_recursive_object2.phpt new file mode 100644 index 000000000..aa12fe869 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_object2.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test array_walk_recursive() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_walk_recursive() with an array of objects +*/ + +echo "*** Testing array_walk_recursive() : array of objects ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ +function callback_private($value, $key, $addValue) +{ + echo "value : "; + var_dump($value->getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +// array containing objects of MyClass +$input = array ( + array( + new MyClass(3), + new MyClass(10), + ), + new MyClass(20), + array(new MyClass(-10)) +); + +echo "-- For private member --\n"; +var_dump( array_walk_recursive($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk_recursive($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk_recursive($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(1) +value : int(-10) +key : int(0) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation1.phpt b/ext/standard/tests/array/array_walk_recursive_variation1.phpt new file mode 100644 index 000000000..2673df99a --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'input' argument +*/ + +echo "*** Testing array_walk_recursive() : unexpected values for 'input' argument ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values given in input array + * $key - keys given in input array + * Description : Function prints each element of an array with key + */ +function callback($value, $key) +{ + echo "key : "; + var_dump($key); + echo "value : "; + var_dump($value); +} + +// extra parameter passed to array_walk_recursive() +$user_data = 10; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// different scalar/nonscalar values to be used in place of an 'input' argument +$input_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/* 10*/ NULL, + null, + + // boolean data +/* 12*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 16*/ "", + '', + + // string data +/* 18*/ "string", + 'string', + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 22*/ @$unset_var, +); + + +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input_values[$count], "callback") ); + var_dump( array_walk_recursive($input_values[$count], "callback", $user_data) ); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation2.phpt b/ext/standard/tests/array/array_walk_recursive_variation2.phpt new file mode 100644 index 000000000..d94647376 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation2.phpt @@ -0,0 +1,271 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values in place of 'funcname' argument(Bug#43543) +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'funcname' argument +*/ + +echo "*** Testing array_walk_recursive() : unexpected values for 'funcname' argument ***\n"; + +$input = array(1, array(2, 3)); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$user_data = 20; + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// class definition +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +// different scalar/nonscalar values to be used in place of callback function +$funcname_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/* 10*/ array(), + array(0), + array(1), + array('color' => 'red', 'item' => 'pen'), + + // null data +/* 14*/ NULL, + null, + + // boolean data +/* 16*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 20*/ "", + '', + + // object data + new MyClass(), + + // resource data +/* 23*/ $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 25*/ @$unset_var, +); + +for($count = 0; $count < count($funcname_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input, $funcname_values[$count]) ); + var_dump( array_walk_recursive($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 11 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 12 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 13 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 14 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 21 -- + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 22 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation3.phpt b/ext/standard/tests/array/array_walk_recursive_variation3.phpt new file mode 100644 index 000000000..747ba3bb0 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with different values +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with following types of 'input' arrays: + * integer, float, string, bool, null, empty & mixed +*/ + +// callback function +/* + * Prototype : print_value(mixed $value, int $key, int $count) + * Parameters : $value - array entries(values) + * $key - keys in given input array + * $count - extra parameter used as an index + * Description : prints the array values with keys and count value + */ +function print_value($value, $key, $count) +{ + echo $count." : ".$key." ".$value."\n"; +} + +echo "*** Testing array_walk_recursive() : 'input' array with different values***\n"; + +// different arrays as input +$input_values = array( + + // integer values +/*1*/ array(array(1, 0, -10), array(023, -041), array(0x5A, 0X1F, -0x6E)), + + // float value + array(array(3.4, 0.8, -2.9), array(6.25e2, 8.20E-3)), + + // string values + array('Mango', array("Apple", 'Orange', "Lemon")), + + // bool values +/*4*/ array( array(true, false), array(TRUE, FALSE)), + + // null values + array( array(null), array(NULL)), + + // empty array + array(), + + // binary array + array(b"binary"), + + // mixed array +/*8*/ array(16, 8.345, array("Fruits"), array(true, null), array(FALSE), array(-98, 0.005, 'banana')) +); + +for($count = 0; $count < count($input_values); $count++) { + echo "\n-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input_values[$count], "print_value", $count+1)); +} +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 0 19 +1 : 1 -33 +1 : 0 90 +1 : 1 31 +1 : 2 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 0 625 +2 : 1 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 0 Apple +3 : 1 Orange +3 : 2 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 0 1 +4 : 1 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 0 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 0 Fruits +8 : 0 1 +8 : 1 +8 : 0 +8 : 0 -98 +8 : 1 0.005 +8 : 2 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation4.phpt b/ext/standard/tests/array/array_walk_recursive_variation4.phpt new file mode 100644 index 000000000..4db34979a --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation4.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with subarray +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with an array having subarrays as elements +*/ + +echo "*** Testing array_walk_recursive() : array with subarray ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values in given 'input' array + * $key - keys in given 'input' array + * Description : It prints the count of an array elements, passed as argument + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +$input = array( + array(), + array(1), + array(1,2,3), + array("Mango", "Orange"), + array(array(1, 2, 3), array(1)) +); + +var_dump( array_walk_recursive( $input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array with subarray *** +int(0) +int(1) + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +string(5) "Mango" + +int(1) +string(6) "Orange" + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +int(1) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation5.phpt b/ext/standard/tests/array/array_walk_recursive_variation5.phpt new file mode 100644 index 000000000..688da57f0 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with an array having reference variables +*/ + +echo "*** Testing array_walk_recursive() : array with references ***\n"; + +$value1 = 10; +$value2 = -20; +$value3 = &$value1; +$value4 = 50; + +// 'input' array containing references to above variables +$input = array(&$value1, array(&$value2, -35), array(&$value3, 0), array(&$value4)); + +// callback function +/* Prototype : callback(int $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : function checks for the value whether positive or negative and displays according to that + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +var_dump( array_walk_recursive($input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array with references *** +int(0) +int(10) + +int(0) +int(-20) + +int(1) +int(-35) + +int(0) +int(10) + +int(1) +int(0) + +int(0) +int(50) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation6.phpt b/ext/standard/tests/array/array_walk_recursive_variation6.phpt new file mode 100644 index 000000000..554ade4f4 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation6.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing 'input' argument as an associative array + * with Numeric & string keys +*/ + +echo "*** Testing array_walk_recursive() : 'input' as an associative array ***\n"; + +// callback functions +/* Prototype : for_numeric( int $value, int $key, int $user_data) + * Parameters : $value - value from key/value pair of the array + * $key - key from key/value pair of the array + * $user_data - data to be added to 'value' + * Description : Function adds values with keys & user_data + */ +function for_numeric($value, $key, $user_data) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_string( string $value, string $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function appends key to the value + */ +function for_string($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_mixed( mixed $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function displays each element of an array with keys + */ +function for_mixed($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +// Numeric keys +$input = array( 0 => array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30)); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk_recursive($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange")); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// binary keys +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk_recursive($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(12) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +int(5) +int(30) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation7.phpt b/ext/standard/tests/array/array_walk_recursive_variation7.phpt new file mode 100644 index 000000000..0cdd6d248 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : proto bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Passing anonymous(run-time) callback function with following variations: +* with one parameter +* two parameters +* three parameters +* extra parameters +* without parameters +*/ + +echo "*** Testing array_walk_recursive() : anonymous function as callback ***\n"; + +$input = array( array(2, 5), array(10, 0)); + +echo "-- Anonymous function with one argument --\n"; +var_dump( array_walk_recursive($input, create_function('$value', 'var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with two arguments --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with three arguments --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10)); + +echo "-- Anonymous function with one more argument --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); + +echo "-- Anonymous function with null argument --\n"; +var_dump( array_walk_recursive( $input, create_function(null, 'echo "1\n";'))); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(0) +int(10) + +int(1) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(0) +int(10) +int(10) + +int(1) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation8.phpt b/ext/standard/tests/array/array_walk_recursive_variation8.phpt new file mode 100644 index 000000000..aa73912cf --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - buit-in function as callback +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different buit-in functionns as callback function + * pow function + * min function + * echo language construct +*/ + +echo "*** Testing array_walk_recursive() : built-in function as callback ***\n"; + +$input = array(array(1, 2)); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk_recursive($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk_recursive($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk_recursive($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- + +Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation9.phpt b/ext/standard/tests/array/array_walk_recursive_variation9.phpt new file mode 100644 index 000000000..f18fe248c --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - different callback functions +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different types of callback functions to array_walk_recursive() + * without parameters + * with less and more parameters +*/ + +echo "*** Testing array_walk_recursive() : callback function variation ***\n"; + +$input = array(array('Apple', 'Banana'), 'Mango', array('Orange')); + +echo "-- callback function with both parameters --\n"; +function callback_two_parameter($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk_recursive($input, 'callback_two_parameter')); + +echo "-- callback function with only one parameter --\n"; +function callback_one_parameter($value) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk_recursive($input, 'callback_one_parameter')); + +echo "-- callback function without parameters --\n"; +function callback_no_parameter() +{ + echo "callback3() called\n"; +} +var_dump( array_walk_recursive($input, 'callback_no_parameter')); + +echo "-- passing one more parameter to function with two parameters --\n"; +var_dump( array_walk_recursive($input, 'callback_two_parameter', 10)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation1.phpt b/ext/standard/tests/array/array_walk_variation1.phpt new file mode 100644 index 000000000..e08c0d711 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'input' argument +*/ + +echo "*** Testing array_walk() : unexpected values for 'input' argument ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values given in input array + * $key - keys given in input array + * Description : Function prints each element of an array with key + */ +function callback($value, $key) +{ + echo "key : "; + var_dump($key); + echo "value : "; + var_dump($value); +} + +// extra parameter passed to array_walk() +$user_data = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// different scalar/nonscalar values to be used in place of an 'input' argument +$input_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/* 10*/ NULL, + null, + + // boolean data +/* 12*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 16*/ "", + '', + + // string data +/* 18*/ "string", + 'string', + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 22*/ @$unset_var, +); + + +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input_values[$count], "callback") ); + var_dump( array_walk($input_values[$count], "callback", $user_data) ); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_variation2.phpt b/ext/standard/tests/array/array_walk_variation2.phpt new file mode 100644 index 000000000..88fbbf3d5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation2.phpt @@ -0,0 +1,271 @@ +--TEST-- +Test array_walk() function : usage variations - unexpected values in place of 'funcname' argument +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'funcname' argument +*/ + +echo "*** Testing array_walk() : unexpected values for 'funcname' argument ***\n"; + +$input = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$user_data = 20; + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// class definition +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +// different scalar/nonscalar values to be used in place of callback function +$funcname_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/* 10*/ array(), + array(0), + array(1), + array('color' => 'red', 'item' => 'pen'), + + // null data +/* 14*/ NULL, + null, + + // boolean data +/* 16*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 20*/ "", + '', + + // object data + new MyClass(), + + // resource data +/* 23*/ $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 25*/ @$unset_var, +); + +for($count = 0; $count < count($funcname_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input, $funcname_values[$count]) ); + var_dump( array_walk($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 11 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 12 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 13 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 14 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 21 -- + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 22 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_variation3.phpt b/ext/standard/tests/array/array_walk_variation3.phpt new file mode 100644 index 000000000..ad2612353 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with different values +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with following types of 'input' arrays: + * integer, float, string, bool, null, empty & mixed +*/ + +// callback function +/* + * Prototype : print_value(mixed $value, int $key, int $count) + * Parameters : $value - array entries(values) + * $key - keys in given input array + * $count - extra parameter used as an index + * Description : prints the array values with keys and count value + */ +function print_value($value, $key, $count) +{ + echo $count." : ".$key." ".$value."\n"; +} + +echo "*** Testing array_walk() : 'input' array with different values***\n"; + +// different arrays as input +$input_values = array( + + // integer values +/*1*/ array(1, 0, -10, 023, -041, 0x5A, 0X1F, -0x6E), + + // float value + array(3.4, 0.8, -2.9, 6.25e2, 8.20E-3), + + // string values + array('Mango', "Apple", 'Orange', "Lemon"), + + // bool values +/*4*/ array(true, false, TRUE, FALSE), + + // null values + array(null, NULL), + + // empty array + array(), + + // binary array + array(b"binary"), + + // mixed array +/*8*/ array(16, 8.345, "Fruits", true, null, FALSE, -98, 0.005, 'banana') +); + +for($count = 0; $count < count($input_values); $count++) { + echo "\n-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input_values[$count], "print_value", $count+1)); +} +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 3 19 +1 : 4 -33 +1 : 5 90 +1 : 6 31 +1 : 7 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 3 625 +2 : 4 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 1 Apple +3 : 2 Orange +3 : 3 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 2 1 +4 : 3 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 1 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 2 Fruits +8 : 3 1 +8 : 4 +8 : 5 +8 : 6 -98 +8 : 7 0.005 +8 : 8 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation4.phpt b/ext/standard/tests/array/array_walk_variation4.phpt new file mode 100644 index 000000000..868732daa --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation4.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with subarray +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with an array having subarrays as elements +*/ + +echo "*** Testing array_walk() : array with subarray ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values in given 'input' array + * $key - keys in given 'input' array + * Description : It prints the count of an array elements, passed as argument + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +$input = array( + array(), + array(1), + array(1,2,3), + array("Mango", "Orange"), + array(array(1, 2, 3)) +); + +var_dump( array_walk( $input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array with subarray *** +int(0) +array(0) { +} + +int(1) +array(1) { + [0]=> + int(1) +} + +int(2) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +int(3) +array(2) { + [0]=> + string(5) "Mango" + [1]=> + string(6) "Orange" +} + +int(4) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation5.phpt b/ext/standard/tests/array/array_walk_variation5.phpt new file mode 100644 index 000000000..f42e0f11e --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument containing reference variables +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with an array having reference variables +*/ + +echo "*** Testing array_walk() : array with references ***\n"; + +$value1 = 10; +$value2 = -20; +$value3 = &$value1; +$value4 = 50; + +// 'input' array containing references to above variables +$input = array(&$value1, &$value2, -35, &$value3, 0, &$value4); + +// callback function +/* Prototype : callback(int $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : function checks for the value whether positive or negative and displays according to that + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +var_dump( array_walk($input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array with references *** +int(0) +int(10) + +int(1) +int(-20) + +int(2) +int(-35) + +int(3) +int(10) + +int(4) +int(0) + +int(5) +int(50) + +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_walk_variation6.phpt b/ext/standard/tests/array/array_walk_variation6.phpt new file mode 100644 index 000000000..c1f23233e --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation6.phpt @@ -0,0 +1,143 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing 'input' argument as an associative array + * with Numeric & string keys +*/ + +echo "*** Testing array_walk() : 'input' as an associative array ***\n"; + +// callback functions +/* Prototype : for_numeric( int $value, int $key, int $user_data) + * Parameters : $value - value from key/value pair of the array + * $key - key from key/value pair of the array + * $user_data - data to be added to 'value' + * Description : Function adds values with keys & user_data + */ +function for_numeric($value, $key, $user_data) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_string( string $value, string $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function appends key to the value + */ +function for_string($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_mixed( mixed $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function displays each element of an array with keys + */ +function for_mixed($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +// Numeric keys +$input = array( 1 => 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange"); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk($input, "for_string")); + +// binary keys +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(30) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation7.phpt b/ext/standard/tests/array/array_walk_variation7.phpt new file mode 100644 index 000000000..da85958b8 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : proto bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Passing anonymous(run-time) callback function with following variations: +* with one parameter +* two parameters +* three parameters +* extra parameters +* without parameters +*/ + +echo "*** Testing array_walk() : anonymous function as callback ***\n"; + +$input = array(2, 5, 10, 0); + +echo "-- Anonymous function with one argument --\n"; +var_dump( array_walk($input, create_function('$value', 'var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with two arguments --\n"; +var_dump( array_walk($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with three arguments --\n"; +var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10)); + +echo "-- Anonymous function with one more argument --\n"; +var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); + +echo "-- Anonymous function with null argument --\n"; +var_dump( array_walk( $input, create_function(null, 'echo "1\n";'))); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(2) +int(10) + +int(3) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(2) +int(10) +int(10) + +int(3) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d +NULL +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation8.phpt b/ext/standard/tests/array/array_walk_variation8.phpt new file mode 100644 index 000000000..2086394dd --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk() function : usage variations - buit-in function as callback +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different buit-in functionns as callback function + * pow function + * min function + * echo language construct +*/ + +echo "*** Testing array_walk() : built-in function as callback ***\n"; + +$input = array(2 => 1, 65, 98, 100, 6 => -4); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- + +Warning: array_walk(): Unable to call echo() - function does not exist in %s on line %d +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation9.phpt b/ext/standard/tests/array/array_walk_variation9.phpt new file mode 100644 index 000000000..42ae20d68 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk() function : usage variations - different callback functions +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different types of callback functions to array_walk() + * without parameters + * with less and more parameters +*/ + +echo "*** Testing array_walk() : callback function variation ***\n"; + +$input = array('Apple', 'Banana', 'Mango', 'Orange'); + +echo "-- callback function with both parameters --\n"; +function callback_two_parameter($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk($input, 'callback_two_parameter')); + +echo "-- callback function with only one parameter --\n"; +function callback_one_parameter($value) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk($input, 'callback_one_parameter')); + +echo "-- callback function without parameters --\n"; +function callback_no_parameter() +{ + echo "callback3() called\n"; +} +var_dump( array_walk($input, 'callback_no_parameter')); + +echo "-- passing one more parameter to function with two parameters --\n"; +var_dump( array_walk($input, 'callback_two_parameter', 10)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_error.phpt b/ext/standard/tests/array/arsort_error.phpt new file mode 100644 index 000000000..676d8265e --- /dev/null +++ b/ext/standard/tests/array/arsort_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : error conditions +--FILE-- +<?php +/* Prototype : bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing arsort() function with all possible error conditions +*/ + +echo "*** Testing arsort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing arsort() function with Zero arguments --\n"; +var_dump( arsort() ); + +//Test arsort with more than the expected number of arguments +echo "\n-- Testing arsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and setting all possible flag values +foreach($flags as $key => $flag){ + echo "\nSort flag = $key\n"; + var_dump( arsort($array_arg,$flag, $extra_arg) ); + + // dump the input array to ensure that it wasn't changed + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : error conditions *** + +-- Testing arsort() function with Zero arguments -- + +Warning: arsort() expects at least 1 parameter, 0 given in %sarsort_error.php on line %d +bool(false) + +-- Testing arsort() function with more than expected no. of arguments -- + +Sort flag = SORT_REGULAR + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_STRING + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_NUMERIC + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation1.phpt b/ext/standard/tests/array/arsort_variation1.phpt new file mode 100644 index 000000000..1545abe34 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation1.phpt @@ -0,0 +1,399 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different unexpected values for array argument with following flag values. + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +//array of values with indices to iterate over +$unexpected_values = array ( + + // int data + 0 => 0, + 1 => 1, + 2 => 12345, + 3 => -2345, + + // float data + 4 => 10.5, + 5 => -10.5, + 6 => 10.5e3, + 7 => 10.6E-2, + 8 => .5, + + // null data + 9 => NULL, + 10 => null, + + // boolean data + 11 => true, + 12 => false, + 13 => TRUE, + 14 => FALSE, + + // empty data + 15 => "", + 16 => '', + + // string data + 17 => "string", + 18 => 'string', + + // object data + 19 => new stdclass(), + + // undefined data + 20 => @undefined_var, + + // unset data + 21 => @unset_var, + + // resource variable + 22 => $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( arsort($value) ); // expecting : bool(false) + var_dump( arsort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( arsort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( arsort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 2 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 3 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 4 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 5 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 6 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 7 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 8 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 9 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 10 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 11 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 12 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 13 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 14 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 15 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 16 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 17 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 18 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 19 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 20 -- + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 21 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 22 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 23 -- + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation10.phpt b/ext/standard/tests/array/arsort_variation10.phpt new file mode 100644 index 000000000..ec483df3a --- /dev/null +++ b/ext/standard/tests/array/arsort_variation10.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different octal array for $array argument with following flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// an array contains unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation11.phpt b/ext/standard/tests/array/arsort_variation11.phpt Binary files differnew file mode 100644 index 000000000..e8bfd772e --- /dev/null +++ b/ext/standard/tests/array/arsort_variation11.phpt diff --git a/ext/standard/tests/array/arsort_variation2.phpt b/ext/standard/tests/array/arsort_variation2.phpt new file mode 100644 index 000000000..ab04b4409 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation2.phpt @@ -0,0 +1,308 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : proto bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// temperory array for checking unexpected behavior +$unsorted_values = array(1 => 10, 2 => 2, 3 => 45); + +//array of values to iterate over +$unexpected_values = array( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $flag arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( arsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 3 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 14 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 15 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 16 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 17 -- + +Warning: arsort() expects parameter 2 to be long, object given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 18 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 19 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 20 -- + +Warning: arsort() expects parameter 2 to be long, resource given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation3.phpt b/ext/standard/tests/array/arsort_variation3.phpt new file mode 100644 index 000000000..609155ca7 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation3.phpt @@ -0,0 +1,326 @@ +--TEST-- +Test arsort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing different integer/float value arrays for $array argument with following values + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// group of various arrays with indices +$various_arrays = array( + // negative/posative integer array + array(1 => 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing arsort() by supplying various integer/float arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation4.phpt b/ext/standard/tests/array/arsort_variation4.phpt new file mode 100644 index 000000000..a76a180f4 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : usage variations - sort reference variables +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing reference variable array with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() :usage variations ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( 1 => &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() :usage variations *** + +-- Testing arsort() by supplying reference variable array, 'flag' value is defualt -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation5.phpt b/ext/standard/tests/array/arsort_variation5.phpt new file mode 100644 index 000000000..e69c26988 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation5.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test arsort() function : usage variations - sort strings +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different string arrays for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +$various_arrays = array ( + // group of escape sequences + array ("null"=> null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing arsort() by supplying various string arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation6.phpt b/ext/standard/tests/array/arsort_variation6.phpt new file mode 100644 index 000000000..687b20a71 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different hexa-decimal array for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// an array contains unsorted hexadecimal values +// There are multiple keys which are duplicate and the later should be picked +$unsorted_hex_array = array ( 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation7.phpt b/ext/standard/tests/array/arsort_variation7.phpt new file mode 100644 index 000000000..97195b709 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test arsort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: This function arsorts an array. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing bool value array for $array argument with following flag values. + * flag value as defualt + * SORT_REGULAR - compare items normally +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// bool value array +$bool_values = array (1 => true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying bool value array, 'flag' value is defualt -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation8.phpt b/ext/standard/tests/array/arsort_variation8.phpt new file mode 100644 index 000000000..c2473160c --- /dev/null +++ b/ext/standard/tests/array/arsort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test arsort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing arrays contains sub arrays for $array argument with flowing flag values + * flag value as default + * SORT_REGULAR - compare items normally + * Note: arrays are sorted based on total count of elements inside it, when all the elements are arrays +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + "array[0]" => array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing arsort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // testing arsort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation9.phpt b/ext/standard/tests/array/arsort_variation9.phpt new file mode 100644 index 000000000..a034db5d9 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation9.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test arsort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing arrays with key values for $array argument with following flag values. + * 1.flag value as default + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing arsort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays with key values --\n"; + +// loop through to test arsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/bug26458.phpt b/ext/standard/tests/array/bug26458.phpt Binary files differindex d24e1f151..ecd12ba84 100644 --- a/ext/standard/tests/array/bug26458.phpt +++ b/ext/standard/tests/array/bug26458.phpt diff --git a/ext/standard/tests/array/bug42177.phpt b/ext/standard/tests/array/bug42177.phpt new file mode 100644 index 000000000..63a9b71d9 --- /dev/null +++ b/ext/standard/tests/array/bug42177.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...) +--FILE-- +<?php + +$a1 = array( 'key1' => 1, 'key3' => 2 ); +$a2 = array(); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => 1, 'key3' => 2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => &$a1 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1['key1'] = null; +unset( $a1, $a2 ); + +$x = 'foo'; +$y =& $x; +$a1 = array($x, $y, $x, $y); +$a2 = array( 'key1' => $a1, $x, $y ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +?> +--EXPECTF-- +Warning: array_merge_recursive(): recursion detected in %s on line 18 diff --git a/ext/standard/tests/array/bug42838.phpt b/ext/standard/tests/array/bug42838.phpt new file mode 100644 index 000000000..1f895f31e --- /dev/null +++ b/ext/standard/tests/array/bug42838.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug#42838 - Wrong results in array_diff_uassoc +--FILE-- +<?php + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +$array1 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); +$array2 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); + +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); +print_r($result); + +?> +--EXPECT-- +Array +( +)
\ No newline at end of file diff --git a/ext/standard/tests/array/bug42850.phpt b/ext/standard/tests/array/bug42850.phpt new file mode 100644 index 000000000..737cd170d --- /dev/null +++ b/ext/standard/tests/array/bug42850.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #42850 array_walk_recursive() leaves references, #34982 array_walk_recursive() modifies elements outside function scope +--FILE-- +<?php + +// Bug #42850 +$data = array ('key1' => 'val1', array('key2' => 'val2')); +function apply_dumb($item, $key) {}; +var_dump($data); +array_walk_recursive($data, 'apply_dumb'); +$data2 = $data; +$data2[0] = 'altered'; +var_dump($data); +var_dump($data2); + +// Bug #34982 +function myfunc($data) { + array_walk_recursive($data, 'apply_changed'); +} +function apply_changed(&$input, $key) { + $input = 'changed'; +} +myfunc($data); +var_dump($data); + +--EXPECT-- +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + string(7) "altered" +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} diff --git a/ext/standard/tests/array/bug43495.phpt b/ext/standard/tests/array/bug43495.phpt new file mode 100644 index 000000000..cd0fab141 --- /dev/null +++ b/ext/standard/tests/array/bug43495.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #43495 (array_merge_recursive() crashes with recursive arrays) +--FILE-- +<?php +$a=array("key1"=>array("key2"=>array())); +$a["key1"]["key2"]["key3"]=&$a; + +$b=array("key1"=>array("key2"=>array())); +$b["key1"]["key2"]["key3"]=&$b; + +array_merge_recursive($a,$b); + +/* Break recursion */ +$a["key1"]["key2"]["key3"] = null; +$b["key1"]["key2"]["key3"] = null; + +echo "Done.\n"; +?> +--EXPECTF-- +Warning: array_merge_recursive(): recursion detected in %s/bug43495.php on line %d +Done. diff --git a/ext/standard/tests/array/bug43505.phpt b/ext/standard/tests/array/bug43505.phpt new file mode 100644 index 000000000..219bbfe29 --- /dev/null +++ b/ext/standard/tests/array/bug43505.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #43505 (Assign by reference bug) +--INI-- +error_reporting=0 +--SKIPIF-- +<?php if (!extension_loaded('spl')) die("skip SPL is not available"); ?> +--FILE-- +<?php +class Test implements Countable { + public function count() { + return $some; + } +} + +$obj = new Test(); + +$a = array(); +$b =& $a['test']; +var_dump($a); + +$t = count($obj); + +$a = array(); +$b =& $a['test']; +var_dump($a); +?> +--EXPECT-- +array(1) { + ["test"]=> + &NULL +} +array(1) { + ["test"]=> + &NULL +} + diff --git a/ext/standard/tests/array/compact_basic.phpt b/ext/standard/tests/array/compact_basic.phpt new file mode 100644 index 000000000..53a946e12 --- /dev/null +++ b/ext/standard/tests/array/compact_basic.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test compact() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) + * Description: Creates a hash containing variables and their values + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Test basic functionality + */ + +echo "*** Testing compact() : basic functionality ***\n"; + +$a=1; +$b=0.2; +$c=true; +$d=array("key"=>"val"); +$e=NULL; +$f="string"; + +// simple array test +var_dump (compact(array("a", "b", "c", "d", "e", "f"))); +// simple parameter test +var_dump (compact("a", "b", "c", "d", "e", "f")); +var_dump (compact(array("keyval"=>"a", "b"=>"b", "c"=>1))); + +// cases which should not yield any output. +var_dump (compact(array(10, 0.3, true, array(20), NULL))); +var_dump (compact(10, 0.3, true, array(20), NULL)); +var_dump (compact(array("g"))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : basic functionality *** +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(2) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) +} +array(0) { +} +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/compact_error.phpt b/ext/standard/tests/array/compact_error.phpt new file mode 100644 index 000000000..d3d6e2cbb --- /dev/null +++ b/ext/standard/tests/array/compact_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test compact() function : error conditions +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) + * Description: Creates a hash containing variables and their values + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Error -tests test compact with zero arguments. + */ + +echo "*** Testing compact() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing compact() function with Zero arguments --\n"; +var_dump( compact() ); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : error conditions *** + +-- Testing compact() function with Zero arguments -- + +Warning: Wrong parameter count for compact() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/count_basic.phpt b/ext/standard/tests/array/count_basic.phpt new file mode 100644 index 000000000..45f63d6a4 --- /dev/null +++ b/ext/standard/tests/array/count_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test count() function : basic functionality +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of count() using an array as $var argument + * and different values as $mode argument. + */ + +echo "*** Testing count() : basic functionality ***\n"; + +echo "\n-- One Dimensional Array: --\n"; +$array = array('zero', 'one', 'two'); +var_dump(count($array)); + +echo "\n-- Two Dimensional Array: --\n"; +$array_multi = array('zero', array(1, 2, 3), 'two'); +echo "\$mode = COUNT_NORMAL: "; +var_dump(count($array_multi, COUNT_NORMAL)); +echo "\$mode = 0: "; +var_dump(count($array_multi, 0)); +echo "\$mode = COUNT_RECURSIVE: "; +var_dump(count($array_multi, COUNT_RECURSIVE)); +echo "\$mode = 1: "; +var_dump(count($array_multi, 1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : basic functionality *** + +-- One Dimensional Array: -- +int(3) + +-- Two Dimensional Array: -- +$mode = COUNT_NORMAL: int(3) +$mode = 0: int(3) +$mode = COUNT_RECURSIVE: int(6) +$mode = 1: int(6) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_error.phpt b/ext/standard/tests/array/count_error.phpt new file mode 100644 index 000000000..76f721364 --- /dev/null +++ b/ext/standard/tests/array/count_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test count() function : error conditions - pass incorrect number of args +--FILE-- +<?php +/* Prototype : int count(mixed var [, int mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to count() to test behaviour + */ + +echo "*** Testing count() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing count() function with Zero arguments --\n"; +var_dump( count() ); + +//Test count with one more than the expected number of arguments +echo "\n-- Testing count() function with more than expected no. of arguments --\n"; +$var = 1; +$mode = 10; +$extra_arg = 10; +var_dump( count($var, $mode, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : error conditions *** + +-- Testing count() function with Zero arguments -- + +Warning: count() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing count() function with more than expected no. of arguments -- + +Warning: count() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_variation1.phpt b/ext/standard/tests/array/count_variation1.phpt new file mode 100644 index 000000000..b40a2ab29 --- /dev/null +++ b/ext/standard/tests/array/count_variation1.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test count() function : usage variations - Pass different data types as $var arg +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * aPass different data types as $var argument to count() to test behaviour + */ + +echo "*** Testing count() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $var argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of count() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( count($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- Iteration 1 -- +int(1) + +-- Iteration 2 -- +int(1) + +-- Iteration 3 -- +int(1) + +-- Iteration 4 -- +int(1) + +-- Iteration 5 -- +int(1) + +-- Iteration 6 -- +int(1) + +-- Iteration 7 -- +int(1) + +-- Iteration 8 -- +int(1) + +-- Iteration 9 -- +int(1) + +-- Iteration 10 -- +int(0) + +-- Iteration 11 -- +int(0) + +-- Iteration 12 -- +int(1) + +-- Iteration 13 -- +int(1) + +-- Iteration 14 -- +int(1) + +-- Iteration 15 -- +int(1) + +-- Iteration 16 -- +int(1) + +-- Iteration 17 -- +int(1) + +-- Iteration 18 -- +int(1) + +-- Iteration 19 -- +int(1) + +-- Iteration 20 -- +int(1) + +-- Iteration 21 -- +int(1) + +-- Iteration 22 -- +int(0) + +-- Iteration 23 -- +int(0) + +-- Iteration 24 -- +int(1) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_variation2.phpt b/ext/standard/tests/array/count_variation2.phpt new file mode 100644 index 000000000..86aecc07b --- /dev/null +++ b/ext/standard/tests/array/count_variation2.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test count() function : usage variations - Pass different data types as $mode arg +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $mode argument to count() to test behaviour + */ + +echo "*** Testing count() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = array(1, 2, array ('one', 'two')); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $mode argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of count() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( count($var, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- Iteration 1 -- +int(3) + +-- Iteration 2 -- +int(5) + +-- Iteration 3 -- +int(3) + +-- Iteration 4 -- +int(3) + +-- Iteration 5 -- +int(3) + +-- Iteration 6 -- +int(3) + +-- Iteration 7 -- +int(3) + +-- Iteration 8 -- +int(3) + +-- Iteration 9 -- +int(3) + +-- Iteration 10 -- +int(3) + +-- Iteration 11 -- +int(3) + +-- Iteration 12 -- +int(5) + +-- Iteration 13 -- +int(3) + +-- Iteration 14 -- +int(5) + +-- Iteration 15 -- +int(3) + +-- Iteration 16 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: count() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- +int(3) + +-- Iteration 23 -- +int(3) + +-- Iteration 24 -- + +Warning: count() expects parameter 2 to be long, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_variation3.phpt b/ext/standard/tests/array/count_variation3.phpt new file mode 100644 index 000000000..7ec5667d3 --- /dev/null +++ b/ext/standard/tests/array/count_variation3.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test count() function : usage variations - Infinitely recursive array +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass count() an infinitely recursive array as $var argument + * This will stop the script before it reaches the end. + */ + +echo "*** Testing count() : usage variations ***\n"; + +$array1 = array (1, 2, 'three'); +// get an infinitely recursive array +$array1[] = &$array1; + +echo "\n-- \$mode not set: --\n"; +var_dump(count ($array1)); + +echo "\n-- \$mode = 1: --\n"; +var_dump(count ($array1, 1)); + +$array1[3] = null; + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- $mode not set: -- +int(4) + +-- $mode = 1: -- + +Warning: count(): recursion detected in %s on line %d +int(12) +Done diff --git a/ext/standard/tests/array/current_basic.phpt b/ext/standard/tests/array/current_basic.phpt new file mode 100644 index 000000000..cec695977 --- /dev/null +++ b/ext/standard/tests/array/current_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test current() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of current() + */ + +echo "*** Testing current() : basic functionality ***\n"; + +$array = array ('zero', 'one', 'two', 'three' => 3); +var_dump(current($array)); +next($array); +var_dump(current($array)); +end($array); +var_dump(current($array)); +next($array); +var_dump(current($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : basic functionality *** +string(4) "zero" +string(3) "one" +int(3) +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_error.phpt b/ext/standard/tests/array/current_error.phpt new file mode 100644 index 000000000..40362e779 --- /dev/null +++ b/ext/standard/tests/array/current_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test current() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass incorrect number of arguments to current() to test behaviour + */ + +echo "*** Testing current() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing current() function with Zero arguments --\n"; +var_dump( current() ); + +//Test current with one more than the expected number of arguments +echo "\n-- Testing current() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( current($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : error conditions *** + +-- Testing current() function with Zero arguments -- + +Warning: Wrong parameter count for current() in %s on line %d +NULL + +-- Testing current() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for current() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/current_variation1.phpt b/ext/standard/tests/array/current_variation1.phpt new file mode 100644 index 000000000..cb21df27a --- /dev/null +++ b/ext/standard/tests/array/current_variation1.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test current() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass different data types as $array_arg argument to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $var1; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_variation2.phpt b/ext/standard/tests/array/current_variation2.phpt new file mode 100644 index 000000000..49769cea3 --- /dev/null +++ b/ext/standard/tests/array/current_variation2.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test current() function : usage variations - arrays containing different data types +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass arrays of different data types as $array_arg to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 : int data -- +int(0) + +-- Iteration 2 : float data -- +float(10.5) + +-- Iteration 3 : null data -- +NULL + +-- Iteration 4 : bool data -- +bool(true) + +-- Iteration 5 : empty string data -- +string(0) "" + +-- Iteration 6 : empty array data -- +bool(false) + +-- Iteration 7 : string data -- +string(6) "string" + +-- Iteration 8 : object data -- +object(classA)#%d (0) { +} + +-- Iteration 9 : undefined data -- +NULL + +-- Iteration 10 : unset data -- +NULL + +-- Iteration 11 : resource data -- +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/array/current_variation3.phpt b/ext/standard/tests/array/current_variation3.phpt new file mode 100644 index 000000000..bab5e6e0c --- /dev/null +++ b/ext/standard/tests/array/current_variation3.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test current() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing current() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); +next($array1); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" +===DONE=== diff --git a/ext/standard/tests/array/current_variation4.phpt b/ext/standard/tests/array/current_variation4.phpt new file mode 100644 index 000000000..19864f584 --- /dev/null +++ b/ext/standard/tests/array/current_variation4.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test current() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how current() behaves with muti-dimensional and recursive arrays + */ + +echo "*** Testing current() : usage variations ***\n"; + +echo "\n-- Two Dimensional Array --\n"; +$multi_array = array ('zero', array (1, 2, 3), 'two'); +echo "Initial Position: "; +var_dump(current($multi_array)); + +echo "Next Position: "; +next($multi_array); +var_dump(current($multi_array)); + +echo "End Position: "; +end($multi_array); +var_dump(current($multi_array)); + +echo "\n-- Access an Array Within an Array --\n"; +//accessing an array within an array +echo "Initial Position: "; +var_dump(current($multi_array[1])); + +echo "\n-- Recursive, Multidimensional Array --\n"; +//create a recursive array +$multi_array[] = &$multi_array; + +//See where internal pointer is after adding more elements +echo "Current Position: "; +var_dump(current($multi_array)); + +//see if internal pointer is in same position as referenced array +var_dump(current($multi_array[3][3][3])); +// see if internal pointer is in the same position from when accessing this inner array +var_dump(current($multi_array[3][3][3][1])); +$multi_array[3] = null; +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: string(4) "zero" +Next Position: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +End Position: string(3) "two" + +-- Access an Array Within an Array -- +Initial Position: int(1) + +-- Recursive, Multidimensional Array -- +Current Position: string(3) "two" +string(3) "two" +int(1) +===DONE=== diff --git a/ext/standard/tests/array/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt new file mode 100644 index 000000000..350b40f9a --- /dev/null +++ b/ext/standard/tests/array/each_basic.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test each() function : basic functionality +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test basic functionality of each() + */ + +echo "*** Testing each() : basic functionality ***\n"; + +$arr = array ('one' => 1, 'zero', 'two' => 'deux', 20 => 'twenty'); +echo "\n-- Passed array: --\n"; +var_dump($arr); + +echo "\n-- Initial position: --\n"; +var_dump(each($arr)); + +echo "\n-- End position: --\n"; +end($arr); +var_dump(each($arr)); + +echo "\n-- Passed the end of array: --\n"; +var_dump(each($arr)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing each() : basic functionality *** + +-- Passed array: -- +array(4) { + ["one"]=> + int(1) + [0]=> + string(4) "zero" + ["two"]=> + string(4) "deux" + [20]=> + string(6) "twenty" +} + +-- Initial position: -- +array(4) { + [1]=> + int(1) + ["value"]=> + int(1) + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- End position: -- +array(4) { + [1]=> + string(6) "twenty" + ["value"]=> + string(6) "twenty" + [0]=> + int(20) + ["key"]=> + int(20) +} + +-- Passed the end of array: -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_error.phpt b/ext/standard/tests/array/each_error.phpt new file mode 100644 index 000000000..02c8ef9c0 --- /dev/null +++ b/ext/standard/tests/array/each_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test each() function : error conditions - pass incorrect number of args +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass an incorrect number of arguments to each() to test behaviour + */ + +echo "*** Testing each() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing each() function with Zero arguments --\n"; +var_dump( each() ); + +//Test each with one more than the expected number of arguments +echo "\n-- Testing each() function with more than expected no. of arguments --\n"; +$arr = array(1, 2); +$extra_arg = 10; +var_dump( each($arr, $extra_arg) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : error conditions *** + +-- Testing each() function with Zero arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL + +-- Testing each() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation1.phpt b/ext/standard/tests/array/each_variation1.phpt new file mode 100644 index 000000000..0afef3143 --- /dev/null +++ b/ext/standard/tests/array/each_variation1.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test each() function : usage variations - Pass different data types as $arr arg +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass different data types as $arr arg to each() to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( each($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/each_variation2.phpt b/ext/standard/tests/array/each_variation2.phpt new file mode 100644 index 000000000..3f7211c89 --- /dev/null +++ b/ext/standard/tests/array/each_variation2.phpt @@ -0,0 +1,248 @@ +--TEST-- +Test each() function : usage variations - arrays of different data types +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass arrays of different data types as $arr argument to each() to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $arr +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + int(0) + ["value"]=> + int(0) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + float(10.5) + ["value"]=> + float(10.5) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 3: null data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 4: bool data -- +array(4) { + [1]=> + bool(true) + ["value"]=> + bool(true) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 5: empty string data -- +array(4) { + [1]=> + string(0) "" + ["value"]=> + string(0) "" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 6: empty array data -- +bool(false) + +-- Iteration 7: string data -- +array(4) { + [1]=> + string(6) "string" + ["value"]=> + string(6) "string" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 8: object data -- +array(4) { + [1]=> + object(classA)#%d (0) { + } + ["value"]=> + object(classA)#%d (0) { + } + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 9: undefined data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 10: unset data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 11: resource data -- +array(4) { + [1]=> + resource(%d) of type (stream) + ["value"]=> + resource(%d) of type (stream) + [0]=> + int(0) + ["key"]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation3.phpt b/ext/standard/tests/array/each_variation3.phpt new file mode 100644 index 000000000..b31ddc61b --- /dev/null +++ b/ext/standard/tests/array/each_variation3.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test each() function : usage variations - keys of different data types +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass each() arrays where the keys are different data types to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $arr +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + string(8) "positive" + ["value"]=> + string(8) "positive" + [0]=> + int(10) + ["key"]=> + int(10) +} + +-- Iteration 3: extreme floats data -- +array(4) { + [1]=> + string(5) "large" + ["value"]=> + string(5) "large" + [0]=> + int(12345678) + ["key"]=> + int(12345678) +} + +-- Iteration 4: null uppercase data -- +array(4) { + [1]=> + string(6) "null 1" + ["value"]=> + string(6) "null 1" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 5: null lowercase data -- +array(4) { + [1]=> + string(6) "null 2" + ["value"]=> + string(6) "null 2" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [1]=> + string(6) "lowert" + ["value"]=> + string(6) "lowert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [1]=> + string(6) "uppert" + ["value"]=> + string(6) "uppert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 8: empty double quotes data -- +array(4) { + [1]=> + string(6) "emptyd" + ["value"]=> + string(6) "emptyd" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 9: empty single quotes data -- +array(4) { + [1]=> + string(6) "emptys" + ["value"]=> + string(6) "emptys" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 10: string data -- +array(4) { + [1]=> + string(7) "stringd" + ["value"]=> + string(7) "stringd" + [0]=> + string(7) "stringd" + ["key"]=> + string(7) "stringd" +} + +-- Iteration 11: undefined data -- +array(4) { + [1]=> + string(9) "undefined" + ["value"]=> + string(9) "undefined" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 12: unset data -- +array(4) { + [1]=> + string(5) "unset" + ["value"]=> + string(5) "unset" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation4.phpt b/ext/standard/tests/array/each_variation4.phpt new file mode 100644 index 000000000..6ac57a736 --- /dev/null +++ b/ext/standard/tests/array/each_variation4.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test each() function : usage variations - Referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test behaviour of each() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array as $arr argument by reference + */ + +echo "*** Testing each() : usage variations ***\n"; + +echo "\n-- Array made up of referenced variables: --\n"; +$val1 = 'foo'; +$val2 = 'bar'; + +$arr1 = array('one' => &$val1, &$val2); + +echo "-- Call each until at the end of the array: --\n"; +var_dump( each($arr1) ); +var_dump( each($arr1) ); +var_dump( each($arr1) ); + + +echo "\n-- Pass an array by reference to each(): --\n"; +$arr2 = array('zero', 'one', 'two'); + +var_dump( each(&$arr2) ); +echo "-- Check original array: --\n"; +var_dump($arr2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Array made up of referenced variables: -- +-- Call each until at the end of the array: -- +array(4) { + [1]=> + string(3) "foo" + ["value"]=> + string(3) "foo" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} +array(4) { + [1]=> + string(3) "bar" + ["value"]=> + string(3) "bar" + [0]=> + int(0) + ["key"]=> + int(0) +} +bool(false) + +-- Pass an array by reference to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +-- Check original array: -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done diff --git a/ext/standard/tests/array/each_variation5.phpt b/ext/standard/tests/array/each_variation5.phpt new file mode 100644 index 000000000..941ad5e3a --- /dev/null +++ b/ext/standard/tests/array/each_variation5.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test each() function : usage variations - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test behaviour of each() when passed: + * 1. a two-dimensional array + * 2. a sub-array + */ + +echo "*** Testing each() : usage variations ***\n"; + +$arr = array ('zero', + array(1, 2, 3), + 'one' => 'un', + array('a', 'b', 'c') + ); + +echo "\n-- Pass each() a two-dimensional array --\n"; +for ($i = 1; $i < count($arr); $i++) { + var_dump( each($arr) ); +} + +echo "\n-- Pass each() a sub-array --\n"; +var_dump( each($arr[2])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Pass each() a two-dimensional array -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +array(4) { + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["value"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + int(1) + ["key"]=> + int(1) +} +array(4) { + [1]=> + string(2) "un" + ["value"]=> + string(2) "un" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- Pass each() a sub-array -- +array(4) { + [1]=> + string(1) "a" + ["value"]=> + string(1) "a" + [0]=> + int(0) + ["key"]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation6.phpt b/ext/standard/tests/array/each_variation6.phpt new file mode 100644 index 000000000..445d63f31 --- /dev/null +++ b/ext/standard/tests/array/each_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test each() function : usage variations - Internal array pointer +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test the position of the internal array pointer after a call to each() + */ + +echo "*** Testing each() : usage variations ***\n"; + +$arr = array('zero', 'one', 'two', 'abc', 'xyz'); + +echo "\n-- Current position: --\n"; +echo key($arr) . " => " . current($arr) . "\n"; + +echo "\n-- Call to each(): --\n"; +var_dump( each($arr) ); + +echo "\n-- New position: --\n"; +echo key($arr) . " => " . current($arr) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Current position: -- +0 => zero + +-- Call to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- New position: -- +1 => one +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/end_basic.phpt b/ext/standard/tests/array/end_basic.phpt new file mode 100644 index 000000000..5a6606d38 --- /dev/null +++ b/ext/standard/tests/array/end_basic.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test end() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of end() + */ + +echo "*** Testing end() : basic functionality ***\n"; + +$array = array('zero', 'one', 200 => 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to end() --\n"; +var_dump(end($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Add a new element to array --\n"; +$array[2] = 'foo'; +var_dump(end($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to end() -- +string(3) "two" + +-- Current Position: -- +200 => two + +-- Add a new element to array -- +string(3) "foo" +===DONE=== diff --git a/ext/standard/tests/array/end_error.phpt b/ext/standard/tests/array/end_error.phpt new file mode 100644 index 000000000..1efc5ac54 --- /dev/null +++ b/ext/standard/tests/array/end_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test end() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to end() to test behaviour + */ + +echo "*** Testing end() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing end() function with Zero arguments --\n"; +var_dump( end() ); + +//Test end with one more than the expected number of arguments +echo "\n-- Testing end() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( end($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : error conditions *** + +-- Testing end() function with Zero arguments -- + +Warning: Wrong parameter count for end() in %s on line %d +NULL + +-- Testing end() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for end() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/end_variation1.phpt b/ext/standard/tests/array/end_variation1.phpt new file mode 100644 index 000000000..4ed70aeb2 --- /dev/null +++ b/ext/standard/tests/array/end_variation1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test end() function : usage variations - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg to test behaviour of end() + */ + +echo "*** Testing end() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $foo = 'hello, world'; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of end() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( end($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Iteration 1 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +string(12) "hello, world" + +-- Iteration 23 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/end_variation2.phpt b/ext/standard/tests/array/end_variation2.phpt new file mode 100644 index 000000000..180f7cdfb --- /dev/null +++ b/ext/standard/tests/array/end_variation2.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test end() function : usage variations - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test end() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing end() : usage variations ***\n"; + +$array_arg = array ('a' => 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(end($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(end($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} + +-- Pass a sub-array as $array_arg -- +int(7) +===DONE=== diff --git a/ext/standard/tests/array/end_variation3.phpt b/ext/standard/tests/array/end_variation3.phpt new file mode 100644 index 000000000..cd1e2d0ec --- /dev/null +++ b/ext/standard/tests/array/end_variation3.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test end() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing end() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); +end($array1); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; +echo "\n-- Position after calling end() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling end() -- +$array1: string(3) "two" +$array2: string(3) "two" +===DONE=== diff --git a/ext/standard/tests/array/key_basic.phpt b/ext/standard/tests/array/key_basic.phpt new file mode 100644 index 000000000..8fdca1966 --- /dev/null +++ b/ext/standard/tests/array/key_basic.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test key() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of key() + */ + +echo "*** Testing key() : basic functionality ***\n"; + +$array = array ('zero', 99 => 'one', 'two', 'three' => 3); +echo "\n-- Initial Position: --\n"; +var_dump(key($array)); + +echo "\n-- Next Position: --\n"; +next($array); +var_dump(key($array)); + +echo "\n-- End Position: --\n"; +end($array); +var_dump(key($array)); + +echo "\n-- Past end of the array --\n"; +next($array); +var_dump(key($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : basic functionality *** + +-- Initial Position: -- +int(0) + +-- Next Position: -- +int(99) + +-- End Position: -- +string(5) "three" + +-- Past end of the array -- +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_error.phpt b/ext/standard/tests/array/key_error.phpt new file mode 100644 index 000000000..ae63bff07 --- /dev/null +++ b/ext/standard/tests/array/key_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test key() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to key() to test behaviour + */ + +echo "*** Testing key() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing key() function with Zero arguments --\n"; +var_dump( key() ); + +//Test current with one more than the expected number of arguments +echo "\n-- Testing key() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( key($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : error conditions *** + +-- Testing key() function with Zero arguments -- + +Warning: Wrong parameter count for key() in %s on line %d +NULL + +-- Testing key() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for key() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_variation1.phpt b/ext/standard/tests/array/key_variation1.phpt new file mode 100644 index 000000000..5b4a367ed --- /dev/null +++ b/ext/standard/tests/array/key_variation1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test key() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to test behaviour of key() + */ + +echo "*** Testing key() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $var1; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( key($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +string(4) "var1" + +-- Iteration 23 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/key_variation2.phpt b/ext/standard/tests/array/key_variation2.phpt new file mode 100644 index 000000000..35389062b --- /dev/null +++ b/ext/standard/tests/array/key_variation2.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where keys are different data types as $array_arg to key() to test behaviour + */ + +echo "*** Testing key() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $array_arg +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + while (key($input) !== NULL) { + var_dump(key($input)); + next($input); + } + $iterator++; +}; +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 : int data -- +int(0) +int(1) +int(12345) +int(-2345) + +-- Iteration 2 : float data -- +int(10) +int(-10) +int(0) + +-- Iteration 3 : extreme floats data -- +int(12345678) +int(0) + +-- Iteration 4 : null uppercase data -- +string(0) "" + +-- Iteration 5 : null lowercase data -- +string(0) "" + +-- Iteration 6 : bool lowercase data -- +int(1) +int(0) + +-- Iteration 7 : bool uppercase data -- +int(1) +int(0) + +-- Iteration 8 : empty double quotes data -- +string(0) "" + +-- Iteration 9 : empty single quotes data -- +string(0) "" + +-- Iteration 10 : string data -- +string(7) "stringd" +string(7) "strings" +string(11) "hello world" + +-- Iteration 11 : undefined data -- +string(0) "" + +-- Iteration 12 : unset data -- +string(0) "" +===DONE=== diff --git a/ext/standard/tests/array/key_variation3.phpt b/ext/standard/tests/array/key_variation3.phpt new file mode 100644 index 000000000..a23191781 --- /dev/null +++ b/ext/standard/tests/array/key_variation3.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing key() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(key($array1)); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; + +next($array1); + +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(key($array1)); +echo "\$array2: "; +var_dump(key($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Initial position of internal pointer -- +int(0) + +-- Position after calling next() -- +$array1: int(1) +$array2: int(1) +===DONE=== diff --git a/ext/standard/tests/array/key_variation4.phpt b/ext/standard/tests/array/key_variation4.phpt new file mode 100644 index 000000000..0ddf05742 --- /dev/null +++ b/ext/standard/tests/array/key_variation4.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test how key() behaves with muti-dimensional and recursive arrays + */ + +echo "*** Testing key() : usage variations ***\n"; + +echo "\n-- Two Dimensional Array --\n"; +$multi_array = array ('zero', array (1, 2, 3), 'two'); +echo "Initial Position: "; +var_dump(key($multi_array)); + +echo "Next Position: "; +next($multi_array); +var_dump(key($multi_array)); + +echo "End Position: "; +end($multi_array); +var_dump(key($multi_array)); + +echo "\n-- Access an Array Within an Array --\n"; +//accessing an array within an array +echo "Initial Position: "; +var_dump(key($multi_array[1])); + +echo "\n-- Recursive, Multidimensional Array --\n"; +//create a recursive array +$multi_array[] = &$multi_array; + +//See where internal pointer is after adding more elements +echo "Current Position: "; +var_dump(key($multi_array)); + +//see if internal pointer is in same position as referenced array +var_dump(key($multi_array[3][3][3])); +// see if internal pointer is in the same position from when accessing this inner array +var_dump(key($multi_array[3][3][3][1])); +$multi_array[3] = null; +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: int(0) +Next Position: int(1) +End Position: int(2) + +-- Access an Array Within an Array -- +Initial Position: int(0) + +-- Recursive, Multidimensional Array -- +Current Position: int(2) +int(2) +int(0) +===DONE=== diff --git a/ext/standard/tests/array/krsort_basic.phpt b/ext/standard/tests/array/krsort_basic.phpt new file mode 100644 index 000000000..913256897 --- /dev/null +++ b/ext/standard/tests/array/krsort_basic.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test krsort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing array of integer/string values to check the basic functionality + * with following flag values : + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( "lemon" => "l", "orange" => "o", "banana" => "b" ); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing krsort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : basic functionality *** + +-- Testing krsort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/krsort_error.phpt b/ext/standard/tests/array/krsort_error.phpt new file mode 100644 index 000000000..1bca5f928 --- /dev/null +++ b/ext/standard/tests/array/krsort_error.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test krsort() function : error conditions +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int asort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing krsort() function with all possible error conditions +*/ + +echo "*** Testing krsort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing krsort() function with zero arguments --\n"; +var_dump( krsort() ); + +//Test krsort with more than the expected number of arguments +echo "\n-- Testing krsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1 => 1, 2 => 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and call krsort with all possible sort flag values +foreach($flags as $key => $flag){ + echo "\n- Sort flag = $key -\n"; + $temp_array = $array_arg; + var_dump( krsort($temp_array,$flag, $extra_arg) ); + var_dump($temp_array); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : error conditions *** + +-- Testing krsort() function with zero arguments -- + +Warning: krsort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing krsort() function with more than expected no. of arguments -- + +- Sort flag = SORT_REGULAR - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_STRING - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_NUMERIC - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/krsort_object.phpt b/ext/standard/tests/array/krsort_object.phpt new file mode 100644 index 000000000..36d8589a8 --- /dev/null +++ b/ext/standard/tests/array/krsort_object.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test krsort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ +/* + * testing krsort() by providing array of integer/string objects with following flag values: + * 1.Defualt flag value + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : object functionality ***\n"; + +// class declaration for integer objects +class Integer +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } +} + +// class declaration for string objects +class String +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects with different key values +$unsorted_int_obj = array ( + 10 => new Integer(11), 20 => new Integer(66), + 3 => new Integer(23), 4 => new Integer(-5), + 50 => new Integer(0.001), 6 => new Integer(0) +); + +// array of string objects with different key values +$unsorted_str_obj = array ( + "axx" => new String("axx"), "t" => new String("t"), + "w" => new String("w"), "py" => new String("py"), + "apple" => new String("apple"), "Orange" => new String("Orange"), + "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") +); + + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing krsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing krsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : object functionality *** + +-- Testing krsort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation1.phpt b/ext/standard/tests/array/krsort_variation1.phpt new file mode 100644 index 000000000..e4cbaf8d2 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation1.phpt @@ -0,0 +1,397 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing different unexpected values for array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +$unexpected_values = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e3, + 10.6E-2, + 0.5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*11*/ true, + false, + TRUE, + FALSE, + + // empty data +/*15*/ "", + '', + + // string data +/*17*/ "string", + 'string', + + // object data +/*19*/ new stdclass(), + + // undefined data +/*20*/ @undefined_var, + + // unset data +/*21*/ @unset_var, + + // resource variable +/*22*/ $fp +); + +// loop though each element of the array and check the working of krsort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing krsort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( krsort($value) ); // expecting : bool(false) + var_dump( krsort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( krsort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( krsort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/krsort_variation10.phpt b/ext/standard/tests/array/krsort_variation10.phpt new file mode 100644 index 000000000..f56d2870b --- /dev/null +++ b/ext/standard/tests/array/krsort_variation10.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test krsort() function : usage variations - sort heredoc strings +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of heredoc strings for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// Different heredoc strings to be sorted +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + +$array = array ( + $simple_heredoc1 => "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt --\n"; +$temp_array = $array; +var_dump(krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} +Done diff --git a/ext/standard/tests/array/krsort_variation11.phpt b/ext/standard/tests/array/krsort_variation11.phpt new file mode 100644 index 000000000..0cfa4821a --- /dev/null +++ b/ext/standard/tests/array/krsort_variation11.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test krsort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of boolean values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// bool value array +$bool_values = array (true => true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying boolean value array, 'flag' value is defualt -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/krsort_variation2.phpt b/ext/standard/tests/array/krsort_variation2.phpt new file mode 100644 index 000000000..c567f766c --- /dev/null +++ b/ext/standard/tests/array/krsort_variation2.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// an array for checking unexpected behavior +$unsorted_values = array(10 => 10, 2 => 2, 45 => 45); + +//array of unexpected values to iterate over +$unexpected_values = array ( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of krsort() +// when 'sort_flags' arugment is supplied with different values +echo "\n-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( krsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 3 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 14 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 15 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 16 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 17 -- + +Warning: krsort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 18 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 19 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 20 -- + +Warning: krsort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/krsort_variation3.phpt b/ext/standard/tests/array/krsort_variation3.phpt new file mode 100644 index 000000000..8f411a973 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation3.phpt @@ -0,0 +1,262 @@ +--TEST-- +Test krsort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing array of integer/float/mixed values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// diff. associative arrays to sort +$various_arrays = array( + // negative/posative integer key value array + array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // float key values + array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2, + -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing krsort() by supplying various integer/float arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +Done diff --git a/ext/standard/tests/array/krsort_variation4.phpt b/ext/standard/tests/array/krsort_variation4.phpt new file mode 100644 index 000000000..3df924ac8 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation4.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of octal values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} +Done diff --git a/ext/standard/tests/array/krsort_variation5.phpt b/ext/standard/tests/array/krsort_variation5.phpt new file mode 100644 index 000000000..59621654c --- /dev/null +++ b/ext/standard/tests/array/krsort_variation5.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test krsort() function : usage variations - sort strings +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of string values for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +$various_arrays = array ( + // diff. escape sequence chars with key values + array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing krsort() by supplying various string arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +Done diff --git a/ext/standard/tests/array/krsort_variation6.phpt b/ext/standard/tests/array/krsort_variation6.phpt new file mode 100644 index 000000000..167d0ee7d --- /dev/null +++ b/ext/standard/tests/array/krsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of hexa-decimal values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// an array containing unsorted hexadecimal values with keys +$unsorted_hex_array = array ( + 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done diff --git a/ext/standard/tests/array/krsort_variation7.phpt b/ext/standard/tests/array/krsort_variation7.phpt new file mode 100644 index 000000000..9ba3fc544 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation7.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test krsort() function : usage variations - sort array with diff. sub arrays +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing arrays contains sub arrays for $array argument + * with flowing flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// array with diff sub arrays to be sorted +$various_arrays = array ( + // null array + 1 => array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation8.phpt b/ext/standard/tests/array/krsort_variation8.phpt Binary files differnew file mode 100644 index 000000000..20276ade6 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation8.phpt diff --git a/ext/standard/tests/array/krsort_variation9.phpt b/ext/standard/tests/array/krsort_variation9.phpt new file mode 100644 index 000000000..d7d8343b0 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation9.phpt @@ -0,0 +1,257 @@ +--TEST-- +Test krsort() function : usage variations - sort array with/without key values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing arrays with/without key values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing krsort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays with/without key values --\n"; + +// loop through to test krsort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With defualt sort flag - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With defualt sort flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With defualt sort flag - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/ksort_basic.phpt b/ext/standard/tests/array/ksort_basic.phpt new file mode 100644 index 000000000..fdc8bd8dc --- /dev/null +++ b/ext/standard/tests/array/ksort_basic.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test ksort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing array of integer/string values to check the basic functionality with following flag values : + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( "lemon" => "l", "orange" => "o", "banana" => "b" ); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing ksort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : basic functionality *** + +-- Testing ksort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- Testing ksort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/ksort_error.phpt b/ext/standard/tests/array/ksort_error.phpt new file mode 100644 index 000000000..f2b102ae0 --- /dev/null +++ b/ext/standard/tests/array/ksort_error.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test ksort() function : error conditions +--FILE-- +<?php +/* Prototype : bool ksort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* +* Testing ksort() function with all possible error conditions +*/ + +echo "*** Testing ksort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing ksort() function with Zero arguments --\n"; +var_dump( ksort() ); + +//Test ksort with more than the expected number of arguments +echo "\n-- Testing ksort() function with more than expected no. of arguments --\n"; +$array_arg = array(1 => 1, 2 => 2); +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and call krsort with all possible sort flag values +foreach($flag_value as $key => $flag){ + echo "\n- Sort flag = $key -\n"; + $temp_array = $array_arg; + var_dump( ksort($temp_array,$flag, $extra_arg) ); + var_dump( $temp_array); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : error conditions *** + +-- Testing ksort() function with Zero arguments -- + +Warning: ksort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing ksort() function with more than expected no. of arguments -- + +- Sort flag = SORT_REGULAR - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_STRING - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_NUMERIC - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/ksort_object.phpt b/ext/standard/tests/array/ksort_object.phpt new file mode 100644 index 000000000..20e8ba26e --- /dev/null +++ b/ext/standard/tests/array/ksort_object.phpt @@ -0,0 +1,241 @@ +--TEST-- +Test ksort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ +/* + * testing ksort() by providing array ofinteger/string objects with following flag values: + * 1.SORT_NUMERIC - compare items numerically + * 2.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : object functionality ***\n"; + +// class declaration for integer objects +class Integer +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class String +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array ( + 11 => new Integer(11), 66 => new Integer(66), + 23 => new Integer(23), -5 => new Integer(-5), + 1 => new Integer(0.001), 0 => new Integer(0) +); + +// array of string objects +$unsorted_str_obj = array ( + "axx" => new String("axx"), "t" => new String("t"), + "w" => new String("w"), "py" => new String("py"), + "apple" => new String("apple"), "Orange" => new String("Orange"), + "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") +); +echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing ksort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +// testing ksort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing ksort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing ksort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : object functionality *** + +-- Testing ksort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [-5]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [-5]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/ext/standard/tests/array/ksort_variation1.phpt b/ext/standard/tests/array/ksort_variation1.phpt new file mode 100644 index 000000000..d8c037fa9 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation1.phpt @@ -0,0 +1,397 @@ +--TEST-- +Test ksort() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : bool ksort(array &array [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing different unexpected values for array argument with following flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +$unexpected_values = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e3, + 10.6E-2, + 0.5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*11*/ true, + false, + TRUE, + FALSE, + + // empty data +/*15*/ "", + '', + + // string data +/*17*/ "string", + 'string', + + // object data +/*19*/ new stdclass(), + + // undefined data +/*20*/ @undefined_var, + + // unset data +/*21*/ @unset_var, + + // resource variable +/*22*/ $fp + +); + +// loop though each element of the array and check the working of ksort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing ksort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( ksort($value) ); // expecting : bool(false) + var_dump( ksort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( ksort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( ksort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/ksort_variation10.phpt b/ext/standard/tests/array/ksort_variation10.phpt new file mode 100644 index 000000000..051bc3061 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation10.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test ksort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of octal values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/ksort_variation11.phpt b/ext/standard/tests/array/ksort_variation11.phpt new file mode 100644 index 000000000..347df65c4 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation11.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test ksort() function : usage variations - sort heredoc strings +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of heredoc strings for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// Different heredoc strings to be sorted +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + +$array = array ( + $simple_heredoc1 => "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' value is defualt --\n"; +$temp_array = $array; +var_dump(ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying heredoc string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/ext/standard/tests/array/ksort_variation2.phpt b/ext/standard/tests/array/ksort_variation2.phpt new file mode 100644 index 000000000..f765977d2 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation2.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test ksort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : bool ksort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// an array for checking unexpected behavior +$unsorted_values = array(10 => 10, 2 => 2, 45 => 45); + +//array of unexpected values to iterate over +$unexpected_values = array ( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of ksort() +// when 'sort_flags' arugment is supplied with different values +echo "\n-- Testing ksort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( ksort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 2 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 3 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 4 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 5 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 6 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 8 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 9 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 10 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 11 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 12 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 13 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 14 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 15 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 16 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 17 -- + +Warning: ksort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 18 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 19 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 20 -- + +Warning: ksort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/ksort_variation3.phpt b/ext/standard/tests/array/ksort_variation3.phpt new file mode 100644 index 000000000..4029b9b8d --- /dev/null +++ b/ext/standard/tests/array/ksort_variation3.phpt @@ -0,0 +1,262 @@ +--TEST-- +Test ksort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing array of integer/float/mixed values for $array argument + * with following flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// diff. associative arrays to sort +$various_arrays = array( + // negative/posative integer key value array + array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // float key values + array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, + 9 => 10.6E-2, -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing ksort() by supplying various integer/float arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +Done diff --git a/ext/standard/tests/array/ksort_variation4.phpt b/ext/standard/tests/array/ksort_variation4.phpt new file mode 100644 index 000000000..d6b3f482b --- /dev/null +++ b/ext/standard/tests/array/ksort_variation4.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test ksort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of boolean values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// bool value array +$bool_values = array (true => true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying boolean value array, 'flag' value is defualt -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/ksort_variation5.phpt b/ext/standard/tests/array/ksort_variation5.phpt new file mode 100644 index 000000000..958476c01 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation5.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test ksort() function : usage variations - sort strings +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of string values for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +$various_arrays = array ( + // diff. escape sequence chars with key values + array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing ksort() by supplying various string arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various string arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\xhh"]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +Done diff --git a/ext/standard/tests/array/ksort_variation6.phpt b/ext/standard/tests/array/ksort_variation6.phpt new file mode 100644 index 000000000..1243ab123 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test ksort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of hexa-decimal values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// an array containng unsorted hexadecimal values with keys +// There are multiple keys which are duplicate and the later should be picked +$unsorted_hex_array = array ( + 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} +Done diff --git a/ext/standard/tests/array/ksort_variation7.phpt b/ext/standard/tests/array/ksort_variation7.phpt new file mode 100644 index 000000000..a0f454bbd --- /dev/null +++ b/ext/standard/tests/array/ksort_variation7.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test ksort() function : usage variations - sort array with diff. sub arrays +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing arrays containing sub arrays for $array argument + * with flowing flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// array with diff sub arrays to be sorted +$various_arrays = array ( + // null array + 1 => array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/ext/standard/tests/array/ksort_variation8.phpt b/ext/standard/tests/array/ksort_variation8.phpt Binary files differnew file mode 100644 index 000000000..787e71d61 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation8.phpt diff --git a/ext/standard/tests/array/ksort_variation9.phpt b/ext/standard/tests/array/ksort_variation9.phpt new file mode 100644 index 000000000..ed406e20b --- /dev/null +++ b/ext/standard/tests/array/ksort_variation9.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test ksort() function : usage variations - sorting arrays with/without keys +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing arrays with/without key values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing ksort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays with/without key values --\n"; + +// loop through to test ksort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} + +-- Iteration 5 -- +- With defualt sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} + +-- Iteration 6 -- +- With defualt sort flag - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} + +-- Iteration 7 -- +- With defualt sort flag - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +Done diff --git a/ext/standard/tests/array/natcasesort_basic.phpt b/ext/standard/tests/array/natcasesort_basic.phpt new file mode 100644 index 000000000..cf6cc5728 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test natcasesort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of natcasesort() + */ + +echo "*** Testing natcasesort() : basic functionality ***\n"; + +$array = array ('A01', 'a1', 'b10', 'a01', 'b01'); +echo "\n-- Before sorting: --\n"; +var_dump($array); + +echo "\n-- After Sorting: --\n"; +var_dump(natcasesort($array)); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : basic functionality *** + +-- Before sorting: -- +array(5) { + [0]=> + string(3) "A01" + [1]=> + string(2) "a1" + [2]=> + string(3) "b10" + [3]=> + string(3) "a01" + [4]=> + string(3) "b01" +} + +-- After Sorting: -- +bool(true) +array(5) { + [3]=> + string(3) "a01" + [0]=> + string(3) "A01" + [1]=> + string(2) "a1" + [4]=> + string(3) "b01" + [2]=> + string(3) "b10" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_error.phpt b/ext/standard/tests/array/natcasesort_error.phpt new file mode 100644 index 000000000..0f18677ca --- /dev/null +++ b/ext/standard/tests/array/natcasesort_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test natcasesort() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to natcasesort() to test behaviour + */ + +echo "*** Testing natcasesort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing natcasesort() function with Zero arguments --\n"; +var_dump( natcasesort() ); + +// Test natcasesort with one more than the expected number of arguments +echo "\n-- Testing natcasesort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( natcasesort($array_arg, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : error conditions *** + +-- Testing natcasesort() function with Zero arguments -- + +Warning: Wrong parameter count for natcasesort() in %s on line %d +NULL + +-- Testing natcasesort() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for natcasesort() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_object1.phpt b/ext/standard/tests/array/natcasesort_object1.phpt new file mode 100644 index 000000000..aab98a45d --- /dev/null +++ b/ext/standard/tests/array/natcasesort_object1.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test natcasesort() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an array of objects to test how it re-orders them + */ + +echo "*** Testing natcasesort() : object functionality ***\n"; + +// class declaration for string objects +class for_string_natcasesort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->class_value; + } + +} + + + +// array of string objects +$unsorted_str_obj = array ( + new for_string_natcasesort("axx"), new for_string_natcasesort("t"), + new for_string_natcasesort("w"), new for_string_natcasesort("py"), + new for_string_natcasesort("apple"), new for_string_natcasesort("Orange"), + new for_string_natcasesort("Lemon"), new for_string_natcasesort("aPPle") +); + + +echo "\n-- Testing natcasesort() by supplying various object arrays --\n"; + +// testing natcasesort() function by supplying string object array +var_dump(natcasesort($unsorted_str_obj) ); +var_dump($unsorted_str_obj); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying various object arrays -- +bool(true) +array(8) { + [4]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [7]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [0]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [6]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [5]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [3]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [1]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_object2.phpt b/ext/standard/tests/array/natcasesort_object2.phpt new file mode 100644 index 000000000..2b4acec25 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_object2.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test natcasesort() function : object functionality - mixed visibility within objects +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an array of objects which have properties of different + * visibilities to test how it re-orders the array. + */ + +echo "*** Testing natcasesort() : object functionality ***\n"; + +// class declaration for string objects +class for_string_natcasesort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->public_class_value; + } + +} + +// array of string objects +$unsorted_str_obj = array ( +new for_string_natcasesort("axx","AXX","ass"), +new for_string_natcasesort("t","eee","abb"), +new for_string_natcasesort("w","W", "c"), +new for_string_natcasesort("py","PY", "pt"), +); + + +echo "\n-- Testing natcasesort() by supplying object arrays --\n"; + +// testing natcasesort() function by supplying string object array +$temp_array = $unsorted_str_obj; +var_dump(natcasesort($temp_array) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying object arrays -- +bool(true) +array(4) { + [0]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value:private"]=> + string(3) "AXX" + ["protected_class_value:protected"]=> + string(3) "ass" + } + [3]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value:private"]=> + string(2) "PY" + ["protected_class_value:protected"]=> + string(2) "pt" + } + [1]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value:private"]=> + string(3) "eee" + ["protected_class_value:protected"]=> + string(3) "abb" + } + [2]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value:private"]=> + string(1) "W" + ["protected_class_value:protected"]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation1.phpt b/ext/standard/tests/array/natcasesort_variation1.phpt new file mode 100644 index 000000000..f6019508c --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test natcasesort() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to natcasesort() to test behaviour + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +bool(true) + +-- Iteration 19 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- +bool(true) + +-- Iteration 23 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation10.phpt b/ext/standard/tests/array/natcasesort_variation10.phpt new file mode 100644 index 000000000..cffa007b7 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation10.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test natcasesort() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Check position of internal array pointer after calling natcasesort() + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +$array_arg = array ('img13', 'img20', 'img2', 'img1'); + +echo "\n-- Initial Position of Internal Pointer: --\n"; +echo key($array_arg) . " => " . current ($array_arg) . "\n"; + +echo "\n-- Call natcasesort() --\n"; +var_dump(natcasesort($array_arg)); +var_dump($array_arg); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($array_arg) . " => " . current ($array_arg) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variations *** + +-- Initial Position of Internal Pointer: -- +0 => img13 + +-- Call natcasesort() -- +bool(true) +array(4) { + [3]=> + string(4) "img1" + [2]=> + string(4) "img2" + [0]=> + string(5) "img13" + [1]=> + string(5) "img20" +} + +-- Position of Internal Pointer in Passed Array: -- +3 => img1 +Done diff --git a/ext/standard/tests/array/natcasesort_variation11.phpt b/ext/standard/tests/array/natcasesort_variation11.phpt new file mode 100644 index 000000000..98158f15d --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation11.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test natcasesort() function : usage variations - Different array keys +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where the keys are different data types to test behaviour of natcasesort() + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays with keys as different data types to be passed as $array_arg +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), + + // duplicate values +/*13*/ 'duplicate' => array( + 'foo' => 'bar', + 'baz' => 'bar', + 'hello' => 'world' + ), + +); + +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variations *** + +-- Iteration 1 -- +bool(true) +array(4) { + [-2345]=> + string(8) "negative" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [0]=> + string(4) "zero" +} + +-- Iteration 2 -- +bool(true) +array(3) { + [0]=> + string(4) "half" + [-10]=> + string(8) "negative" + [10]=> + string(8) "positive" +} + +-- Iteration 3 -- +bool(true) +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} + +-- Iteration 4 -- +bool(true) +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 -- +bool(true) +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 -- +bool(true) +array(2) { + [0]=> + string(6) "lowerf" + [1]=> + string(6) "lowert" +} + +-- Iteration 7 -- +bool(true) +array(2) { + [0]=> + string(6) "upperf" + [1]=> + string(6) "uppert" +} + +-- Iteration 8 -- +bool(true) +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 -- +bool(true) +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 -- +bool(true) +array(3) { + ["stringd"]=> + string(7) "stringd" + ["hello world"]=> + string(7) "stringh" + ["strings"]=> + string(7) "strings" +} + +-- Iteration 11 -- +bool(true) +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 -- +bool(true) +array(1) { + [""]=> + string(5) "unset" +} + +-- Iteration 13 -- +bool(true) +array(3) { + ["foo"]=> + string(3) "bar" + ["baz"]=> + string(3) "bar" + ["hello"]=> + string(5) "world" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation2.phpt b/ext/standard/tests/array/natcasesort_variation2.phpt new file mode 100644 index 000000000..00edf9434 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test natcasesort() function : usage variations - Pass arrays of different data types +--FILE-- +<?php + +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types to natcasesort() to test how they are sorted + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + var_dump($input); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(4) { + [3]=> + int(-2345) + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) +} + +-- Iteration 2 -- +bool(true) +array(5) { + [1]=> + float(-10.5) + [4]=> + float(0.5) + [3]=> + float(1.23456789E-9) + [0]=> + float(10.5) + [2]=> + float(123456789000) +} + +-- Iteration 3 -- +bool(true) +array(2) { + [1]=> + NULL + [0]=> + NULL +} + +-- Iteration 4 -- +bool(true) +array(4) { + [3]=> + bool(false) + [1]=> + bool(false) + [0]=> + bool(true) + [2]=> + bool(true) +} + +-- Iteration 5 -- +bool(true) +array(2) { + [1]=> + string(0) "" + [0]=> + string(0) "" +} + +-- Iteration 6 -- +bool(true) +array(0) { +} + +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + string(11) "hello world" + [1]=> + string(6) "string" + [0]=> + string(6) "string" +} + +-- Iteration 8 -- +bool(true) +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 11 -- +bool(true) +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation3.phpt b/ext/standard/tests/array/natcasesort_variation3.phpt new file mode 100644 index 000000000..f15150843 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation3.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test natcasesort() function : usage variations - different numeric types +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of numeric data to test how natcasesort re-orders the array + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$inputs = array ( + + // negative/positive integers array + array(11, -11, 21, -21, 31, -31, 0, 41, -41), + + // float value array + array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1), + + // mixed value array + array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33), + + // array values contains minimum and maximum ranges + array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649) +); + +$iterator = 1; +foreach ($inputs as $array_arg) { + echo "\n-- Iteration $iterator --\n"; + var_dump(natcasesort($array_arg)); + var_dump($array_arg); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(9) { + [1]=> + int(-11) + [3]=> + int(-21) + [5]=> + int(-31) + [8]=> + int(-41) + [6]=> + int(0) + [0]=> + int(11) + [2]=> + int(21) + [4]=> + int(31) + [7]=> + int(41) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [6]=> + float(-0.1) + [1]=> + float(-10.5) + [5]=> + float(0.01) + [4]=> + float(0.5) + [3]=> + float(0.106) + [0]=> + float(10.5) + [2]=> + float(1050) +} + +-- Iteration 1 -- +bool(true) +array(11) { + [2]=> + float(-0.01) + [7]=> + float(-0.9) + [9]=> + float(-0.106) + [3]=> + int(-1) + [4]=> + int(0) + [0]=> + float(0.0001) + [1]=> + float(0.0021) + [5]=> + float(0.09) + [8]=> + float(0.106) + [6]=> + int(2) + [10]=> + int(33) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [2]=> + int(-2147483647) + [3]=> + float(-2147483648) + [6]=> + float(-2147483649) + [5]=> + int(0) + [4]=> + int(0) + [0]=> + int(2147483647) + [1]=> + float(2147483648) +} +Done diff --git a/ext/standard/tests/array/natcasesort_variation4.phpt b/ext/standard/tests/array/natcasesort_variation4.phpt new file mode 100644 index 000000000..81276ef1c --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation4.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test natcasesort() function : usage variations - different string types +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of string data to see how natcasesort() re-orders the array + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$inputs = array ( + // group of escape sequences + array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"), + + // array contains combination of capital/small letters + array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") +); + +foreach ($inputs as $array_arg) { + var_dump( natcasesort($array_arg) ); + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [0]=> + NULL + [1]=> + NULL + [6]=> + string(1) " +" + [10]=> + string(1) "" + [7]=> + string(1) " " + [5]=> + string(1) "" + [2]=> + string(2) "\a" + [3]=> + string(3) "\cx" + [9]=> + string(4) "\ddd" + [4]=> + string(2) "\e" + [8]=> + string(4) "\xhh" +} +bool(true) +array(12) { + [3]=> + string(5) "apple" + [11]=> + string(6) "BANANA" + [2]=> + string(6) "banana" + [0]=> + string(5) "lemoN" + [10]=> + string(6) "oraNGe" + [1]=> + string(6) "Orange" + [4]=> + string(4) "Test" + [6]=> + string(3) "ttt" + [5]=> + string(4) "TTTT" + [7]=> + string(2) "ww" + [8]=> + string(1) "x" + [9]=> + string(1) "X" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation5.phpt b/ext/standard/tests/array/natcasesort_variation5.phpt new file mode 100644 index 000000000..867d0b89e --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation5.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test natcasesort() function : usage variations - different hex values +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of different hex values to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa); +var_dump( natcasesort($unsorted_hex_array) ); +var_dump($unsorted_hex_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [8]=> + int(-255) + [10]=> + int(-682) + [9]=> + int(0) + [2]=> + int(15) + [5]=> + int(187) + [3]=> + int(255) + [7]=> + int(255) + [0]=> + int(427) + [6]=> + int(427) + [4]=> + int(682) + [1]=> + int(4095) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation6.phpt b/ext/standard/tests/array/natcasesort_variation6.phpt new file mode 100644 index 000000000..1d151d80d --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation6.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test natcasesort() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of referenced varaibles to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +echo "\n-- Initial test --\n"; +$array = array( &$value1 , &$value2, &$value3); +var_dump( natcasesort($array) ); +var_dump($array); + +echo "\n-- Change \$value1 --\n"; +$value1 = -29; +var_dump( natcasesort($array) ); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Initial test -- +bool(true) +array(3) { + [1]=> + &int(33) + [0]=> + &int(100) + [2]=> + &int(555) +} + +-- Change $value1 -- +bool(true) +array(3) { + [0]=> + &int(-29) + [1]=> + &int(33) + [2]=> + &int(555) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation7.phpt b/ext/standard/tests/array/natcasesort_variation7.phpt new file mode 100644 index 000000000..eefcd1d6f --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test natcasesort() function : usage variations - recursive arrays +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an infinitely recursive array to test how it is re-ordered + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +$array = array (1, 3.00, 'zero', '2'); +$array[] = &$array; +var_dump($array); + +var_dump(@natcasesort($array)); +var_dump($array); + +$array[4] = null; + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variations *** +array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + &array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + &array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + *RECURSION* + } + } +} +bool(true) +array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + &array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + &array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + *RECURSION* + [2]=> + string(4) "zero" + } + [2]=> + string(4) "zero" + } + [2]=> + string(4) "zero" +} +Done diff --git a/ext/standard/tests/array/natcasesort_variation8.phpt b/ext/standard/tests/array/natcasesort_variation8.phpt new file mode 100644 index 000000000..fbced4a22 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation8.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test natcasesort() function : usage variations - octal values +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of octal values to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0); + +var_dump( natcasesort($unsorted_oct_array) ); +var_dump($unsorted_oct_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(9) { + [6]=> + int(-54) + [7]=> + int(-229) + [8]=> + int(0) + [3]=> + int(54) + [5]=> + int(63) + [1]=> + int(209) + [2]=> + int(229) + [4]=> + int(506) + [0]=> + int(669) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation9.phpt b/ext/standard/tests/array/natcasesort_variation9.phpt new file mode 100644 index 000000000..98eec05a0 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation9.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test natcasesort() function : usage variations - mixed array +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array containing sub-arrays, ints, floats, strings, boolean, null + * and escape characters to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$mixed_values = array ( + array(), + array( array(33, -5, 6), + array(11), + array(22, -55), + array() + ), + -4, "4", 4.00, "b", "5", -2, -2.0, -2.98989, "-.9", "True", "", + NULL, "ab", "abcd", 0.0, -0, "abcd\x00abcd\x00abcd", '', true, false +); +// suppress errors as is generating a lot of "array to string" notices +var_dump( @natcasesort($mixed_values) ); + +var_dump($mixed_values); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(22) { + [13]=> + NULL + [19]=> + string(0) "" + [21]=> + bool(false) + [12]=> + string(0) "" + [10]=> + string(3) "-.9" + [7]=> + int(-2) + [8]=> + float(-2) + [9]=> + float(-2.98989) + [2]=> + int(-4) + [16]=> + float(0) + [17]=> + int(0) + [20]=> + bool(true) + [3]=> + string(1) "4" + [4]=> + float(4) + [6]=> + string(1) "5" + [14]=> + string(2) "ab" + [15]=> + string(4) "abcd" + [18]=> + string(14) "%s" + [0]=> + array(0) { + } + [1]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [5]=> + string(1) "b" + [11]=> + string(4) "True" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/next_basic.phpt b/ext/standard/tests/array/next_basic.phpt new file mode 100644 index 000000000..fe8b70c88 --- /dev/null +++ b/ext/standard/tests/array/next_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test next() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of next() + */ + +echo "*** Testing next() : basic functionality ***\n"; + +$array = array('zero', 'one', 'two'); +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : basic functionality *** +0 => zero +string(3) "one" +1 => one +string(3) "two" +2 => two +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/next_error.phpt b/ext/standard/tests/array/next_error.phpt new file mode 100644 index 000000000..ba7596feb --- /dev/null +++ b/ext/standard/tests/array/next_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test next() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to next() to test behaviour + */ + +echo "*** Testing next() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing next() function with Zero arguments --\n"; +var_dump( next() ); + +//Test next with one more than the expected number of arguments +echo "\n-- Testing next() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( next($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : error conditions *** + +-- Testing next() function with Zero arguments -- + +Warning: Wrong parameter count for next() in %s on line %d +NULL + +-- Testing next() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for next() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/next_variation1.phpt b/ext/standard/tests/array/next_variation1.phpt new file mode 100644 index 000000000..aa02ac599 --- /dev/null +++ b/ext/standard/tests/array/next_variation1.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test next() function : usage variation - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to next() to test behaviour + */ + +echo "*** Testing next() : variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of next() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( next($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : variation *** + +-- Iteration 1 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/next_variation2.phpt b/ext/standard/tests/array/next_variation2.phpt new file mode 100644 index 000000000..e7505096d --- /dev/null +++ b/ext/standard/tests/array/next_variation2.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test next() function : usage variation - Mulit-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test next() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing next() : usage variations ***\n"; + +$array_arg = array ('a' => 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(next($array_arg)); +var_dump(next($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(next($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) +===DONE=== diff --git a/ext/standard/tests/array/reset_basic.phpt b/ext/standard/tests/array/reset_basic.phpt new file mode 100644 index 000000000..d376e68a2 --- /dev/null +++ b/ext/standard/tests/array/reset_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test reset() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of reset() + */ + +echo "*** Testing reset() : basic functionality ***\n"; + +$array = array('zero', 'one', 200 => 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to next() --\n"; +var_dump(next($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to reset() --\n"; +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to next() -- +string(3) "one" + +-- Current Position: -- +1 => one + +-- Call to reset() -- +string(4) "zero" +===DONE=== diff --git a/ext/standard/tests/array/reset_error.phpt b/ext/standard/tests/array/reset_error.phpt new file mode 100644 index 000000000..1bf0f9613 --- /dev/null +++ b/ext/standard/tests/array/reset_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test reset() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to reset() to test behaviour + */ + +echo "*** Testing reset() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing reset() function with Zero arguments --\n"; +var_dump( reset() ); + +//Test reset with one more than the expected number of arguments +echo "\n-- Testing reset() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( reset($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : error conditions *** + +-- Testing reset() function with Zero arguments -- + +Warning: Wrong parameter count for reset() in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for reset() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/reset_variation1.phpt b/ext/standard/tests/array/reset_variation1.phpt new file mode 100644 index 000000000..0dc99512e --- /dev/null +++ b/ext/standard/tests/array/reset_variation1.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test reset() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to reset() to test behaviour + */ + +echo "*** Testing reset() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of reset() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( reset($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Iteration 1 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 2 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 3 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 4 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 5 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 6 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 7 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 8 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 9 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 10 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 11 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 12 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 13 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 14 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 15 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 16 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 17 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 20 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 21 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 24 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 25 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/reset_variation2.phpt b/ext/standard/tests/array/reset_variation2.phpt new file mode 100644 index 000000000..1384affa9 --- /dev/null +++ b/ext/standard/tests/array/reset_variation2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test reset() function : usage variations - unset first element +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Unset first element of an array and test behaviour of reset() + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array = array('a', 'b', 'c'); + +echo "\n-- Initial Position: --\n"; +echo current($array) . " => " . key($array) . "\n"; + +echo "\n-- Unset First element in array and check reset() --\n"; +unset($array[0]); +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial Position: -- +a => 0 + +-- Unset First element in array and check reset() -- +string(1) "b" +===DONE=== diff --git a/ext/standard/tests/array/reset_variation3.phpt b/ext/standard/tests/array/reset_variation3.phpt new file mode 100644 index 000000000..29f965abe --- /dev/null +++ b/ext/standard/tests/array/reset_variation3.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test reset() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Reference two arrays to each other then call reset() to test position of + * internal pointer in both arrays + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; + +next($array1); + +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); + +echo "\n-- Position after calling reset() --\n"; +var_dump(reset($array1)); +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" + +-- Position after calling reset() -- +string(4) "zero" +$array1: string(4) "zero" +$array2: string(4) "zero" +===DONE=== diff --git a/ext/standard/tests/array/rsort_basic.phpt b/ext/standard/tests/array/rsort_basic.phpt new file mode 100644 index 000000000..5495be925 --- /dev/null +++ b/ext/standard/tests/array/rsort_basic.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test rsort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of rsort() + */ + +echo "*** Testing rsort() : basic functionality ***\n"; + +// associative array containing unsorted string values +$unsorted_strings = array( "l" => "lemon", "o" => "orange", "b" => "banana" ); + +// array with default keys containing unsorted numeric values +$unsorted_numerics = array( 100, 33, 555, 22 ); + +echo "\n-- Testing rsort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_STRING) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_NUMERIC) ); +var_dump( $temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : basic functionality *** + +-- Testing rsort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + string(6) "banana" +} + +-- Testing rsort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + string(6) "banana" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + string(6) "banana" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_error.phpt b/ext/standard/tests/array/rsort_error.phpt new file mode 100644 index 000000000..6f6f2f976 --- /dev/null +++ b/ext/standard/tests/array/rsort_error.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test rsort() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to rsort() to test behaviour + */ + +echo "*** Testing rsort() : error conditions ***\n"; + +// zero arguments +echo "\n-- Testing rsort() function with Zero arguments --\n"; +var_dump( rsort() ); + +//Test rsort() with more than the expected number of arguments +echo "\n-- Testing rsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$sort_flags = SORT_REGULAR; +$extra_arg = 10; +var_dump( rsort($array_arg, $sort_flags, $extra_arg) ); + +// dump the input array to ensure that it wasn't changed +var_dump($array_arg); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : error conditions *** + +-- Testing rsort() function with Zero arguments -- + +Warning: rsort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing rsort() function with more than expected no. of arguments -- + +Warning: rsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_object1.phpt b/ext/standard/tests/array/rsort_object1.phpt new file mode 100644 index 000000000..98f7cfec1 --- /dev/null +++ b/ext/standard/tests/array/rsort_object1.phpt @@ -0,0 +1,243 @@ +--TEST-- +Test rsort() function : object functionality +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of rsort() with objects + */ + +echo "*** Testing rsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_rsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class for_string_rsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array( + new for_integer_rsort(11), new for_integer_rsort(66), + new for_integer_rsort(23), new for_integer_rsort(-5), + new for_integer_rsort(0.001), new for_integer_rsort(0) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_rsort("axx"), new for_string_rsort("t"), + new for_string_rsort("w"), new for_string_rsort("py"), + new for_string_rsort("apple"), new for_string_rsort("Orange"), + new for_string_rsort("Lemon"), new for_string_rsort("aPPle") +); + + +echo "\n-- Sort flag = default --\n"; + +// testing rsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +// testing rsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_object2.phpt b/ext/standard/tests/array/rsort_object2.phpt new file mode 100644 index 000000000..216d3c910 --- /dev/null +++ b/ext/standard/tests/array/rsort_object2.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test rsort() function : object functionality - different visibilities +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test functionality of rsort() with objects where properties have different visibilities + */ + +echo "*** Testing rsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_rsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + +} + +// class declaration for string objects +class for_string_rsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects + +$unsorted_int_obj = array( + new for_integer_rsort(11,33,30), + new for_integer_rsort(66,44,4), + new for_integer_rsort(-88,-5,5), + new for_integer_rsort(0.001,99.5,0.1) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_rsort("axx","AXX","ass"), + new for_string_rsort("t","eee","abb"), + new for_string_rsort("w","W", "c"), + new for_string_rsort("py","PY", "pt"), +); + + +echo "\n-- Sort flag = default --\n"; + +// testing rsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +// testing rsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value:private"]=> + int(44) + ["protected_class_value:protected"]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value:private"]=> + int(33) + ["protected_class_value:protected"]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value:private"]=> + float(99.5) + ["protected_class_value:protected"]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value:private"]=> + int(-5) + ["protected_class_value:protected"]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value:private"]=> + string(1) "W" + ["protected_class_value:protected"]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value:private"]=> + string(3) "eee" + ["protected_class_value:protected"]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value:private"]=> + string(2) "PY" + ["protected_class_value:protected"]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value:private"]=> + string(3) "AXX" + ["protected_class_value:protected"]=> + string(3) "ass" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value:private"]=> + int(44) + ["protected_class_value:protected"]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value:private"]=> + int(33) + ["protected_class_value:protected"]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value:private"]=> + float(99.5) + ["protected_class_value:protected"]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value:private"]=> + int(-5) + ["protected_class_value:protected"]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value:private"]=> + string(1) "W" + ["protected_class_value:protected"]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value:private"]=> + string(3) "eee" + ["protected_class_value:protected"]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value:private"]=> + string(2) "PY" + ["protected_class_value:protected"]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value:private"]=> + string(3) "AXX" + ["protected_class_value:protected"]=> + string(3) "ass" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation1.phpt b/ext/standard/tests/array/rsort_variation1.phpt new file mode 100644 index 000000000..96dac90ae --- /dev/null +++ b/ext/standard/tests/array/rsort_variation1.phpt @@ -0,0 +1,514 @@ +--TEST-- +Test rsort() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of rsort() +$iterator = 1; +foreach ($inputs as $input) { + echo "-- Iteration $iterator --\n"; + echo "Flag = default:\n"; + var_dump( rsort($input) ); + echo "Flag = SORT_REGULAR:\n"; + var_dump( rsort($input, SORT_REGULAR) ); + echo "Flag = SORT_NUMERIC:\n"; + var_dump( rsort($input, SORT_NUMERIC) ); + echo "Flag = SORT_STRING:\n"; + var_dump( rsort($input, SORT_STRING) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** +-- Iteration 1 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 21 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 22 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 23 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 24 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation10.phpt b/ext/standard/tests/array/rsort_variation10.phpt new file mode 100644 index 000000000..ccf886b07 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation10.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test rsort() function : usage variations - Octal values +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() an array containing octal values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0); + +echo "\n-- Sort flag = default --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Sort flag = default -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_NUMERIC -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation11.phpt b/ext/standard/tests/array/rsort_variation11.phpt Binary files differnew file mode 100644 index 000000000..83bbf84df --- /dev/null +++ b/ext/standard/tests/array/rsort_variation11.phpt diff --git a/ext/standard/tests/array/rsort_variation2.phpt b/ext/standard/tests/array/rsort_variation2.phpt new file mode 100644 index 000000000..2196a6494 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation2.phpt @@ -0,0 +1,484 @@ +--TEST-- +Test rsort() function : usage variations - Pass different data types as $sort_flags arg +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $sort_flags argument to rsort() to test behaviour + * Where possible, 'SORT_NUMERIC' has been entered as a string value + */ + +echo "*** Testing rsort() : variation ***\n"; + +// Initialise function arguments not being substituted +$array_arg = array (1, 5, 2, 3, 1); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "SORT_NUMERIC"; + } +} + +// heredoc string +$heredoc = <<<EOT +SORT_NUMERIC +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $sort_flags argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "SORT_NUMERIC", + 'SORT_NUMERIC', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of rsort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + + //create temporary array in case rsort() works + $temp = $array_arg; + + var_dump( rsort($temp, $input) ); + var_dump($temp); + $iterator++; + + $temp = null; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 2 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 3 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 4 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 5 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 6 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 7 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 8 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 9 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 10 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 11 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 12 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 13 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 14 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 15 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 16 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 17 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 18 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 19 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 20 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 21 -- + +Warning: rsort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 22 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 23 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 24 -- + +Warning: rsort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation3.phpt b/ext/standard/tests/array/rsort_variation3.phpt new file mode 100644 index 000000000..798e148c7 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation3.phpt @@ -0,0 +1,325 @@ +--TEST-- +Test rsort() function : usage variations - numeric values +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays containing different numeric data to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// group of various arrays + +$various_arrays = array ( +// negative/positive integers array +array(11, -11, 21, -21, 31, -31, 0, 41, -41), + +// float value array +array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1), + +// mixed value array +array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33), + +// array values contains minimum and maximum ranges +array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; + +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Defualt sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Defualt sort flag - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} + +-- Iteration 2 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} + +-- Iteration 3 -- +- With Defualt sort flag - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} + +-- Iteration 4 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +Done diff --git a/ext/standard/tests/array/rsort_variation4.phpt b/ext/standard/tests/array/rsort_variation4.phpt new file mode 100644 index 000000000..4cab1a933 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation4.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test rsort() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test behaviour of rsort() when: + * 1. passed an array of referenced variables + * 2. $array_arg is a reference to another array + * 3. $array_arg is passed by reference + */ + +echo "*** Testing rsort() : variation ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( &$value1 , &$value2, &$value3); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort(&$temp_array, SORT_NUMERIC) ); +var_dump( $temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done diff --git a/ext/standard/tests/array/rsort_variation5.phpt b/ext/standard/tests/array/rsort_variation5.phpt new file mode 100644 index 000000000..eba6bc420 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation5.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test rsort() function : usage variations - String values +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays containing different string data to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +$various_arrays = array ( +// group of escape sequences +array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"), + +// array contains combination of capital/small letters +array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation6.phpt b/ext/standard/tests/array/rsort_variation6.phpt new file mode 100644 index 000000000..559a1ebaf --- /dev/null +++ b/ext/standard/tests/array/rsort_variation6.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test rsort() function : usage variations - Hexadecimal vales +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() an array of hexadecimal values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// an array contains unsorted hexadecimal values +$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation7.phpt b/ext/standard/tests/array/rsort_variation7.phpt new file mode 100644 index 000000000..a996bf6db --- /dev/null +++ b/ext/standard/tests/array/rsort_variation7.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test rsort() function : usage variations - boolean values +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() arrays of boolean values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// bool value array +$bool_values = array (true, false, TRUE, FALSE); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation8.phpt b/ext/standard/tests/array/rsort_variation8.phpt new file mode 100644 index 000000000..a4f94b5f0 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test rsort() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() multi-dimensional arrays to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + array(), + + // array contains null sub array + array( array() ), + + // array of arrays along with some values + array(44, 11, array(64, 61) ), + + // array containing sub arrays + array(array(33, -5, 6), array(11), array(22, -55), array() ) +); + + +$count = 1; + +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + + echo "\n-- 'flag' value is default --\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + echo "\n-- 'flag' value is SORT_REGULAR --\n"; + $temp_array = $array; + var_dump(rsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- + +-- 'flag' value is default -- +bool(true) +array(0) { +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(0) { +} + +-- Iteration 2 -- + +-- 'flag' value is default -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 3 -- + +-- 'flag' value is default -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- Iteration 4 -- + +-- 'flag' value is default -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation9.phpt b/ext/standard/tests/array/rsort_variation9.phpt new file mode 100644 index 000000000..c08791df1 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation9.phpt @@ -0,0 +1,259 @@ +--TEST-- +Test rsort() function : usage variations - mixed associative arrays +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() associative arrays to test key re-assignment + */ + +echo "*** Testing rsort() : variation ***\n"; + +// Associative arrays +$various_arrays = array( + // numeric assoc. only array + array(5 => 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11), + + // two-dimensional assoc. and default key array + array("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), + "numbers" => array(1, 2, 3, 4, 5, 6), + "holes" => array("first", 5 => "second", "third")), + + // numeric assoc. and default key array + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + + // mixed assoc. array + array('bar' => 'baz', "foo" => 1), + + // assoc. only multi-dimensional array + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; + +// loop through to test rsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "-- Sort flag = default --\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + echo "-- Sort flag = SORT_REGULAR --\n"; + $temp_array = $array; + var_dump(rsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +-- Sort flag = default -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} + +-- Iteration 2 -- +-- Sort flag = default -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [2]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [2]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } +} + +-- Iteration 3 -- +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} + +-- Iteration 4 -- +-- Sort flag = default -- +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} + +-- Iteration 5 -- +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/sizeof_basic1.phpt b/ext/standard/tests/array/sizeof_basic1.phpt new file mode 100644 index 000000000..dea4a68ea --- /dev/null +++ b/ext/standard/tests/array/sizeof_basic1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test sizeof() function : basic functionality - for scalar types +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is + * installed, it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +/* Testing the sizeof() for some of the scalar types(integer, float) values + * in default, COUNT_NORMAL and COUNT_RECURSIVE modes. + */ + +echo "*** Testing sizeof() : basic functionality ***\n"; + +$intval = 10; +$floatval = 10.5; +$stringval = "String"; + +echo "-- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($intval) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($intval, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($intval, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($floatval) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($floatval, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($floatval, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : basic functionality *** +-- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- +default mode: int(1) + +COUNT_NORMAL mode: int(1) + +COUNT_RECURSIVE mode: int(1) + +-- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- +default mode: int(1) + +COUNT_NORMAL mode: int(1) + +COUNT_RECURSIVE mode: int(1) +Done diff --git a/ext/standard/tests/array/sizeof_basic2.phpt b/ext/standard/tests/array/sizeof_basic2.phpt new file mode 100644 index 000000000..a2ab2eedf --- /dev/null +++ b/ext/standard/tests/array/sizeof_basic2.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test sizeof() function : basic functionality - for non-scalar type(array) +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is + * installed, it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +/* Testing the sizeof() for non-scalar type(array) value + * in default, COUNT_NORMAL and COUNT_RECURSIVE modes. + * Sizeof() has been tested for simple integer, string, + * indexed and mixed arrays. + */ + +echo "*** Testing sizeof() : basic functionality ***\n"; + +$int_array = array(1, 2, 3, 4); +$string_array = array("Saffron", "White", "Green"); +$indexed_array = array("Agression" => "Saffron", "Peace" => "White", "Growth" => "Green"); +$mixed_array = array(1, 2, "Aggression" => "Saffron", 10 => "Ten", "Ten" => 10); + +echo "-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($int_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($int_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($int_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($string_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($string_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($string_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($indexed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($indexed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($indexed_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($mixed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($mixed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($mixed_array, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : basic functionality *** +-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(4) + +COUNT_NORMAL mode: int(4) + +COUNT_RECURSIVE mode: int(4) + +-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(5) + +COUNT_NORMAL mode: int(5) + +COUNT_RECURSIVE mode: int(5) +Done diff --git a/ext/standard/tests/array/sizeof_error.phpt b/ext/standard/tests/array/sizeof_error.phpt new file mode 100644 index 000000000..79a75f315 --- /dev/null +++ b/ext/standard/tests/array/sizeof_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test sizeof() function : error conditions +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP Library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +// Calling sizeof() with zero and more than expected arguments . + +echo "*** Testing sizeof() : error conditions ***\n"; + +echo "-- Testing sizeof() with zero arguments --\n"; +var_dump( sizeof() ); +echo "-- Testing sizeof() function with more than two arguments under COUNT_NORMAL mode --\n"; +$var = 100; +$extra_arg = 10;; +var_dump( sizeof($var, COUNT_NORMAL, $extra_arg) ); +echo "-- Testing sizeof() function with more than two arguments under COUNT_RECURSIVE mode --\n"; +var_dump( sizeof($var, COUNT_RECURSIVE, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : error conditions *** +-- Testing sizeof() with zero arguments -- + +Warning: sizeof() expects at least 1 parameter, 0 given in %s on line %d +NULL +-- Testing sizeof() function with more than two arguments under COUNT_NORMAL mode -- + +Warning: sizeof() expects at most 2 parameters, 3 given in %s on line %d +NULL +-- Testing sizeof() function with more than two arguments under COUNT_RECURSIVE mode -- + +Warning: sizeof() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/sizeof_object1.phpt b/ext/standard/tests/array/sizeof_object1.phpt new file mode 100644 index 000000000..470599605 --- /dev/null +++ b/ext/standard/tests/array/sizeof_object1.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test sizeof() function : object functionality - object with Countable interface +--SKIPIF-- +<?php +// Skip the test case if Standard PHP Library(spl) is not installed + if( !extension_loaded('spl')) + { + die('skip spl is not installed'); + } +?> +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : object functionality ***\n"; + +echo "-- Testing sizeof() with an object which implements Countable interface --\n"; +class sizeof_class implements Countable +{ + public $member1; + private $member2; + protected $member3; + + public function count() + { + return 3; // return the count of member variables in the object + } +} + +$obj = new sizeof_class(); + +echo "-- Testing sizeof() in default mode --\n"; +var_dump( sizeof($obj) ); +echo "-- Testing sizeof() in COUNT_NORMAL mode --\n"; +var_dump( sizeof($obj, COUNT_NORMAL) ); +echo "-- Testing sizeof() in COUNT_RECURSIVE mode --\n"; +var_dump( sizeof($obj, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : object functionality *** +-- Testing sizeof() with an object which implements Countable interface -- +-- Testing sizeof() in default mode -- +int(3) +-- Testing sizeof() in COUNT_NORMAL mode -- +int(3) +-- Testing sizeof() in COUNT_RECURSIVE mode -- +int(3) +Done diff --git a/ext/standard/tests/array/sizeof_object2.phpt b/ext/standard/tests/array/sizeof_object2.phpt new file mode 100644 index 000000000..e2c0816c6 --- /dev/null +++ b/ext/standard/tests/array/sizeof_object2.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test sizeof() function : object functionality - objects without Countable interface +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : object functionality ***\n"; + +echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n"; + +// class without member +class test +{ + // no members +} + +// class with only members and with out member functions +class test1 +{ + public $member1; + var $var1; + private $member2; + protected $member3; + + // no member functions +} + +// class with only member functions +class test2 +{ + // no data members + + public function display() + { + echo " Class Name : test2\n"; + } +} + +// child class which inherits parent test2 +class child_test2 extends test2 +{ + public $child_member1; + private $child_member2; +} + +// abstract class +abstract class abstract_class +{ + public $member1; + private $member2; + + abstract protected function display(); +} + +// implement abstract 'abstract_class' class +class concrete_class extends abstract_class +{ + protected function display() + { + echo " class name is : concrete_class \n "; + } +} + +$objects = array ( + /* 1 */ new test(), + new test1(), + new test2(), + new child_test2(), + /* 5 */ new concrete_class() +); + +$counter = 1; +for($i = 0; $i < count($objects); $i++) +{ + echo "-- Iteration $counter --\n"; + $var = $objects[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : object functionality *** +--- Testing sizeof() with objects which doesn't implement Countable interface --- +-- Iteration 1 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 2 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 3 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 4 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 5 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +Done diff --git a/ext/standard/tests/array/sizeof_variation1.phpt b/ext/standard/tests/array/sizeof_variation1.phpt new file mode 100644 index 000000000..328645f9e --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation1.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test sizeof() function : usage variations - for all scalar types and resource variable +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode ---\n"; +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// array containing all scalar types +$values = array ( + // int values + /* 1 */ 0, + 1, + + // float values + /* 3 */ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + /* 7 */ .5, + + // NULL values + /* 8 */ NULL, + null, + + // boolean values + /* 10 */ TRUE, + FALSE, + true, + /* 13 */ false, + + // string data + /* 14 */ "", + '', + "string", + /* 17 */ 'string', + + // undefined variable + @$undefined_var, + + // resource variable + /* 19 */ $fp +); + +// loop through the each value of the array for 'var' argument and check the behaviour of sizeof() +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + + $var = $values[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode --- +-- Iteration 1 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 2 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 3 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 4 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 5 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 6 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 7 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 8 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 9 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 10 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 11 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 12 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 13 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 14 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 15 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 16 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 17 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 18 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 19 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +Done diff --git a/ext/standard/tests/array/sizeof_variation2.phpt b/ext/standard/tests/array/sizeof_variation2.phpt new file mode 100644 index 000000000..a22457978 --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation2.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test sizeof() function : usage variations - different array values for 'var' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +echo "--- Testing sizeof() with different array values for 'var' argument ---\n"; + +// array containing different types of array values for 'var' argument +$values = array ( + /* 1 */ array($fp, "resource" => $fp), + array(1, array(3, 4, array(6, array(8)))), + array("a" => 1, 'b' => 2, array( "c" =>3, array( "d" => 5))), + array(), + /* 5 */ array(1, 2, 3, 4), + array("Saffron", "White", "Green"), + array('saffron', 'white', 'green'), + array(1 => "Hi", 2 => "Hello" ), + array("color" => "red", "item" => "pen"), + /* 10 */ array('color' => 'red', 'item' => 'pen'), + array(TRUE => "red", FALSE => "pen" ), + array(false => 'red', true => 'pen' ), + array('color' => "red", "item" => 'pen', 1 => "Hi", "" => "Hello" ), + /* 14 */ array($fp, "resource1" => $fp, 'resource2' => $fp, array( $fp, 'type' => $fp) ) +); + +// loop through each element of the values array for 'var' argument +// check the working of sizeof() +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + $var = $values[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() with different array values for 'var' argument --- +-- Iteration 1 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 2 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(8) + +-- Iteration 3 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(6) + +-- Iteration 4 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 5 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 6 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 7 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 8 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 9 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 10 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 11 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 12 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 13 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 14 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(6) + +Done diff --git a/ext/standard/tests/array/sizeof_variation3.phpt b/ext/standard/tests/array/sizeof_variation3.phpt new file mode 100644 index 000000000..ba8afb83e --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation3.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test sizeof() function : usage variations - checking for infinite recursion in COUNT_RECURSIVE mode +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "-- Testing sizeof() for infinite recursion with arrays as argument in COUNT_RECURSIVE mode --\n"; + +$array2 = array ( "Hi", "Hello",@$a); +$array3 = array( 'hi', 'hello'); +$a = array ( 1, @$array1, $array2, $array3); +$array1 = array( array(1, 2), $a); +$array4 = array( 100, @$array4); + +var_dump( sizeof($array1, COUNT_RECURSIVE) ); +echo "\n"; +var_dump( sizeof($array4, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +-- Testing sizeof() for infinite recursion with arrays as argument in COUNT_RECURSIVE mode -- +int(13) + +int(2) +Done diff --git a/ext/standard/tests/array/sizeof_variation4.phpt b/ext/standard/tests/array/sizeof_variation4.phpt new file mode 100644 index 000000000..a2462757d --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation4.phpt @@ -0,0 +1,350 @@ +--TEST-- +Test sizeof() function : usage variations - all kinds of unset variables for 'var' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() for all kinds of unset variables in default, Normal and Recursive Modes ---\n"; + +// class declaration +class test +{ + public $member1; +} + +// get an resource variable +$fp = fopen(__FILE__, "r"); + +// array containing different types of variables +$values = array ( + // int values + /* 1 */ 0, + 1, + // float values + /* 3 */ 10.5, + -10.5, + 12.34e3, + /* 6 */ 12.34E-3, + // string values + /* 7 */ "string", + 'string', + "", + /* 10 */ '', + // NULL values + /* 11 */ NULL, + null, + // Boolean Values + /* 12 */ TRUE, + true, + false, + /* 16 */ FALSE, + // array values + /* 17 */ array(), + array(1, 2, 3,4 , array(5, 6)), + // object variable + /* 19 */ new test(), + // resource variable + /* 20 */ $fp +); + +// loop through the each element of the $values array for 'var' arugment +// and check the functionality of sizeof() +$counter = 1; +foreach($values as $value) +{ + echo "-- Iteration $counter --\n"; + + // unset the variable + unset($value); + + // now check the size of unset variable when different modes are given + echo "Default Mode: "; + var_dump( sizeof($value) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($value, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($value, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() for all kinds of unset variables in default, Normal and Recursive Modes --- +-- Iteration 1 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 2 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 3 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 4 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 5 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 6 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 7 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 8 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 9 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 10 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 11 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 12 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 13 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 14 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 15 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 16 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 17 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 18 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 19 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 20 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +Done diff --git a/ext/standard/tests/array/sizeof_variation5.phpt b/ext/standard/tests/array/sizeof_variation5.phpt new file mode 100644 index 000000000..6e40f7ea7 --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation5.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test sizeof() function : usage variations - different values for 'mode' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() with different values for 'mode' argument ---\n"; +$array1 = array(1, 2, 3, 4, array(1.0, 2.0, array()), array() ); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//unset variable +$unset_var = 10; +unset($unset_var); + +//class declaration +class test +{ + public $member1; +} + +$mode_values = array ( + /* 1 */ COUNT_NORMAL, + COUNT_RECURSIVE, + 0, // same as COUNT_NORMAL + 1, // same as COUNT_RECURSIVE + + /* 5 */ TRUE, // same as COUNT_RECURSIVE + true, // same as COUNT_RECURSIVE + FALSE, // same as COUNT_NORMAL + false, // same as COUNT_NORMAL + NULL, // same as COUNT_NORMAL + /* 10 */ null, // same as COUNT_NORMAL + 100, + 10.5, + 12.34e3, + 12.34E-2, + /* 15 */ .5, + "", + '', + "string", + 'string', + /* 20 */ @$unset_var, + new test(), + /* 22 */ $fp +); + +// loop through the each element of $modes_array for 'mode' argument +// and check the working of sizeof() +$counter = 1; +for($i = 0; $i < count($mode_values); $i++) +{ + echo "-- Iteration $counter --\n"; + $mode = $mode_values[$i]; + + var_dump( sizeof($array1, $mode) ); + + $counter++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() with different values for 'mode' argument --- +-- Iteration 1 -- +int(6) +-- Iteration 2 -- +int(9) +-- Iteration 3 -- +int(6) +-- Iteration 4 -- +int(9) +-- Iteration 5 -- +int(9) +-- Iteration 6 -- +int(9) +-- Iteration 7 -- +int(6) +-- Iteration 8 -- +int(6) +-- Iteration 9 -- +int(6) +-- Iteration 10 -- +int(6) +-- Iteration 11 -- +int(6) +-- Iteration 12 -- +int(6) +-- Iteration 13 -- +int(6) +-- Iteration 14 -- +int(6) +-- Iteration 15 -- +int(6) +-- Iteration 16 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- +int(6) +-- Iteration 21 -- + +Warning: sizeof() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: sizeof() expects parameter 2 to be long, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_basic1.phpt b/ext/standard/tests/array/uasort_basic1.phpt new file mode 100644 index 000000000..70dd04c0c --- /dev/null +++ b/ext/standard/tests/array/uasort_basic1.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test uasort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : basic functionality ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Numeric array with default keys --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("This", "is", 'a', "test"); +echo "-- String array with default keys --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +// Associative array with numeric keys +$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); +echo "-- Associative array with numeric keys --\n"; +var_dump( uasort($numeric_key_arg, 'cmp') ); +var_dump($numeric_key_arg); + +// Associative array with string keys +$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); +echo "-- Associative array with string keys --\n"; +var_dump( uasort($string_key_arg, 'cmp') ); +var_dump($string_key_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality *** +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [2]=> + string(1) "a" + [1]=> + string(2) "is" + [3]=> + string(4) "test" +} +-- Associative array with numeric keys -- +bool(true) +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [5]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} +-- Associative array with string keys -- +bool(true) +array(4) { + ["three"]=> + int(1) + ["two"]=> + int(2) + ["one"]=> + int(4) + ["four"]=> + int(10) +} +Done diff --git a/ext/standard/tests/array/uasort_basic2.phpt b/ext/standard/tests/array/uasort_basic2.phpt new file mode 100644 index 000000000..e1b4ac9b2 --- /dev/null +++ b/ext/standard/tests/array/uasort_basic2.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test uasort() function : basic functionality - duplicate values +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : basic functionality with duplicate values ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// increasing values +$int_values1 = array(1, 1, 2, 2, 3, 3); +echo "-- Numeric array with increasing values --\n"; +var_dump( uasort($int_values1, 'cmp') ); +var_dump($int_values1); + +// decreasing values +$int_values2 = array(3, 3, 2, 2, 1, 1); +echo "-- Numeric array with decreasing values --\n"; +var_dump( uasort($int_values2, 'cmp') ); +var_dump($int_values2); + +// increasing and decreasing values +$int_values3 = array(1, 2, 3, 3, 2, 1); +echo "-- Numeric array with increasing and decreasing values --\n"; +var_dump( uasort($int_values3, 'cmp') ); +var_dump($int_values3); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality with duplicate values *** +-- Numeric array with increasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [5]=> + int(3) + [4]=> + int(3) +} +-- Numeric array with decreasing values -- +bool(true) +array(6) { + [4]=> + int(1) + [5]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [1]=> + int(3) + [0]=> + int(3) +} +-- Numeric array with increasing and decreasing values -- +bool(true) +array(6) { + [5]=> + int(1) + [0]=> + int(1) + [1]=> + int(2) + [4]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/uasort_error.phpt b/ext/standard/tests/array/uasort_error.phpt new file mode 100644 index 000000000..5f3d7ef10 --- /dev/null +++ b/ext/standard/tests/array/uasort_error.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test uasort() function : error conditions +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : error conditions ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Initialize 'array_arg' +$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25); + +// With zero arguments +echo "-- Testing uasort() function with Zero argument --\n"; +var_dump( uasort() ); + +// With one more than the expected number of arguments +echo "-- Testing uasort() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( uasort($array_arg, 'cmp', $extra_arg) ); + +// With one less than the expected number of arguments +echo "-- Testing uasort() function with less than expected no. of arguments --\n"; +var_dump( uasort($array_arg) ); + +// With non existent comparison function +echo "-- Testing uasort() function with non-existent compare function --\n"; +var_dump( uasort($array_arg, 'non_existent') ); + +// With non existent comparison function and extra arguemnt +echo "-- Testing uasort() function with non-existent compare function and extra argument --\n"; +var_dump( uasort($array_arg, 'non_existent', $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : error conditions *** +-- Testing uasort() function with Zero argument -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Testing uasort() function with non-existent compare function and extra argument -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_object1.phpt b/ext/standard/tests/array/uasort_object1.phpt new file mode 100644 index 000000000..c407ebc1f --- /dev/null +++ b/ext/standard/tests/array/uasort_object1.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test uasort() function : object functionality +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* + * Testing uasort() function with the array of objects + * array of objects which has only one member variable & more than one member variables + */ + +echo "*** Testing uasort() : object functionality ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value3 + * Description : compares value1 and value2 + */ +function simple_cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// comparison function for SimpleClass2 objects which has more than one members +function multiple_cmp($value1, $value2) +{ + if($value1->getValue() == $value2->getValue()) + return 0; + else if($value1->getValue() > $value2->getValue()) + return 1; + else + return -1; +} + +// Simple class with single member variable +class SimpleClass1 +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Simple class with more than one member variables +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() { + return $this->int_value; + } +} + +// array of SimpleClass objects with only one member +$array_arg = array( + 0 => new SimpleClass1(10), + 1 => new SimpleClass1(1), + 2 => new SimpleClass1(100), + 3 => new SimpleClass1(50) +); +var_dump( uasort($array_arg, 'simple_cmp') ); +var_dump($array_arg); + +// array of SimpleClass objects having more than one members +$array_arg = array( + 0 => new SimpleClass2(2, 3.4, "mango"), + 1 => new SimpleClass2(10, 1.2, "apple"), + 2 => new SimpleClass2(5, 2.5, "orange"), +); +var_dump( uasort($array_arg, 'multiple_cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +bool(true) +array(4) { + [1]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(1) + } + [0]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(10) + } + [3]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(50) + } + [2]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#%d (3) { + ["int_value:private"]=> + int(2) + ["float_value:protected"]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [2]=> + object(SimpleClass2)#%d (3) { + ["int_value:private"]=> + int(5) + ["float_value:protected"]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [1]=> + object(SimpleClass2)#%d (3) { + ["int_value:private"]=> + int(10) + ["float_value:protected"]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} +Done diff --git a/ext/standard/tests/array/uasort_object2.phpt b/ext/standard/tests/array/uasort_object2.phpt new file mode 100644 index 000000000..cd32d8d94 --- /dev/null +++ b/ext/standard/tests/array/uasort_object2.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test uasort() function : object functionality - sort diff. objects +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +* + +/* + * This testcase tests uasort() functionality with differnt objects + * Objects of different classes: + * simple class, + * child class, + * empty class & + * static class + */ + +echo "*** Testing uasort() : object functionality ***\n"; + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + + +// Simple class with single member variable +class SimpleClass +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } + +} + +// Class without any member +class EmptyClass +{ +} + +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) { + StaticClass::$static_value = $value; + } +} + +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + public abstract function abstractMethod(); +} + +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() { + $pub_value = 5; + } + public function __construct($value) { + $this->child_value = $value; + } +} + +// Testing uasort with StaticClass objects as elements of 'array_arg' +echo "-- Testing uasort() with StaticClass objects --\n"; +$array_arg = array( + 0 => new StaticClass(20), + 1 => new StaticClass(50), + 2 => new StaticClass(15), + 3 => new StaticClass(70), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with EmptyClass objects as elements of 'array_arg' +echo "-- Testing uasort() with EmptyClass objects --\n"; +$array_arg = array( + 0 => new EmptyClass(), + 1 => new EmptyClass(), + 2 => new EmptyClass(), + 3 => new EmptyClass(), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with ChildClass objects as elements of 'array_arg' +echo "-- Testing uasort() with ChildClass objects --\n"; +$array_arg = array( + 0 => new ChildClass(20), + 1 => new ChildClass(500), + 2 => new ChildClass(15), + 3 => new ChildClass(700), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +-- Testing uasort() with StaticClass objects -- +bool(true) +array(4) { + [3]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [0]=> + object(StaticClass)#%d (0) { + } +} +-- Testing uasort() with EmptyClass objects -- +bool(true) +array(4) { + [3]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [0]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing uasort() with ChildClass objects -- +bool(true) +array(4) { + [2]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(15) + ["pub_value"]=> + NULL + } + [0]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(20) + ["pub_value"]=> + NULL + } + [1]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(500) + ["pub_value"]=> + NULL + } + [3]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(700) + ["pub_value"]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/uasort_variation1.phpt b/ext/standard/tests/array/uasort_variation1.phpt new file mode 100644 index 000000000..cce86ee0b --- /dev/null +++ b/ext/standard/tests/array/uasort_variation1.phpt @@ -0,0 +1,188 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() function by passing different scalar/nonscalar values as 'array_arg' argument +*/ + +echo "*** Testing uasort() : unexpected values for 'array_arg' ***\n"; + +// Comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__,'r'); + +//array of values to iterate over +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // resource data +/*20*/ $fp, + + // undefined data + @$undefined_var, + + // unset data +/*22*/ @$unset_var, +); + +// loop through each value of input_values +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($input_values[$count], 'cmp_function') ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : unexpected values for 'array_arg' *** +-- Iteration 1 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/uasort_variation10.phpt b/ext/standard/tests/array/uasort_variation10.phpt new file mode 100644 index 000000000..809cb78f5 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation10.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test uasort() function : usage variations - sort array with reference variables +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() with 'array_arg' containing different reference variables +*/ + +// comparision function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : 'array_arg' with elements as reference ***\n"; + +// different variables which are used as elements of 'array_arg' +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// array_args an array containing elements with reference variables +$array_arg = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +echo "-- Sorting 'array_arg' containing different references --\n"; +var_dump( uasort($array_arg, 'cmp_function') ); // expecting: bool(true) +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'array_arg' with elements as reference *** +-- Sorting 'array_arg' containing different references -- +bool(true) +array(5) { + [1]=> + &int(-5) + [4]=> + &int(0) + [0]=> + int(10) + [2]=> + &int(100) + [3]=> + int(200) +} +Done diff --git a/ext/standard/tests/array/uasort_variation11.phpt b/ext/standard/tests/array/uasort_variation11.phpt new file mode 100644 index 000000000..6d523eaed --- /dev/null +++ b/ext/standard/tests/array/uasort_variation11.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test uasort() function : usage variations - different associative arrays +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* Testing uasort() with different associative arrays having keys as + * string, integer, default & duplicate keys + */ + +echo "*** Testing uasort() : sorting different associative arrays ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Array with duplicate string and integer keys +$array_arg = array(0 => 2, "a" => 8, "d" => 9, 3 => 3, 5 => 2, "o" => 6, "z" => -99, 0 => 1, "z" => 3); +echo "-- Array with duplicate keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +// Array with default and assigned keys +$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); +echo "-- Array with default/assigned keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : sorting different associative arrays *** +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [5]=> + int(2) + ["z"]=> + int(3) + [3]=> + int(3) + ["o"]=> + int(6) + ["a"]=> + int(8) + ["d"]=> + int(9) +} +-- Array with default/assigned keys -- +bool(true) +array(4) { + [2]=> + string(5) "Apple" + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation2.phpt b/ext/standard/tests/array/uasort_variation2.phpt new file mode 100644 index 000000000..af1b71c0e --- /dev/null +++ b/ext/standard/tests/array/uasort_variation2.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'cmp_function' argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() function with different scalar and nonscalar values in place of 'cmp_function' +*/ + +echo "*** Testing uasort() : Unexpected values in place of comparison function ***\n"; + +// Class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +$array_arg = array(0 => 1, 1 => -1, 2 => 3, 3 => 10, 4 => 4, 5 => 2, 6 => 8, 7 => 5); + +// Get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Get resource variable +$fp = fopen(__FILE__,'r'); + +// different values for 'cmp_function' +$cmp_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data + "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of the cmp_values for 'cmp_function' +for($count = 0; $count < count($cmp_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($array_arg, $cmp_values[$count]) ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : Unexpected values in place of comparison function *** +-- Iteration 1 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 26 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 27 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 28 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/uasort_variation3.phpt b/ext/standard/tests/array/uasort_variation3.phpt Binary files differnew file mode 100644 index 000000000..9147d5991 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation3.phpt diff --git a/ext/standard/tests/array/uasort_variation4.phpt b/ext/standard/tests/array/uasort_variation4.phpt new file mode 100644 index 000000000..c2844bfd2 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation4.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test uasort() function : usage variations - sort different numeric values +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* sorting different types of numeric arrays containing data of following type: +* integer, octal, hexadecimal & float +*/ + +// comparision function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : different numeric arrays as 'array_arg' ***\n"; + +// Int array +$int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200); +echo "-- Sorting Integer array --\n"; +var_dump( uasort($int_values, 'cmp_function') ); // expecting: bool(true) +var_dump($int_values); + +// Octal array +$octal_values = array(0 => 056, 1 => 023, 2 => 090, 3 => 015, 4 => -045, 5 => 01, 6 => -078); +echo "-- Sorting Octal array --\n"; +var_dump( uasort($octal_values, 'cmp_function') ); // expecting: bool(true) +var_dump($octal_values); + +// Hexadecimal array +$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, 3 => -0xCF, 4 => 0X12, 5 => -0XF2); +echo "-- Sorting Hex array --\n"; +var_dump( uasort($hex_values, 'cmp_function') ); // expecting: bool(true) +var_dump($hex_values); + +// Float array +$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2); +echo "-- Sorting Float array --\n"; +var_dump( uasort($float_values, 'cmp_function') ); // expecting: bool(true) +var_dump($float_values); + +// empty array +$empty_array = array(); +echo "-- Sorting empty array --\n"; +var_dump( uasort($empty_array, 'cmp_function') ); // expecting: bool(true) +var_dump($empty_array); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different numeric arrays as 'array_arg' *** +-- Sorting Integer array -- +bool(true) +array(9) { + [9]=> + int(-1200) + [8]=> + int(-3) + [7]=> + int(0) + [1]=> + int(2) + [0]=> + int(3) + [5]=> + int(25) + [3]=> + int(100) + [4]=> + int(150) + [6]=> + int(350) +} +-- Sorting Octal array -- +bool(true) +array(7) { + [4]=> + int(-37) + [6]=> + int(-7) + [2]=> + int(0) + [5]=> + int(1) + [3]=> + int(13) + [1]=> + int(19) + [0]=> + int(46) +} +-- Sorting Hex array -- +bool(true) +array(6) { + [5]=> + int(-242) + [3]=> + int(-207) + [2]=> + int(16) + [4]=> + int(18) + [1]=> + int(43) + [0]=> + int(174) +} +-- Sorting Float array -- +bool(true) +array(7) { + [2]=> + float(-3.4) + [6]=> + float(-0.0934) + [3]=> + int(0) + [4]=> + float(0.5) + [1]=> + float(2.4) + [0]=> + float(10.2) + [5]=> + float(7300) +} +-- Sorting empty array -- +bool(true) +array(0) { +} +Done diff --git a/ext/standard/tests/array/uasort_variation5.phpt b/ext/standard/tests/array/uasort_variation5.phpt new file mode 100644 index 000000000..22d9da31c --- /dev/null +++ b/ext/standard/tests/array/uasort_variation5.phpt @@ -0,0 +1,145 @@ +--TEST-- +Test uasort() function : usage variations - sort diff. strings +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* sorting different strings: +* single quoted, double quoted and heredoc strings +*/ + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Different heredoc strings to be sorted +$empty_heredoc =<<<EOT +EOT; + +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + + +echo "*** Testing uasort() : different string arrays as 'array_arg' ***\n"; + +// Single quoted strings +$single_quoted_values = array( + 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', + 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%' +); +echo "-- Sorting Single Quoted String values --\n"; +var_dump( uasort($single_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($single_quoted_values); + +// Double quoted strings +$double_quoted_values = array( + 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", + 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%" +); +echo "-- Sorting Double Quoted String values --\n"; +var_dump( uasort($double_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($double_quoted_values); + +// Heredoc strings +$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); +echo "-- Sorting Heredoc String values --\n"; +var_dump( uasort($heredoc_values, 'cmp_function') ); // expecting: bool(true) +var_dump($heredoc_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different string arrays as 'array_arg' *** +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [0]=> + string(1) " " + [9]=> + string(1) "'" + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [6]=> + string(2) "\t" + [1]=> + string(4) "test" +} +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [6]=> + string(1) " " + [0]=> + string(1) " " + [9]=> + string(1) """ + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [1]=> + string(4) "test" +} +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [2]=> + string(7) "HEREDOC" + [1]=> + string(7) "Heredoc" + [3]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/ext/standard/tests/array/uasort_variation6.phpt b/ext/standard/tests/array/uasort_variation6.phpt new file mode 100644 index 000000000..48d9c0357 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation6.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test uasort() function : usage variations - sort array having subarrays +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() with 'array_arg' having different subarrays as array elements +*/ + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : sorting array having different subarrays ***\n"; + +$array_args = array( + 0 => array(2, 10, -1), + 1 => array(100), + 2 => array(), + 3 => array(0), + 4 => array(-1), + 5 => array(-9, 34, 54, 0, 20), + 6 => array(''), + 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe") +); +$temp_array = $array_args; +// sorting array_arg as whole array +var_dump( uasort($temp_array, 'cmp_function') ); // expecting: bool(true) +var_dump($temp_array); + +?> +--EXPECTF-- +*** Testing uasort() : sorting array having different subarrays *** +bool(true) +array(8) { + [2]=> + array(0) { + } + [4]=> + array(1) { + [0]=> + int(-1) + } + [6]=> + array(1) { + [0]=> + string(0) "" + } + [3]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(100) + } + [0]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [5]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} diff --git a/ext/standard/tests/array/uasort_variation7.phpt b/ext/standard/tests/array/uasort_variation7.phpt new file mode 100644 index 000000000..44a2bb3a2 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation7.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test uasort() function : usage variations - anonymous function as 'cmp_function' +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Passing different anonymous functions as 'cmp_function' +* arguments passed by value +* arguments passed by reference +*/ + +echo "*** Testing uasort() : anonymous function as 'cmp_function' ***\n"; + +$cmp_function = 'if($value1 == $value2) {return 0;} else if($value1 > $value2) {return 1;} else{return -1;}'; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); +echo "-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( uasort($array_arg, create_function('$value1, $value2',$cmp_function) ) ); +var_dump($array_arg); + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); +echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( uasort($array_arg, create_function('&$value1, &$value2', $cmp_function) ) ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : anonymous function as 'cmp_function' *** +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [2]=> + int(-70) + [1]=> + int(3) + [3]=> + int(24) + [4]=> + int(90) + [0]=> + int(100) +} +-- Anonymous 'cmp_function' with parameters passed by reference -- +bool(true) +array(4) { + ["a"]=> + string(5) "Apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation8.phpt b/ext/standard/tests/array/uasort_variation8.phpt new file mode 100644 index 000000000..858ce2009 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation8.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test uasort() function : usage variations - built-in function as 'cmp_function' +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Passing different built-in library functions in place of 'cmp_function' +* valid comparison functions: strcmp() & strcasecmp() +* language constructs: echo & exit +*/ + +echo "*** Testing uasort() : built in function as 'cmp_function' ***\n"; +// Initializing variables +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "apple", "p" => "Pineapple", "o" => "orange"); +$builtin_fun_arg = $array_arg; +$languageConstruct_fun_arg = $array_arg; + +// Testing library functions as comparison function +echo "-- Testing uasort() with built-in 'cmp_function': strcasecmp() --\n"; +var_dump( uasort($builtin_fun_arg, 'strcasecmp') ); // expecting: bool(true) +var_dump($builtin_fun_arg); + +echo "-- Testing uasort() with built-in 'cmp_function': strcmp() --\n"; +var_dump( uasort($array_arg, 'strcmp') ); // expecting: bool(true) +var_dump($array_arg); + +// Testing with language construct as comparison function +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'echo') ); // expecting: bool(false) + +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'exit') ); // expecting: bool(false) + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : built in function as 'cmp_function' *** +-- Testing uasort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["o"]=> + string(6) "orange" + ["p"]=> + string(9) "Pineapple" +} +-- Testing uasort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" + ["a"]=> + string(5) "apple" + ["o"]=> + string(6) "orange" +} +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/uasort_variation9.phpt b/ext/standard/tests/array/uasort_variation9.phpt new file mode 100644 index 000000000..486042e5e --- /dev/null +++ b/ext/standard/tests/array/uasort_variation9.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test uasort() function : usage variations - 'cmp_function' with reference argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* Testing uasort() functionality with comparison function having arguments as reference + */ + +echo "*** Testing uasort() : 'cmp_function' with reference arguments ***\n"; + +// comparison function +/* Prototype : int cmp(mixed &$value1, mixed &$value2) + * Parameters : $value1 and $value2 - values recieved by reference + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp(&$value1, &$value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Passing integer values to 'cmp_function' --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("Mango", "Apple", "Orange", "Banana"); +echo "-- Passing string values to 'cmp_function' --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'cmp_function' with reference arguments *** +-- Passing integer values to 'cmp_function' -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- Passing string values to 'cmp_function' -- +bool(true) +array(4) { + [1]=> + string(5) "Apple" + [3]=> + string(6) "Banana" + [0]=> + string(5) "Mango" + [2]=> + string(6) "Orange" +} +Done diff --git a/ext/standard/tests/array/var_export2.phpt b/ext/standard/tests/array/var_export2.phpt Binary files differindex 2b8a1f97e..6db44d5ca 100644 --- a/ext/standard/tests/array/var_export2.phpt +++ b/ext/standard/tests/array/var_export2.phpt diff --git a/ext/standard/tests/class_object/class_exists_basic_001.phpt b/ext/standard/tests/class_object/class_exists_basic_001.phpt new file mode 100644 index 000000000..4cb6cbd32 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_basic_001.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test class_exists() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing class_exists() : basic functionality ***\n"; + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +echo "Calling class_exists() on non-existent class with autoload explicitly enabled:\n"; +var_dump( class_exists('C', true) ); +echo "\nCalling class_exists() on existing class with autoload explicitly enabled:\n"; +var_dump( class_exists('stdclass', true) ); + +echo "\nCalling class_exists() on non-existent class with autoload explicitly enabled:\n"; +var_dump( class_exists('D', false) ); +echo "\nCalling class_exists() on existing class with autoload explicitly disabled:\n"; +var_dump( class_exists('stdclass', false) ); + +echo "\nCalling class_exists() on non-existent class with autoload unspecified:\n"; +var_dump( class_exists('E') ); +echo "\nCalling class_exists() on existing class with autoload unspecified:\n"; +var_dump( class_exists('stdclass') ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : basic functionality *** +Calling class_exists() on non-existent class with autoload explicitly enabled: +In __autoload(C) +bool(false) + +Calling class_exists() on existing class with autoload explicitly enabled: +bool(true) + +Calling class_exists() on non-existent class with autoload explicitly enabled: +bool(false) + +Calling class_exists() on existing class with autoload explicitly disabled: +bool(true) + +Calling class_exists() on non-existent class with autoload unspecified: +In __autoload(E) +bool(false) + +Calling class_exists() on existing class with autoload unspecified: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_error_001.phpt b/ext/standard/tests/class_object/class_exists_error_001.phpt new file mode 100644 index 000000000..99c0b89b3 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test class_exists() function : error conditions (wrong number of arguments) +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/** + * Test wrong number of arguments + */ + +echo "*** Testing class_exists() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing class_exists() function with Zero arguments --\n"; +var_dump( class_exists() ); + +//Test class_exists with one more than the expected number of arguments +echo "\n-- Testing class_exists() function with more than expected no. of arguments --\n"; +$classname = 'string_val'; +$autoload = true; +$extra_arg = 10; +var_dump( class_exists($classname, $autoload, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : error conditions *** + +-- Testing class_exists() function with Zero arguments -- + +Warning: class_exists() expects at least 1 parameter, 0 given in %s on line 16 +NULL + +-- Testing class_exists() function with more than expected no. of arguments -- + +Warning: class_exists() expects at most 2 parameters, 3 given in %s on line 23 +NULL +Done diff --git a/ext/standard/tests/class_object/class_exists_variation_001.phpt b/ext/standard/tests/class_object/class_exists_variation_001.phpt new file mode 100644 index 000000000..2141d65eb --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_001.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test class_exists() function : usage variations - unexpected types for agument 1 +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing class_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$autoload = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for classname + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( class_exists($value, $autoload) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +In __autoload(0) +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value 12345 +In __autoload(12345) +bool(false) + +Arg value -2345 +In __autoload(-2345) +bool(false) + +Arg value 10.5 +In __autoload(10.5) +bool(false) + +Arg value -10.5 +In __autoload(-10.5) +bool(false) + +Arg value 101234567000 +In __autoload(101234567000) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(1.07654321E-9) +bool(false) + +Arg value 0.5 +In __autoload(0.5) +bool(false) + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 1 to be string, array given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(1) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 2 - class_exists() expects parameter 1 to be string, object given, %s(77) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_variation_002.phpt b/ext/standard/tests/class_object/class_exists_variation_002.phpt new file mode 100644 index 000000000..da10cac90 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_002.phpt @@ -0,0 +1,193 @@ +--TEST-- +Test class_exists() function : usage variations - unexpected types for agument 2 +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing class_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$classname = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for autoload + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( class_exists($classname, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing class_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(71) +Error: 8 - Undefined variable: unset_var, %s(74) + +Arg value 0 +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value 12345 +In __autoload(string_val) +bool(false) + +Arg value -2345 +In __autoload(string_val) +bool(false) + +Arg value 10.5 +In __autoload(string_val) +bool(false) + +Arg value -10.5 +In __autoload(string_val) +bool(false) + +Arg value 101234567000 +In __autoload(string_val) +bool(false) + +Arg value 1.07654321E-9 +In __autoload(string_val) +bool(false) + +Arg value 0.5 +In __autoload(string_val) +bool(false) + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value Array +Error: 2 - class_exists() expects parameter 2 to be boolean, array given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value 1 +In __autoload(string_val) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) + +Arg value string +In __autoload(string_val) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(80) + +Arg value +Error: 2 - class_exists() expects parameter 2 to be boolean, object given, %s(81) +NULL + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/class_exists_variation_003.phpt b/ext/standard/tests/class_object/class_exists_variation_003.phpt new file mode 100644 index 000000000..074560145 --- /dev/null +++ b/ext/standard/tests/class_object/class_exists_variation_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test class_exists() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool class_exists(string classname [, bool autoload]) + * Description: Checks if the class exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class caseSensitivityTest {} +var_dump(class_exists('casesensitivitytest')); + +echo "Done" +?> +--EXPECTF-- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_error_001.phpt b/ext/standard/tests/class_object/get_class_error_001.phpt new file mode 100644 index 000000000..b563c3188 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_error_001.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test get_class() function : error conditions - wrong number of arguments. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class() : error conditions ***\n"; + +//Test get_class with one more than the expected number of arguments +echo "\n-- Testing get_class() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$extra_arg = 10; +var_dump( get_class($object, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class() : error conditions *** + +-- Testing get_class() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_class() in %s on line 14 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_001.phpt b/ext/standard/tests/class_object/get_class_methods_basic_001.phpt new file mode 100644 index 000000000..b2b87af4e --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_001.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test basic behaviour with existing class and non-existent class. + */ + +echo "*** Testing get_class_methods() : basic functionality ***\n"; + +class C { + function f() {} + function g() {} + function h() {} +} + +echo "Argument is class name:\n"; +var_dump( get_class_methods("C") ); +echo "Argument is class instance:\n"; +$c = new C; +var_dump( get_class_methods($c) ); + +class D {} +echo "Argument is name of class which has no methods:\n"; +var_dump( get_class_methods("D") ); + +echo "Argument is non existent class:\n"; +var_dump( get_class_methods("NonExistent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : basic functionality *** +Argument is class name: +array(3) { + [0]=> + string(1) "f" + [1]=> + string(1) "g" + [2]=> + string(1) "h" +} +Argument is class instance: +array(3) { + [0]=> + string(1) "f" + [1]=> + string(1) "g" + [2]=> + string(1) "h" +} +Argument is name of class which has no methods: +array(0) { +} +Argument is non existent class: +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_002.phpt b/ext/standard/tests/class_object/get_class_methods_basic_002.phpt new file mode 100644 index 000000000..441bb45d6 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_002.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test behaviour with various visibility levels. + */ + +class C { + private function privC() {} + protected function protC() {} + public function pubC() {} + + public static function testFromC() { + echo "Accessing C from C:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from C:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from C:\n"; + var_dump(get_class_methods("X")); + } +} + +class D extends C { + private function privD() {} + protected function protD() {} + public function pubD() {} + + public static function testFromD() { + echo "Accessing C from D:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from D:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from D:\n"; + var_dump(get_class_methods("X")); + } +} + +class X { + private function privX() {} + protected function protX() {} + public function pubX() {} + + public static function testFromX() { + echo "Accessing C from X:\n"; + var_dump(get_class_methods("C")); + echo "Accessing D from X:\n"; + var_dump(get_class_methods("D")); + echo "Accessing X from X:\n"; + var_dump(get_class_methods("X")); + } +} + +echo "Accessing D from global scope:\n"; +var_dump(get_class_methods("D")); + +C::testFromC(); +D::testFromD(); +X::testFromX(); + +echo "Done"; +?> +--EXPECTF-- +Accessing D from global scope: +array(4) { + [0]=> + string(4) "pubD" + [1]=> + string(9) "testFromD" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing C from C: +array(4) { + [0]=> + string(5) "privC" + [1]=> + string(5) "protC" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing D from C: +array(7) { + [0]=> + string(5) "protD" + [1]=> + string(4) "pubD" + [2]=> + string(9) "testFromD" + [3]=> + string(5) "privC" + [4]=> + string(5) "protC" + [5]=> + string(4) "pubC" + [6]=> + string(9) "testFromC" +} +Accessing X from C: +array(2) { + [0]=> + string(4) "pubX" + [1]=> + string(9) "testFromX" +} +Accessing C from D: +array(3) { + [0]=> + string(5) "protC" + [1]=> + string(4) "pubC" + [2]=> + string(9) "testFromC" +} +Accessing D from D: +array(7) { + [0]=> + string(5) "privD" + [1]=> + string(5) "protD" + [2]=> + string(4) "pubD" + [3]=> + string(9) "testFromD" + [4]=> + string(5) "protC" + [5]=> + string(4) "pubC" + [6]=> + string(9) "testFromC" +} +Accessing X from D: +array(2) { + [0]=> + string(4) "pubX" + [1]=> + string(9) "testFromX" +} +Accessing C from X: +array(2) { + [0]=> + string(4) "pubC" + [1]=> + string(9) "testFromC" +} +Accessing D from X: +array(4) { + [0]=> + string(4) "pubD" + [1]=> + string(9) "testFromD" + [2]=> + string(4) "pubC" + [3]=> + string(9) "testFromC" +} +Accessing X from X: +array(4) { + [0]=> + string(5) "privX" + [1]=> + string(5) "protX" + [2]=> + string(4) "pubX" + [3]=> + string(9) "testFromX" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_basic_003.phpt b/ext/standard/tests/class_object/get_class_methods_basic_003.phpt new file mode 100644 index 000000000..b64f702b8 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_basic_003.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test get_class_methods() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test behaviour with interfaces. + */ + +interface I { + public function pubI(); + +} + +class C implements I { + public function pubI() {} + + private function privC() {} + protected function protC() {} + public function pubC() {} + + public static function testFromC() { + echo "Accessing I from C:\n"; + var_dump(get_class_methods("I")); + echo "Accessing C from C:\n"; + var_dump(get_class_methods("C")); + } +} + + +echo "Accessing I from global scope:\n"; +var_dump(get_class_methods("I")); +echo "Accessing C from global scope:\n"; +var_dump(get_class_methods("C")); +C::testFromC(); +echo "Done"; +?> +--EXPECTF-- +Accessing I from global scope: +array(1) { + [0]=> + string(4) "pubI" +} +Accessing C from global scope: +array(3) { + [0]=> + string(4) "pubI" + [1]=> + string(4) "pubC" + [2]=> + string(9) "testFromC" +} +Accessing I from C: +array(1) { + [0]=> + string(4) "pubI" +} +Accessing C from C: +array(5) { + [0]=> + string(4) "pubI" + [1]=> + string(5) "privC" + [2]=> + string(5) "protC" + [3]=> + string(4) "pubC" + [4]=> + string(9) "testFromC" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_error_001.phpt b/ext/standard/tests/class_object/get_class_methods_error_001.phpt new file mode 100644 index 000000000..6edb10803 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_error_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test get_class_methods() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +/* + * Test wrong number of arguments. + */ + +echo "*** Testing get_class_methods() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing get_class_methods() function with Zero arguments --\n"; +var_dump( get_class_methods() ); + +//Test get_class_methods with one more than the expected number of arguments +echo "\n-- Testing get_class_methods() function with more than expected no. of arguments --\n"; +$class = 1; +$extra_arg = 10; +var_dump( get_class_methods($class, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : error conditions *** + +-- Testing get_class_methods() function with Zero arguments -- + +Warning: Wrong parameter count for get_class_methods() in %s on line 16 +NULL + +-- Testing get_class_methods() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_class_methods() in %s on line 22 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_variation_001.phpt b/ext/standard/tests/class_object/get_class_methods_variation_001.phpt new file mode 100644 index 000000000..b881452b4 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_001.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test get_class_methods() function : usage variations - unexpected types +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing get_class_methods() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( get_class_methods($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +NULL + +Arg value 1 +NULL + +Arg value 12345 +NULL + +Arg value -2345 +NULL + +Arg value 10.5 +NULL + +Arg value -10.5 +NULL + +Arg value 101234567000 +NULL + +Arg value 1.07654321E-9 +NULL + +Arg value 0.5 +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value Array +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value 1 +NULL + +Arg value +NULL + +Arg value 1 +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value +NULL + +Arg value string +NULL + +Arg value string +NULL +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +array(0) { +} + +Arg value +NULL + +Arg value +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_methods_variation_002.phpt b/ext/standard/tests/class_object/get_class_methods_variation_002.phpt new file mode 100644 index 000000000..60b944c69 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_methods_variation_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_class_methods() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto array get_class_methods(mixed class) + * Description: Returns an array of method names for class or class instance. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class_methods() : usage variations ***\n"; + +class caseSensitivityTest { + function MyMeThOd() {} +} + +var_dump( get_class_methods('CasesensitivitytesT') ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class_methods() : usage variations *** +array(1) { + [0]=> + string(8) "MyMeThOd" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_variation_001.phpt b/ext/standard/tests/class_object/get_class_variation_001.phpt new file mode 100644 index 000000000..6cbe0b368 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_001.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test get_class() function : usage variations - passing unexpected types. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_class() : usage variations ***\n"; + +// Note: basic use cases in Zend/tests/009.phpt + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value: $value (type: " . gettype($value) . ")\n"; + var_dump( get_class($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_class() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 58 + +Notice: Undefined variable: unset_var in %s on line 61 + +Arg value: 0 (type: integer) +bool(false) + +Arg value: 1 (type: integer) +bool(false) + +Arg value: 12345 (type: integer) +bool(false) + +Arg value: -2345 (type: integer) +bool(false) + +Arg value: 10.5 (type: double) +bool(false) + +Arg value: -10.5 (type: double) +bool(false) + +Arg value: 101234567000 (type: double) +bool(false) + +Arg value: 1.07654321E-9 (type: double) +bool(false) + +Arg value: 0.5 (type: double) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: Array (type: array) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: 1 (type: boolean) +bool(false) + +Arg value: (type: boolean) +bool(false) + +Arg value: 1 (type: boolean) +bool(false) + +Arg value: (type: boolean) +bool(false) + +Arg value: (type: string) +bool(false) + +Arg value: (type: string) +bool(false) + +Arg value: string (type: string) +bool(false) + +Arg value: string (type: string) +bool(false) + +Arg value: (type: NULL) +bool(false) + +Arg value: (type: NULL) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_class_variation_002.phpt b/ext/standard/tests/class_object/get_class_variation_002.phpt new file mode 100644 index 000000000..1ee352981 --- /dev/null +++ b/ext/standard/tests/class_object/get_class_variation_002.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test get_class() function : usage variations - ensure class name case is preserved. +--FILE-- +<?php +/* Prototype : proto string get_class([object object]) + * Description: Retrieves the class name + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class caseSensitivityTest {} +var_dump(get_class(new casesensitivitytest)); + +echo "Done"; +?> +--EXPECTF-- +string(19) "caseSensitivityTest" +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt b/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt new file mode 100644 index 000000000..123e9772c --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test get_declared_classes() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_classes() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing get_declared_classes() function with Zero arguments --\n"; +var_dump(get_declared_classes()); + +foreach (get_declared_classes() as $class) { + if (!class_exists($class)) { + echo "Error: $class is not a valid class.\n"; + } +} + +echo "\n-- Ensure userspace classes are listed --\n"; +Class C {} +var_dump(in_array('C', get_declared_classes())); + +echo "\n-- Ensure userspace interfaces are not listed --\n"; +Interface I {} +var_dump(in_array( 'I', get_declared_classes())); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_classes() : basic functionality *** + +-- Testing get_declared_classes() function with Zero arguments -- +array(%d) { +%a +} + +-- Ensure userspace classes are listed -- +bool(true) + +-- Ensure userspace interfaces are not listed -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_classes_error_001.phpt b/ext/standard/tests/class_object/get_declared_classes_error_001.phpt new file mode 100644 index 000000000..a50844367 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_classes_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_declared_classes() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_declared_classes() + * Description: Returns an array of all declared classes. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_declared_classes() : error conditions ***\n"; + +// One argument +echo "\n-- Testing get_declared_classes() function with one argument --\n"; +$extra_arg = 10;; +var_dump( get_declared_classes($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_classes() : error conditions *** + +-- Testing get_declared_classes() function with one argument -- + +Warning: Wrong parameter count for get_declared_classes() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt b/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt new file mode 100644 index 000000000..a0ec71518 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test get_declared_interfaces() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + + +echo "*** Testing get_declared_interfaces() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing get_declared_interfaces() function with Zero arguments --\n"; +var_dump(get_declared_interfaces()); + +foreach (get_declared_interfaces() as $interface) { + if (!interface_exists($interface)) { + echo "Error: $interface is not a valid interface.\n"; + } +} + +echo "\n-- Ensure userspace classes are not listed --\n"; +Class C {} +var_dump(in_array('C', get_declared_interfaces())); + +echo "\n-- Ensure userspace interfaces are listed --\n"; +Interface I {} +var_dump(in_array('I', get_declared_interfaces())); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : basic functionality *** + +-- Testing get_declared_interfaces() function with Zero arguments -- +array(%d) { +%a +} + +-- Ensure userspace classes are not listed -- +bool(false) + +-- Ensure userspace interfaces are listed -- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt b/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt new file mode 100644 index 000000000..93aabb6f6 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_interfaces_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_declared_interfaces() function : error conditions +--FILE-- +<?php +/* Prototype : proto array get_declared_interfaces() + * Description: Returns an array of all declared interfaces. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_declared_interfaces() : error conditions ***\n"; + +// One argument +echo "\n-- Testing get_declared_interfaces() function with one argument --\n"; +$extra_arg = 10;; +var_dump( get_declared_interfaces($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_declared_interfaces() : error conditions *** + +-- Testing get_declared_interfaces() function with one argument -- + +Warning: Wrong parameter count for get_declared_interfaces() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_basic_001.phpt b/ext/standard/tests/class_object/get_object_vars_basic_001.phpt new file mode 100644 index 000000000..38ed74fb0 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_basic_001.phpt @@ -0,0 +1,107 @@ +--TEST-- +get_object_vars(): visibility from static methods (target object passed as arg) +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + private $hiddenPriv = 'A::hiddenPriv'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class B extends A { + private $hiddenPriv = 'B::hiddenPriv'; + private $priv = 'B::priv'; + protected $prot = 'B::prot'; + public $pub = 'B::pub'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class C extends B { + private $hiddenPriv = 'C::hiddenPriv'; + + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class X { + public static function test($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + + +$b = new B; +echo "\n---( Global scope: )---\n"; +var_dump(get_object_vars($b)); +echo "\n---( Declaring class: )---\n"; +B::test($b); +echo "\n---( Subclass: )---\n"; +C::test($b); +echo "\n---( Superclass: )---\n"; +A::test($b); +echo "\n---( Unrelated class: )---\n"; +X::test($b); +?> +--EXPECTF-- + +---( Global scope: )--- +array(1) { + ["pub"]=> + string(6) "B::pub" +} + +---( Declaring class: )--- +B::test +array(4) { + ["hiddenPriv"]=> + string(13) "B::hiddenPriv" + ["priv"]=> + string(7) "B::priv" + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Subclass: )--- +C::test +array(2) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Superclass: )--- +A::test +array(3) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" + ["hiddenPriv"]=> + string(13) "A::hiddenPriv" +} + +---( Unrelated class: )--- +X::test +array(1) { + ["pub"]=> + string(6) "B::pub" +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_basic_002.phpt b/ext/standard/tests/class_object/get_object_vars_basic_002.phpt new file mode 100644 index 000000000..910926bc1 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_basic_002.phpt @@ -0,0 +1,64 @@ +--TEST-- +get_object_vars(): visibility from non static methods (target object passed as arg) +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + private $hiddenPriv = 'A::hiddenPriv'; + + public function testA($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + +Class B extends A { + private $hiddenPriv = 'B::hiddenPriv'; + private $priv = 'B::priv'; + protected $prot = 'B::prot'; + public $pub = 'B::pub'; + + public function testB($b) { + echo __METHOD__ . "\n"; + var_dump(get_object_vars($b)); + } +} + + +$b = new B; +echo "\n---( Declaring class: )---\n"; +$b->testB($b); +echo "\n---( Superclass: )---\n"; +$b->testA($b); + +?> +--EXPECTF-- + +---( Declaring class: )--- +B::testB +array(4) { + ["hiddenPriv"]=> + string(13) "B::hiddenPriv" + ["priv"]=> + string(7) "B::priv" + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" +} + +---( Superclass: )--- +A::testA +array(3) { + ["prot"]=> + string(7) "B::prot" + ["pub"]=> + string(6) "B::pub" + ["hiddenPriv"]=> + string(13) "A::hiddenPriv" +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_error_001.phpt b/ext/standard/tests/class_object/get_object_vars_error_001.phpt new file mode 100644 index 000000000..67a2705d0 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_error_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test get_object_vars() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_object_vars() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing get_object_vars() function with Zero arguments --\n"; +var_dump( get_object_vars() ); + +//Test get_object_vars with one more than the expected number of arguments +echo "\n-- Testing get_object_vars() function with more than expected no. of arguments --\n"; +$obj = new stdclass(); +$extra_arg = 10; +var_dump( get_object_vars($obj, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_object_vars() : error conditions *** + +-- Testing get_object_vars() function with Zero arguments -- + +Warning: Wrong parameter count for get_object_vars() in %s on line 12 +NULL + +-- Testing get_object_vars() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_object_vars() in %s on line 18 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_001.phpt b/ext/standard/tests/class_object/get_object_vars_variation_001.phpt new file mode 100644 index 000000000..89fbc53e9 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_001.phpt @@ -0,0 +1,20 @@ +--TEST-- +get_object_vars() - ensure statics are not shown +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class A { + public static $var = 'hello'; +} + +$a = new A; +var_dump(get_object_vars($a)); +?> +--EXPECTF-- +array(0) { +}
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_002.phpt b/ext/standard/tests/class_object/get_object_vars_variation_002.phpt new file mode 100644 index 000000000..73478de79 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_002.phpt @@ -0,0 +1,47 @@ +--TEST-- +get_object_vars() - ensure references are preserved +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +$obj = new stdClass; +var_dump(get_object_vars($obj)); + +$a='original.a'; +$obj->ref = &$a; +$obj->val = $a; + +$arr = get_object_vars($obj); +var_dump($arr); + +$arr['ref'] = 'changed.ref'; +$arr['val'] = 'changed.val'; + +var_dump($arr, $obj, $a); +?> +--EXPECTF-- +array(0) { +} +array(2) { + ["ref"]=> + &string(10) "original.a" + ["val"]=> + string(10) "original.a" +} +array(2) { + ["ref"]=> + &string(11) "changed.ref" + ["val"]=> + string(11) "changed.val" +} +object(stdClass)#1 (2) { + ["ref"]=> + &string(11) "changed.ref" + ["val"]=> + string(10) "original.a" +} +string(11) "changed.ref"
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_object_vars_variation_003.phpt b/ext/standard/tests/class_object/get_object_vars_variation_003.phpt new file mode 100644 index 000000000..70794e7d5 --- /dev/null +++ b/ext/standard/tests/class_object/get_object_vars_variation_003.phpt @@ -0,0 +1,158 @@ +--TEST-- +Test get_object_vars() function : usage variations - unexpected types for argument 1 +--FILE-- +<?php +/* Prototype : proto array get_object_vars(object obj) + * Description: Returns an array of object properties + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_object_vars() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for obj + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( get_object_vars($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_object_vars() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 56 + +Notice: Undefined variable: unset_var in %s on line 59 + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +bool(false) + +Arg value string +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_error_001.phpt b/ext/standard/tests/class_object/get_parent_class_error_001.phpt new file mode 100644 index 000000000..cf9c3e867 --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test get_parent_class() function : error conditions - wrong number of args. +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing get_parent_class() : error conditions ***\n"; + + +//Test get_parent_class with one more than the expected number of arguments +echo "\n-- Testing get_parent_class() function with more than expected no. of arguments --\n"; +$object = 1; +$extra_arg = 10; +var_dump( get_parent_class($object, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : error conditions *** + +-- Testing get_parent_class() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for get_parent_class() in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_variation_001.phpt b/ext/standard/tests/class_object/get_parent_class_variation_001.phpt new file mode 100644 index 000000000..6f2e32805 --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_variation_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test get_parent_class() function : variation - case sensitivity +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +// Note: basic use cases in Zend/tests/010.phpt + +echo "*** Testing get_parent_class() : variation ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(get_parent_class('CasesensitivitytestCHILD')); +var_dump(get_parent_class(new CasesensitivitytestCHILD)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : variation *** +string(19) "caseSensitivityTest" +string(19) "caseSensitivityTest" +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/get_parent_class_variation_002.phpt b/ext/standard/tests/class_object/get_parent_class_variation_002.phpt new file mode 100644 index 000000000..f7e5b9df3 --- /dev/null +++ b/ext/standard/tests/class_object/get_parent_class_variation_002.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test get_parent_class() function : usage variations - unexpected argument type. +--FILE-- +<?php +/* Prototype : proto string get_parent_class([mixed object]) + * Description: Retrieves the parent class name for object or class or current scope. + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing get_parent_class() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( get_parent_class($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing get_parent_class() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(68) +Error: 8 - Undefined variable: unset_var, %s(71) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a_error_001.phpt b/ext/standard/tests/class_object/is_a_error_001.phpt new file mode 100644 index 000000000..0d1aedca0 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_error_001.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test is_a() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_a() : error conditions ***\n"; + + +//Test is_a with one more than the expected number of arguments +echo "\n-- Testing is_a() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$class_name = 'string_val'; +$extra_arg = 10; +var_dump( is_a($object, $class_name, $extra_arg) ); + +// Testing is_a with one less than the expected number of arguments +echo "\n-- Testing is_a() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( is_a($object) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : error conditions *** + +-- Testing is_a() function with more than expected no. of arguments -- + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 16 + +Warning: Wrong parameter count for is_a() in %s on line 16 +NULL + +-- Testing is_a() function with less than expected no. of arguments -- + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 21 + +Warning: Wrong parameter count for is_a() in %s on line 21 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a_variation_001.phpt b/ext/standard/tests/class_object/is_a_variation_001.phpt new file mode 100644 index 000000000..d521502dc --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_001.phpt @@ -0,0 +1,213 @@ +--TEST-- +Test is_a() function : usage variations - wrong type for arg 1 +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +echo "*** Testing is_a() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'stdClass'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_a($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 59 + +Notice: Undefined variable: unset_var in %s on line 62 + +Arg value 0 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 12345 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value -2345 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 10.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value -10.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 101234567000 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1.07654321E-9 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 0.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value string + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value String + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 69 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a_variation_002.phpt b/ext/standard/tests/class_object/is_a_variation_002.phpt new file mode 100644 index 000000000..9835e7c68 --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_002.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test is_a() function : usage variations - wrong type for arg 2 +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +class C { + function __toString() { + return "C Instance"; + } +} + +echo "*** Testing is_a() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new C, + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class_name + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_a($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** + +Notice: Undefined variable: undefined_var in %s on line 64 + +Notice: Undefined variable: unset_var in %s on line 67 + +Arg value 0 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 12345 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value -2345 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 10.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value -10.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 101234567000 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1.07654321E-9 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 0.5 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value Array + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 + +Notice: Array to string conversion in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value 1 + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value C Instance + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) + +Arg value + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 74 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_a_variation_003.phpt b/ext/standard/tests/class_object/is_a_variation_003.phpt new file mode 100644 index 000000000..9cc50f34b --- /dev/null +++ b/ext/standard/tests/class_object/is_a_variation_003.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test is_a() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool is_a(object object, string class_name) + * Description: Returns true if the object is of this class or has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_a() : usage variations ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(is_a(new caseSensitivityTestChild, 'caseSensitivityTEST')); + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_a() : usage variations *** + +Strict Standards: is_a(): Deprecated. Please use the instanceof operator in %s on line 13 +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_error_001.phpt b/ext/standard/tests/class_object/is_subclass_of_error_001.phpt new file mode 100644 index 000000000..4403bde4c --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_error_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test is_subclass_of() function : wrong number of args +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_subclass_of() : error conditions ***\n"; + + +//Test is_subclass_of with one more than the expected number of arguments +echo "\n-- Testing is_subclass_of() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$class_name = 'string_val'; +$extra_arg = 10; +var_dump( is_subclass_of($object, $class_name, $extra_arg) ); + +// Testing is_subclass_of with one less than the expected number of arguments +echo "\n-- Testing is_subclass_of() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( is_subclass_of($object) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : error conditions *** + +-- Testing is_subclass_of() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for is_subclass_of() in %s on line 16 +NULL + +-- Testing is_subclass_of() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for is_subclass_of() in %s on line 21 +NULL +Done diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt new file mode 100644 index 000000000..f11183d48 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_001.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ +// Note: basic use cases in Zend/tests/is_a.phpt +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$class_name = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($value, $class_name) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(69) +Error: 8 - Undefined variable: unset_var, %s(72) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value string +In __autoload(string) +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value String +In __autoload(String) +Error: 2 - Unknown class passed as parameter, %s(79) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt new file mode 100644 index 000000000..a45583ce6 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_002.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test is_subclass_of() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for class_name + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( is_subclass_of($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) +Error: 8 - Object of class stdClass to string conversion, %s(77) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt b/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt new file mode 100644 index 000000000..d4aef1234 --- /dev/null +++ b/ext/standard/tests/class_object/is_subclass_of_variation_003.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test is_subclass_of() function : usage variations - case sensitivity +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing is_subclass_of() : usage variations ***\n"; + +echo "*** Testing is_a() : usage variations ***\n"; + +class caseSensitivityTest {} +class caseSensitivityTestChild extends caseSensitivityTest {} + +var_dump(is_subclass_of('caseSensitivityTestCHILD', 'caseSensitivityTEST')); + +echo "Done" +?> +--EXPECTF-- +*** Testing is_subclass_of() : usage variations *** +*** Testing is_a() : usage variations *** +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_001.phpt b/ext/standard/tests/class_object/method_exists_basic_001.phpt new file mode 100644 index 000000000..2f11e4c46 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_001.phpt @@ -0,0 +1,83 @@ +--TEST-- +method_exists() on userspace classes; static & non-static methods with various visibilities. +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +Class B { + public function inherit_pub() {} + protected function inherit_prot() {} + private function inherit_priv() {} + static public function inherit_static_pub() {} + static protected function inherit_static_prot() {} + static private function inherit_static_priv() {} +} + +Class C extends B { + public function pub() {} + protected function prot() {} + private function priv() {} + static public function static_pub() {} + static protected function static_prot() {} + static private function static_priv() {} +} + + +$methods = array( + 'inherit_pub', 'inherit_prot', 'inherit_priv', + 'inherit_static_pub', 'inherit_static_prot', 'inherit_static_priv', + 'pub', 'prot', 'priv', + 'static_pub', 'static_prot', 'static_priv', + 'non_existent'); + +echo "\n ---(Using string class name)---\n"; +foreach ($methods as $method) { + echo "Does C::$method exist? "; + var_dump(method_exists("C", $method)); +} + +echo "\n ---(Using object)---\n"; +$myC = new C; +foreach ($methods as $method) { + echo "Does C::$method exist? "; + var_dump(method_exists($myC, $method)); +} + +echo "Done"; +?> +--EXPECTF-- + + ---(Using string class name)--- +Does C::inherit_pub exist? bool(true) +Does C::inherit_prot exist? bool(true) +Does C::inherit_priv exist? bool(true) +Does C::inherit_static_pub exist? bool(true) +Does C::inherit_static_prot exist? bool(true) +Does C::inherit_static_priv exist? bool(true) +Does C::pub exist? bool(true) +Does C::prot exist? bool(true) +Does C::priv exist? bool(true) +Does C::static_pub exist? bool(true) +Does C::static_prot exist? bool(true) +Does C::static_priv exist? bool(true) +Does C::non_existent exist? bool(false) + + ---(Using object)--- +Does C::inherit_pub exist? bool(true) +Does C::inherit_prot exist? bool(true) +Does C::inherit_priv exist? bool(true) +Does C::inherit_static_pub exist? bool(true) +Does C::inherit_static_prot exist? bool(true) +Does C::inherit_static_priv exist? bool(true) +Does C::pub exist? bool(true) +Does C::prot exist? bool(true) +Does C::priv exist? bool(true) +Does C::static_pub exist? bool(true) +Does C::static_prot exist? bool(true) +Does C::static_priv exist? bool(true) +Does C::non_existent exist? bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_002.phpt b/ext/standard/tests/class_object/method_exists_basic_002.phpt new file mode 100644 index 000000000..f6b62aa26 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_002.phpt @@ -0,0 +1,33 @@ +--TEST-- +method_exists() on internal classes +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo " ---(Internal classes, using string class name)---\n"; +echo "Does exception::getmessage exist? "; +var_dump(method_exists("exception", "getmessage")); +echo "Does stdclass::nonexistent exist? "; +var_dump(method_exists("stdclass", "nonexistent")); + +echo "\n ---(Internal classes, using class instance)---\n"; +echo "Does exception::getmessage exist? "; +var_dump(method_exists(new exception, "getmessage")); +echo "Does stdclass::nonexistent exist? "; +var_dump(method_exists(new stdclass, "nonexistent")); + +echo "Done"; +?> +--EXPECTF-- + ---(Internal classes, using string class name)--- +Does exception::getmessage exist? bool(true) +Does stdclass::nonexistent exist? bool(false) + + ---(Internal classes, using class instance)--- +Does exception::getmessage exist? bool(true) +Does stdclass::nonexistent exist? bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_basic_003.phpt b/ext/standard/tests/class_object/method_exists_basic_003.phpt new file mode 100644 index 000000000..32f62b7e4 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_basic_003.phpt @@ -0,0 +1,22 @@ +--TEST-- +method_exists() on non-existent class, with __autoload(). +--FILE-- +<?php +/* Prototype : proto bool is_subclass_of(object object, string class_name) + * Description: Returns true if the object has this class as one of its parents + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($name) { + echo "In __autoload($name)\n"; +} + +var_dump(method_exists('UndefC', 'func')); + +echo "Done"; +?> +--EXPECTF-- +In __autoload(UndefC) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_error_001.phpt b/ext/standard/tests/class_object/method_exists_error_001.phpt new file mode 100644 index 000000000..203128c67 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_error_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test method_exists() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing method_exists() : error conditions ***\n"; + + +//Test method_exists with one more than the expected number of arguments +echo "\n-- Testing method_exists() function with more than expected no. of arguments --\n"; +$object = new stdclass(); +$method = 'string_val'; +$extra_arg = 10; +var_dump( method_exists($object, $method, $extra_arg) ); + +// Testing method_exists with one less than the expected number of arguments +echo "\n-- Testing method_exists() function with less than expected no. of arguments --\n"; +$object = new stdclass(); +var_dump( method_exists($object) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : error conditions *** + +-- Testing method_exists() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for method_exists() in %s on line 16 +NULL + +-- Testing method_exists() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for method_exists() in %s on line 21 +NULL +Done diff --git a/ext/standard/tests/class_object/method_exists_variation_001.phpt b/ext/standard/tests/class_object/method_exists_variation_001.phpt new file mode 100644 index 000000000..117c211d0 --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_001.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test method_exists() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing method_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$method = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'String', + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for object + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( method_exists($value, $method) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(68) +Error: 8 - Undefined variable: unset_var, %s(71) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value Array +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value string +In __autoload(string) +bool(false) + +Arg value String +In __autoload(String) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_variation_002.phpt b/ext/standard/tests/class_object/method_exists_variation_002.phpt new file mode 100644 index 000000000..54d0ef94f --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_002.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test method_exists() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +function __autoload($className) { + echo "In __autoload($className)\n"; +} + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing method_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$object = new stdclass(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for method + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( method_exists($object, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +bool(false) + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(77) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value 1 +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(77) +Error: 8 - Object of class stdClass to string conversion, %s(77) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/class_object/method_exists_variation_003.phpt b/ext/standard/tests/class_object/method_exists_variation_003.phpt new file mode 100644 index 000000000..debe5a35e --- /dev/null +++ b/ext/standard/tests/class_object/method_exists_variation_003.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test method_exists() function : variation - Case sensitivity +--FILE-- +<?php +/* Prototype : proto bool method_exists(object object, string method) + * Description: Checks if the class method exists + * Source code: Zend/zend_builtin_functions.c + * Alias to functions: + */ + +echo "*** Testing method_exists() : variation ***\n"; + +Class caseSensitivityTest { + public function myMethod() {} +} + +var_dump(method_exists(new casesensitivitytest, 'myMetHOD')); +var_dump(method_exists('casesensiTivitytest', 'myMetHOD')); + +echo "Done"; +?> +--EXPECTF-- +*** Testing method_exists() : variation *** +bool(true) +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/dir/chdir_basic.phpt b/ext/standard/tests/dir/chdir_basic.phpt new file mode 100644 index 000000000..5fc0e5b88 --- /dev/null +++ b/ext/standard/tests/dir/chdir_basic.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test chdir() function : basic functionality +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of chdir() with absolute and relative paths + */ + +echo "*** Testing chdir() : basic functionality ***\n"; +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "level_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "level_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- Testing chdir() with absolute path: --\n"; +chdir($base_dir_path); +var_dump(chdir($level_one_dir_path)); +var_dump(getcwd()); + +echo "\n-- Testing chdir() with relative paths: --\n"; +var_dump(chdir($level_two_dir_name)); +var_dump(getcwd()); +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/level_one/level_two"); +rmdir("$file_path/level_one"); +?> +--EXPECTF-- +*** Testing chdir() : basic functionality *** + +-- Testing chdir() with absolute path: -- +bool(true) +string(%d) "%slevel_one" + +-- Testing chdir() with relative paths: -- +bool(true) +string(%d) "%slevel_one%elevel_two" +===DONE=== diff --git a/ext/standard/tests/dir/chdir_error1.phpt b/ext/standard/tests/dir/chdir_error1.phpt new file mode 100644 index 000000000..0f57ff5b2 --- /dev/null +++ b/ext/standard/tests/dir/chdir_error1.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test chdir() function : error conditions - Incorrect number of arguments +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to chdir() to test behaviour + */ + +echo "*** Testing chdir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing chdir() function with Zero arguments --\n"; +var_dump( chdir() ); + +//Test chdir with one more than the expected number of arguments +echo "\n-- Testing chdir() function with more than expected no. of arguments --\n"; +$directory = __FILE__; +$extra_arg = 10; +var_dump( chdir($directory, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing chdir() : error conditions *** + +-- Testing chdir() function with Zero arguments -- + +Warning: chdir() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing chdir() function with more than expected no. of arguments -- + +Warning: chdir() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/chdir_error2.phpt b/ext/standard/tests/dir/chdir_error2.phpt new file mode 100644 index 000000000..a3bbb63e6 --- /dev/null +++ b/ext/standard/tests/dir/chdir_error2.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test chdir() function : error conditions - Non-existent directory +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory that does not exist as $directory to chdir() to test behaviour + */ + +echo "*** Testing chdir() : error conditions ***\n"; + +$directory = __FILE__ . '/idonotexist'; + +var_dump(chdir($directory)); +?> +===DONE=== +--EXPECTF-- +*** Testing chdir() : error conditions *** + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/chdir_variation1.phpt b/ext/standard/tests/dir/chdir_variation1.phpt new file mode 100644 index 000000000..a7cf857f7 --- /dev/null +++ b/ext/standard/tests/dir/chdir_variation1.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test chdir() function : usage variations - different data type as $directory arg +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $directory argument to test behaviour + */ + +echo "*** Testing chdir() : usage variations ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/chdir_basic"; +@mkdir($dir_path); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA { + var $dir_path; + + function __construct($dir) { + $this->dir_path = $dir; + } + + public function __toString() { + return "$this->dir_path"; + } +} + +// heredoc string +$heredoc = <<<EOT +$dir_path +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $directory argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "$dir_path", + 'string', + $heredoc, + + // object data +/*22*/ new classA($dir_path), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of chdir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( chdir($input) ); + $iterator++; +}; + +fclose($fp); + +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/chdir_basic"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing chdir() : usage variations *** + +-- Iteration 1 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: chdir() expects parameter 1 to be string, array given in %s on line %d +bool(false) + +-- Iteration 19 -- +bool(true) + +-- Iteration 20 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 21 -- +bool(true) + +-- Iteration 22 -- +bool(true) + +-- Iteration 23 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: chdir(): %s (errno %d) in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: chdir() expects parameter 1 to be string, resource given in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/chdir_variation2.phpt b/ext/standard/tests/dir/chdir_variation2.phpt new file mode 100644 index 000000000..fa70f9e10 --- /dev/null +++ b/ext/standard/tests/dir/chdir_variation2.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test chdir() function : usage variations - relative paths +--FILE-- +<?php +/* Prototype : bool chdir(string $directory) + * Description: Change the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test chdir() with variations of relative paths + */ + +echo "*** Testing chdir() : usage variations ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "level_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "level_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- \$directory = './level_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(chdir("./$level_one_dir_name")); +var_dump(getcwd()); + +echo "\n-- \$directory = 'level_one/level_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(chdir("$level_one_dir_name/$level_two_dir_name")); +var_dump(getcwd()); + +echo "\n-- \$directory = '..': --\n"; +var_dump(chdir('..')); +var_dump(getcwd()); + +echo "\n-- \$directory = 'level_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir('.')); +var_dump(getcwd()); + +echo "\n-- \$directory = '../': --\n"; +var_dump(chdir('../')); +var_dump(getcwd()); + +echo "\n-- \$directory = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir('./')); +var_dump(getcwd()); + +echo "\n-- \$directory = '../../'level_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(chdir("../../$level_one_dir_name")); +var_dump(getcwd()); + +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/level_one/level_two"); +rmdir("$file_path/level_one"); +?> +--EXPECTF-- +*** Testing chdir() : usage variations *** + +-- $directory = './level_one': -- +bool(true) +bool(true) +string(%d) "%slevel_one" + +-- $directory = 'level_one/level_two': -- +bool(true) +bool(true) +string(%d) "%slevel_one%elevel_two" + +-- $directory = '..': -- +bool(true) +string(%d) "%slevel_one" + +-- $directory = 'level_two', '.': -- +bool(true) +bool(true) +string(%d) "%slevel_one%elevel_two" + +-- $directory = '../': -- +bool(true) +string(%d) "%slevel_one" + +-- $directory = './': -- +bool(true) +bool(true) +string(%d) "%slevel_one%elevel_two" + +-- $directory = '../../'level_one': -- +bool(true) +bool(true) +string(%d) "%slevel_one" +===DONE=== diff --git a/ext/standard/tests/dir/closedir_basic.phpt b/ext/standard/tests/dir/closedir_basic.phpt new file mode 100644 index 000000000..49080bb6a --- /dev/null +++ b/ext/standard/tests/dir/closedir_basic.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test closedir() function : basic functionality +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Test basic functionality of closedir() + */ + +echo "*** Testing closedir() : basic functionality ***\n"; + +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '/closedir_basic'; +mkdir($dir_path); + +echo "\n-- Call closedir() with no arguments: --\n"; +$dh1 = opendir($dir_path); +var_dump(closedir()); +echo "-- Check Directory Handle: --\n"; +var_dump($dh1); + +echo "\n-- Call closedir() with \$dir_handle argument supplied: --\n"; +$dh2 = opendir($dir_path); + +if ((int)$dh1 === (int)$dh2) { + echo "\nNo new resource created\n"; +} +var_dump(closedir($dh2)); +echo "-- Check Directory Handle: --\n"; +var_dump($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '/closedir_basic'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing closedir() : basic functionality *** + +-- Call closedir() with no arguments: -- +NULL +-- Check Directory Handle: -- +resource(%d) of type (Unknown) + +-- Call closedir() with $dir_handle argument supplied: -- +NULL +-- Check Directory Handle: -- +resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/closedir_error.phpt b/ext/standard/tests/dir/closedir_error.phpt new file mode 100644 index 000000000..1a8a043d0 --- /dev/null +++ b/ext/standard/tests/dir/closedir_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test closedir() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Pass incorrect number of arguments to closedir() to test behaviour + */ + +echo "*** Testing closedir() : error conditions ***\n"; + + +//Test closedir with one more than the expected number of arguments +echo "\n-- Testing closedir() function with more than expected no. of arguments --\n"; + +$dir_path = dirname(__FILE__) . '\closedir_error'; +mkdir($dir_path); +$dir_handle = opendir($dir_path); + +$extra_arg = 10; +var_dump( closedir($dir_handle, $extra_arg) ); + +//successfully close the directory handle so can delete in CLEAN section +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$base_dir = dirname(__FILE__); +$dir_path = $base_dir . '\closedir_error'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing closedir() : error conditions *** + +-- Testing closedir() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for closedir() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/closedir_variation1.phpt b/ext/standard/tests/dir/closedir_variation1.phpt new file mode 100644 index 000000000..d5c843996 --- /dev/null +++ b/ext/standard/tests/dir/closedir_variation1.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test closedir() function : usage variations - different data types as $dir_handle arg +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Pass different data types as $dir_handle argument to closedir() to test behaviour + */ + +echo "*** Testing closedir() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $dir_handle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of closedir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( closedir($input) ); + $iterator++; +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing closedir() : usage variations *** + +-- Iteration 1 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/closedir_variation2.phpt b/ext/standard/tests/dir/closedir_variation2.phpt new file mode 100644 index 000000000..015176c84 --- /dev/null +++ b/ext/standard/tests/dir/closedir_variation2.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test closedir() function : usage variations - close directory handle twice +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * close the directory handle twice using closedir() to test behaviour + */ + +echo "*** Testing closedir() : usage variations ***\n"; + +//create temporary directory for test, removed in CLEAN section +$directory = dirname(__FILE__) . "/closedir_variation2"; +mkdir($directory); + +$dh = opendir($directory); + +echo "\n-- Close directory handle first time: --\n"; +var_dump(closedir($dh)); +echo "Directory Handle: "; +var_dump($dh); + +echo "\n-- Close directory handle second time: --\n"; +var_dump(closedir($dh)); +echo "Directory Handle: "; +var_dump($dh); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . "/closedir_variation2"; +rmdir($directory); +?> +--EXPECTF-- +*** Testing closedir() : usage variations *** + +-- Close directory handle first time: -- +NULL +Directory Handle: resource(%d) of type (Unknown) + +-- Close directory handle second time: -- + +Warning: closedir(): %d is not a valid Directory resource in %s on line %d +bool(false) +Directory Handle: resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/closedir_variation3.phpt b/ext/standard/tests/dir/closedir_variation3.phpt new file mode 100644 index 000000000..b9b5e67e7 --- /dev/null +++ b/ext/standard/tests/dir/closedir_variation3.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test closedir() function : usage variations - close a file pointer +--FILE-- +<?php +/* Prototype : void closedir([resource $dir_handle]) + * Description: Close directory connection identified by the dir_handle + * Source code: ext/standard/dir.c + * Alias to functions: close + */ + +/* + * Create a file pointer using fopen() then try to close it using closedir() + */ + +echo "*** Testing closedir() : usage variations ***\n"; + +echo "\n-- Open a file using fopen() --\n"; +var_dump($fp = fopen(__FILE__, 'r')); + +echo "\n-- Try to close the file pointer using closedir() --\n"; +var_dump(closedir($fp)); + +echo "\n-- Check file pointer: --\n"; +var_dump($fp); + +if(is_resource($fp)) { + fclose($fp); +} +?> +===DONE=== +--EXPECTF-- +*** Testing closedir() : usage variations *** + +-- Open a file using fopen() -- +resource(%d) of type (stream) + +-- Try to close the file pointer using closedir() -- + +Warning: closedir(): %d is not a valid Directory resource in %s on line %d +bool(false) + +-- Check file pointer: -- +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/dir_basic.phpt b/ext/standard/tests/dir/dir_basic.phpt new file mode 100644 index 000000000..dba49dba0 --- /dev/null +++ b/ext/standard/tests/dir/dir_basic.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test dir() function : basic functionality +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +echo "*** Testing dir() : basic functionality ***\n"; + +// include the file.inc for Function: function create_files() +include(dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_basic"; +@mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "dir_basic"); + +echo "Get Directory instance:\n"; +$d = dir($dir_path); +var_dump( $d ); + +echo "\nRead and rewind:\n"; +var_dump( $d->read() ); +var_dump( $d->read() ); +var_dump( $d->rewind() ); + +echo "\nTest using handle directly:\n"; +var_dump( readdir($d->handle) ); +var_dump( readdir($d->handle) ); + +echo "\nClose directory:\n"; +var_dump( $d->close() ); +var_dump( $d ); + +echo "\nTest read after closing the dir:"; +var_dump( $d->read() ); + +// delete temp files +delete_files($dir_path, 3, "dir_basic", 1, ".tmp"); +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_basic"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing dir() : basic functionality *** +Get Directory instance: +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_basic" + ["handle"]=> + resource(%d) of type (stream) +} + +Read and rewind: +string(%d) "%s" +string(%d) "%s" +NULL + +Test using handle directly: +string(%d) "%s" +string(%d) "%s" + +Close directory: +NULL +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_basic" + ["handle"]=> + resource(%d) of type (Unknown) +} + +Test read after closing the dir: +Warning: Directory::read(): %d is not a valid Directory resource in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/dir/dir_error.phpt b/ext/standard/tests/dir/dir_error.phpt new file mode 100644 index 000000000..f2ef25cc8 --- /dev/null +++ b/ext/standard/tests/dir/dir_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test dir() function : error conditions +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +echo "*** Testing dir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing dir() function with zero arguments --"; +var_dump( dir() ); + +// With one more than expected number of arguments +echo "\n-- Testing dir() function with one more than expected number of arguments --"; +$extra_arg = 10; +var_dump( dir(getcwd(), "stream", $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : error conditions *** + +-- Testing dir() function with zero arguments -- +Warning: dir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing dir() function with one more than expected number of arguments -- +Warning: dir() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/dir/dir_variation1.phpt b/ext/standard/tests/dir/dir_variation1.phpt new file mode 100644 index 000000000..ad912c008 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation1.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test dir() function : usage variations - unexpected value for 'dir' argument +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Passing non string values to 'directory' argument of dir() and see + * that the function outputs proper warning messages wherever expected. + */ + +echo "*** Testing dir() : unexpected values for \$directory argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset($unset_var); + +class A +{ + public $var; + public function init() { + $this->var = 10; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); // get a file handle +$dfp = opendir( dirname(__FILE__) ); // get a dir handle + +// unexpected values to be passed to $directory argument +$unexpected_values = array ( + + // array data +/*1*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*6*/ NULL, + null, + + // boolean data +/*8*/ true, + false, + TRUE, + FALSE, + + // empty data +/*12*/ "", + '', + + // undefined data +/*14*/ @$undefined_var, + + // unset data +/*15*/ @$unset_var, + + // resource variable(dir and file handle) +/*16*/ $fp, + $dfp, + + // object data +/*18*/ new A() +); + +// loop through various elements of $unexpected_values to check the behavior of dir() +$iterator = 1; +foreach( $unexpected_values as $unexpected_value ) { + echo "\n-- Iteration $iterator --\n"; + var_dump( dir($unexpected_value) ); + $iterator++; +} + +fclose($fp); +closedir($dfp); +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : unexpected values for $directory argument *** + +-- Iteration 1 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: dir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) + +-- Iteration 8 -- + +Warning: dir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 9 -- +bool(false) + +-- Iteration 10 -- + +Warning: dir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- + +Warning: dir() expects parameter 1 to be string, resource given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: dir() expects parameter 1 to be string, resource given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: dir() expects parameter 1 to be string, object given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation2.phpt b/ext/standard/tests/dir/dir_variation2.phpt new file mode 100644 index 000000000..ee42900ee --- /dev/null +++ b/ext/standard/tests/dir/dir_variation2.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test dir() function : usage variations - unexpected value for 'context' argument +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Passing non resource values to 'context' argument of dir() and see + * that the function outputs proper warning messages wherever expected. + */ + +echo "*** Testing dir() : unexpected values for \$context argument ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$directory = $file_path."/dir_variation2"; +@mkdir($directory); + +// get an unset variable +$unset_var = stream_context_create(); +unset($unset_var); + +class classA +{ + public $var; + public function init() { + $this->var = 10; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $directory argument +$unexpected_values = array ( + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // object data +/*26*/ new classA(), + + // undefined data +/*27*/ @$undefined_var, + + // unset data +/*28*/ @$unset_var +); + +// loop through various elements of $unexpected_values to check the behavior of dir() +$iterator = 1; +foreach( $unexpected_values as $unexpected_value ) { + echo "\n-- Iteration $iterator --"; + var_dump( dir($directory, $unexpected_value) ); + $iterator++; +} + +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$directory = $file_path."/dir_variation2"; + +rmdir($directory); +?> +--EXPECTF-- +*** Testing dir() : unexpected values for $context argument *** + +-- Iteration 1 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: dir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: dir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: dir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: dir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 25 -- +Warning: dir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 26 -- +Warning: dir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 27 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 28 -- +Warning: dir() expects parameter 2 to be resource, null given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation3.phpt b/ext/standard/tests/dir/dir_variation3.phpt new file mode 100644 index 000000000..f8d325874 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation3.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test dir() function : usage variations - different directory permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/dir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Providing various permissions to the directory to be opened and checking + * to see if dir() function opens the directory successfully. + */ + +echo "*** Testing dir() : different directory permissions ***"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation3"; +@mkdir($dir_path); + +/* different values for directory permissions */ +$permission_values = array( +/*1*/ 0477, // owner has read only, other and group has rwx + 0677, // owner has rw only, other and group has rwx + +/*3*/ 0444, // all have read only + 0666, // all have rw only + +/*5*/ 0400, // owner has read only, group and others have no permission + 0600, // owner has rw only, group and others have no permission + +/*7*/ 0470, // owner has read only, group has rwx & others have no permission + 0407, // owner has read only, other has rwx & group has no permission + +/*9*/ 0670, // owner has rw only, group has rwx & others have no permission +/*10*/ 0607 // owner has rw only, group has no permission and others have rwx +); + +// Open directory with different permission values, read and close, expected: none of them to succeed. +for($count = 0; $count < count($permission_values); $count++) { + echo "\n-- Iteration ".($count + 1)." --\n"; + + // try to remove the dir if exists & create + $file_path = dirname(__FILE__); + $dir_path = $file_path."/dir_variation3"; + @chmod ($dir_path, 0777); // change dir permission to allow all operation + @rmdir ($dir_path); // try n delete the dir + + // create the dir now + @mkdir($dir_path); + + // change the dir permisson to test dir on it + var_dump( chmod($dir_path, $permission_values[$count]) ); + + // try to get dir handle + $d = dir($dir_path); + var_dump($d); // dump the handle + + // try read directory, expected : false + echo "-- reading contents --\n"; + var_dump($d->read()); + + // close directory + $d->close(); +} + +echo "Done"; +?> +--CLEAN-- +<?php +// deleting temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation3"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing dir() : different directory permissions *** +-- Iteration 1 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 2 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 3 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 4 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 5 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 6 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 7 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 8 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 9 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" + +-- Iteration 10 -- +bool(true) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation3" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading contents -- +string(%d) "%s" +Done diff --git a/ext/standard/tests/dir/dir_variation4.phpt b/ext/standard/tests/dir/dir_variation4.phpt new file mode 100644 index 000000000..62b10b2a8 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation4.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test dir() function : usage variations - operate on previously opened directory +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Testing the behavior of dir() function by trying to open a + * directory which is already open. + */ + +echo "*** Testing dir() : operate on previously opened directory ***\n"; + +// include the file.inc for Function: function create_files() +include( dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation4"; +@mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "dir_variation4"); + +// open the directory +$d = dir($dir_path); +var_dump( $d ); + +// open the same directory again without closing it +$e = dir($dir_path); +var_dump( $e ); + +echo "-- reading directory contents with previous handle --\n"; +var_dump( $d->read() ); // with previous handle + +echo "-- reading directory contents with current handle --\n"; +var_dump( $e->read() ); // with current handle + +// delete temporary files +delete_files($dir_path, 3, "dir_variation4"); +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation4"; + +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing dir() : operate on previously opened directory *** +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation4" + ["handle"]=> + resource(%d) of type (stream) +} +-- reading directory contents with previous handle -- +string(%d) "%s" +-- reading directory contents with current handle -- +string(%d) "%s" +Done diff --git a/ext/standard/tests/dir/dir_variation5.phpt b/ext/standard/tests/dir/dir_variation5.phpt new file mode 100644 index 000000000..2399c634c --- /dev/null +++ b/ext/standard/tests/dir/dir_variation5.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test dir() function : usage variations - open a file instead of directory +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Passing a file as argument to dir() function instead of a directory + * and checking if proper warning message is generated. + */ + +echo "*** Testing dir() : open a file instead of a directory ***\n"; + +// open the file instead of directory +$d = dir(__FILE__); +var_dump( $d ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : open a file instead of a directory *** + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation6.phpt b/ext/standard/tests/dir/dir_variation6.phpt new file mode 100644 index 000000000..e42057ed1 --- /dev/null +++ b/ext/standard/tests/dir/dir_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test dir() function : usage variations - non-existent directory +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Passing a non-existent directory as argument to dir() function + * and checking to see if proper warning message is output. + */ +echo "*** Testing dir() : open a non-existent directory ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation6"; +@mkdir($dir_path); + +// open existent directory +$d = dir($dir_path); +$d->close(); //close the dir + +// remove directory and try to open the same(non-existent) directory again +rmdir($dir_path); +clearstatcache(); + +echo "-- opening previously removed directory --\n"; +var_dump( dir($dir_path) ); + +// point to a non-existent directory +$non_existent_dir = $file_path."/non_existent_dir"; +echo "-- opening non-existent directory --\n"; +$d = dir($non_existent_dir); +var_dump( $d ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing dir() : open a non-existent directory *** +-- opening previously removed directory -- + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +-- opening non-existent directory -- + +Warning: dir(%s): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation7.phpt b/ext/standard/tests/dir/dir_variation7.phpt new file mode 100644 index 000000000..ca168f90a --- /dev/null +++ b/ext/standard/tests/dir/dir_variation7.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test dir() function : usage variations - directories with restricted permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/dir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * remove the execute permission from the parent dir and test dir() on child dir + * 1) remove write & execute permission from the 1st parent and test dir() + * 2) remove execute permission from 2nd parent and test dir() + */ + +echo "*** Testing dir() : remove execute permission from the parent dir ***\n"; + +/* create the temporary directory : + dir_variation7 ( parent ) + |-> sub_dir ( sub parent ) + |-> child_dir ( child dir) +*/ +$file_path = dirname(__FILE__); +$parent_dir_path = $file_path."/dir_variation7"; +@mkdir($parent_dir_path); +chmod($parent_dir_path, 0777); + +// create sub_dir +$sub_dir_path = $parent_dir_path."/sub_dir"; +@mkdir($sub_dir_path); +chmod($sub_dir_path, 0777); + +//create sub_sub_dir +$child_dir_path = $sub_dir_path."/child_dir"; +@mkdir($child_dir_path); + +// remove the write and execute permisson from sub parent +chmod($sub_dir_path, 0444); +echo "-- After restricting 1st level parent directory --\n"; +$d = dir($child_dir_path); // try to open, expected failure +var_dump( $d ); // dump it + +// remove the execute permisson from parent dir, allowing all permission for sub dir +chmod($sub_dir_path, 0777); // all permisson to sub dir +chmod($parent_dir_path, 0666); // restricting parent directory +echo "-- After restricting parent directory --\n"; +$d = dir($child_dir_path); // try to open, expected failure +var_dump( $d ); // dump it + +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$parent_dir_path = $file_path."/dir_variation7"; +$sub_dir_path = $parent_dir_path."/sub_dir"; +$child_dir_path = $sub_dir_path."/child_dir"; + +// changing permissions for each temporary directory to delete them +chmod($parent_dir_path, 0777); +chmod($sub_dir_path, 0777); +chmod($child_dir_path, 0777); + +rmdir($child_dir_path); +rmdir($sub_dir_path); +rmdir($parent_dir_path); +?> +--EXPECTF-- +*** Testing dir() : remove execute permission from the parent dir *** +-- After restricting 1st level parent directory -- + +Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d +bool(false) +-- After restricting parent directory -- + +Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/dir/dir_variation8.phpt b/ext/standard/tests/dir/dir_variation8.phpt new file mode 100644 index 000000000..41217500d --- /dev/null +++ b/ext/standard/tests/dir/dir_variation8.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test dir() function : usage variations - checking with wildcard characters +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Create more than one temporary directory & subdirectory and check if dir() function can open + * those directories when wildcard characters are used to refer to them. + */ + +echo "*** Testing dir() : checking with wildcard characters ***\n"; + +// create the temporary directories +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation81"; +$sub_dir_path = $dir_path."/sub_dir1"; + +@mkdir($dir_path1); +@mkdir($sub_dir_path); + +/* with different wildcard characters */ + +echo "-- wildcard = '*' --\n"; +var_dump( dir($file_path."/dir_var*") ); +var_dump( dir($file_path."/*") ); + +echo "-- wildcard = '?' --\n"; +var_dump( dir($dir_path."/sub_dir?") ); +var_dump( dir($dir_path."/sub?dir1") ); + +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +$dir_path = $file_path."/dir_variation81"; +$sub_dir_path = $dir_path."/sub_dir1"; + +rmdir($dir_path1); +rmdir($dir_path2); +?> +--EXPECTF-- +*** Testing dir() : checking with wildcard characters *** +-- wildcard = '*' -- + +Warning: dir(%s/dir_var*): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/*): failed to open dir: %s in %s on line %d +bool(false) +-- wildcard = '?' -- + +Warning: dir(%s/dir_variation81/sub_dir?): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation81/sub?dir1): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/dir_variation9.phpt b/ext/standard/tests/dir/dir_variation9.phpt new file mode 100644 index 000000000..22f3d5baa --- /dev/null +++ b/ext/standard/tests/dir/dir_variation9.phpt @@ -0,0 +1,111 @@ +--TEST-- +Test dir() function : usage variations - relative valid and invalid paths +--FILE-- +<?php +/* + * Prototype : object dir(string $directory[, resource $context]) + * Description: Directory class with properties, handle and class and methods read, rewind and close + * Source code: ext/standard/dir.c + */ + +/* + * Checking the behavior of dir() function by passing directories which + * have valid and invalid relative path. + */ + +echo "*** Testing dir() : checking with valid and invalid paths ***\n"; + +/* create the temporary directories */ + +$file_path = dirname(__FILE__); + +// directory dir_variation91 with one sub-directory sub_dir11 and sub-sub-directory sub_dir111 +$dir_path1 = $file_path."/dir_variation91"; +$sub_dir11 = $dir_path1."/sub_dir11"; +$sub_dir111 = $sub_dir11."/sub_dir111"; + +// directory dir_variation92 with one sub-directory sub_dir21 +$dir_path2 = $file_path."/dir_variation92"; +$sub_dir21 = $dir_path2."/sub_dir21"; + +@mkdir($dir_path1); +@mkdir($dir_path2); +@mkdir($sub_dir11); +@mkdir($sub_dir111); +@mkdir($sub_dir21); + +// open the directory with valid paths +echo "\n-- With valid paths --\n"; +var_dump( dir("$dir_path1/sub_dir11/sub_dir111/..") ); +var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91") ); +var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir11/..") ); +var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/..") ); + +// open the directory with invalid path +echo "\n-- With invalid paths --\n"; +var_dump( dir("$dir_path1/sub_dir12/sub_dir111/..") ); +var_dump( dir("$dir_path2/sub_dir21/../dir_variation91") ); +var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir12/..") ); +var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..") ); + +echo "Done"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); + +$dir_path1 = $file_path."/dir_variation91"; +$sub_dir11 = $dir_path1."/sub_dir11"; +$sub_dir111 = $sub_dir11."/sub_dir111"; +$dir_path2 = $file_path."/dir_variation92"; +$sub_dir21 = $dir_path2."/sub_dir21"; + +rmdir($sub_dir21); +rmdir($sub_dir111); +rmdir($sub_dir11); +rmdir($dir_path1); +rmdir($dir_path2); +?> +--EXPECTF-- +*** Testing dir() : checking with valid and invalid paths *** + +-- With valid paths -- +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/.." + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir11/.." + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/.." + ["handle"]=> + resource(%d) of type (stream) +} + +-- With invalid paths -- + +Warning: dir(%s/dir_variation91/sub_dir12/sub_dir111/..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation92/sub_dir21/../dir_variation91): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir12/..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(%s/dir_variation91/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..): failed to open dir: %s in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/dir/getcwd_basic.phpt b/ext/standard/tests/dir/getcwd_basic.phpt new file mode 100644 index 000000000..ef720d095 --- /dev/null +++ b/ext/standard/tests/dir/getcwd_basic.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test getcwd() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed getcwd(void) + * Description: Gets the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of getcwd() + */ + +echo "*** Testing getcwd() : basic functionality ***\n"; + +//create temporary directory for test, removed in CLEAN section +$directory = dirname(__FILE__) . "/getcwd_basic"; +mkdir($directory); + +var_dump(getcwd()); +chdir($directory); +var_dump(getcwd()); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . "/getcwd_basic"; +rmdir($directory); +?> +--EXPECTF-- +*** Testing getcwd() : basic functionality *** +string(%d) "%s" +string(%d) "%s%egetcwd_basic" +===DONE=== diff --git a/ext/standard/tests/dir/getcwd_error.phpt b/ext/standard/tests/dir/getcwd_error.phpt new file mode 100644 index 000000000..09ee25481 --- /dev/null +++ b/ext/standard/tests/dir/getcwd_error.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test getcwd() function : error conditions - Incorrect number of arguments +--FILE-- +<?php +/* Prototype : mixed getcwd(void) + * Description: Gets the current directory + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to getcwd() to test behaviour + */ + +echo "*** Testing getcwd() : error conditions ***\n"; + +// One argument +echo "\n-- Testing getcwd() function with one argument --\n"; +$extra_arg = 10; +var_dump( getcwd($extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing getcwd() : error conditions *** + +-- Testing getcwd() function with one argument -- + +Warning: Wrong parameter count for getcwd() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_basic.phpt b/ext/standard/tests/dir/opendir_basic.phpt new file mode 100644 index 000000000..17ada17ea --- /dev/null +++ b/ext/standard/tests/dir/opendir_basic.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test opendir() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of opendir() with absolute and relative paths as $path argument + */ + +echo "*** Testing opendir() : basic functionality ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "level_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "level_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create temporary directories - will remove in CLEAN section +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- Testing opendir() with absolute path: --\n"; +var_dump($dh1 = opendir($level_one_dir_path)); + + +echo "\n-- Testing opendir() with relative paths: --\n"; +var_dump(chdir($level_one_dir_path)); +var_dump($dh2 = opendir($level_two_dir_name)); + +echo "\n-- Close directory handles: --\n"; +closedir($dh1); +var_dump($dh1); +closedir($dh2); +var_dump($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/level_one/level_two"); +rmdir("$file_path/level_one"); +?> +--EXPECTF-- +*** Testing opendir() : basic functionality *** + +-- Testing opendir() with absolute path: -- +resource(%d) of type (stream) + +-- Testing opendir() with relative paths: -- +bool(true) +resource(%d) of type (stream) + +-- Close directory handles: -- +resource(%d) of type (Unknown) +resource(%d) of type (Unknown) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_error1.phpt b/ext/standard/tests/dir/opendir_error1.phpt new file mode 100644 index 000000000..92b8eee1b --- /dev/null +++ b/ext/standard/tests/dir/opendir_error1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test opendir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to opendir() to test behaviour + */ + +echo "*** Testing opendir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing opendir() function with Zero arguments --\n"; +var_dump( opendir() ); + +//Test opendir with one more than the expected number of arguments +echo "\n-- Testing opendir() function with more than expected no. of arguments --\n"; +$path = dirname(__FILE__) . "/opendir_error"; +mkdir($path); +$context = stream_context_create(); + +$extra_arg = 10; +var_dump( opendir($path, $context, $extra_arg) ); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/opendir_error"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : error conditions *** + +-- Testing opendir() function with Zero arguments -- + +Warning: opendir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing opendir() function with more than expected no. of arguments -- + +Warning: opendir() expects at most 2 parameters, 3 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_error2.phpt b/ext/standard/tests/dir/opendir_error2.phpt new file mode 100644 index 000000000..0762be2ad --- /dev/null +++ b/ext/standard/tests/dir/opendir_error2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test opendir() function : error conditions - Non-existent directory +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass a non-existent directory as $path argument to opendir() to test behaviour + */ + +echo "*** Testing opendir() : error conditions ***\n"; + +echo "\n-- Pass a non-existent absolute path: --\n"; +$path = dirname(__FILE__) . "/idonotexist"; +var_dump(opendir($path)); + +echo "\n-- Pass a non-existent relative path: --\n"; +chdir(dirname(__FILE__)); +var_dump(opendir('idonotexist')); +?> +===DONE=== +--EXPECTF-- +*** Testing opendir() : error conditions *** + +-- Pass a non-existent absolute path: -- + +Warning: opendir(%s/idonotexist): failed to open dir: %s in %s on line %d +bool(false) + +-- Pass a non-existent relative path: -- + +Warning: opendir(idonotexist): failed to open dir: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation1.phpt b/ext/standard/tests/dir/opendir_variation1.phpt new file mode 100644 index 000000000..dc10356f5 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test opendir() function : usage variations - different data types as $path arg +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $path argument to opendir() to test behaviour + * Where possible, an existing directory has been entered as a string value + */ + +echo "*** Testing opendir() : usage variations ***\n"; + +// create directory to be passed as string value where possible +$path = dirname(__FILE__) . "/opendir_variation1"; +mkdir($path); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA { + + var $path; + function __construct($path) { + $this->path = $path; + } + public function __toString() { + return $this->path; + } +} + +// heredoc string +$heredoc = <<<EOT +$path +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $path argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "$path", + 'string', + $heredoc, + + // object data +/*22*/ new classA($path), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of opendir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( $dh = opendir($input) ); + if ($dh) { + closedir($dh); + } + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/opendir_variation1"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Iteration 1 -- + +Warning: opendir(0): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: opendir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: opendir(12345): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: opendir(-2345): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: opendir(10.5): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: opendir(-10.5): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: opendir(123456789000): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: opendir(1.23456789E-9): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: opendir(0.5): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- + +Warning: opendir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- + +Warning: opendir(1): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- + +Warning: opendir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 19 -- +resource(%d) of type (stream) + +-- Iteration 20 -- + +Warning: opendir(string): failed to open dir: %s in %s on line %d +bool(false) + +-- Iteration 21 -- +resource(%d) of type (stream) + +-- Iteration 22 -- +resource(%d) of type (stream) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- +bool(false) + +-- Iteration 25 -- + +Warning: opendir() expects parameter 1 to be string, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation2.phpt b/ext/standard/tests/dir/opendir_variation2.phpt new file mode 100644 index 000000000..4236bec84 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation2.phpt @@ -0,0 +1,239 @@ +--TEST-- +Test opendir() function : usage variations - different data types as $context arg +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $context argument to opendir() to test behaviour + */ + +echo "*** Testing opendir() : usage variation ***\n"; + + +// Initialise function arguments not being substituted (if any) +// create temporary directory for test, removed in CLEAN section +$path = dirname(__FILE__) . "/opendir_variation2"; +mkdir($path); + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() + { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $context argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of opendir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump($dh = opendir($path, $input) );# + if ($dh) { + closedir($dh); + } + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/opendir_variation2"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Iteration 1 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: opendir() expects parameter 2 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: opendir() expects parameter 2 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: opendir() expects parameter 2 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: opendir() expects parameter 2 to be resource, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: opendir() expects parameter 2 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: opendir() expects parameter 2 to be resource, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: opendir() expects parameter 2 to be resource, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: opendir(): supplied resource is not a valid Stream-Context resource in %s on line %d +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation3.phpt b/ext/standard/tests/dir/opendir_variation3.phpt new file mode 100644 index 000000000..3de0dd370 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation3.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test opendir() function : usage variations - open a directory twice +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Call opendir() twice with the same directory as $path argument + */ + +echo "*** Testing opendir() : usage variation ***\n"; + +$path = dirname(__FILE__) . "/opendir_variation3"; +mkdir($path); + +echo "\n-- Open directory first time: --\n"; +var_dump($dh1 = opendir($path)); + +echo "\n-- Open directory second time: --\n"; +var_dump($dh2 = opendir($path)); + +if ($dh1 !== $dh2) { + echo "\nNew resource created\n"; +} else { + echo "\nNo new resource created\n"; +} + +closedir($dh1); +closedir($dh2); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/opendir_variation3"; +rmdir($path); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- Open directory first time: -- +resource(%d) of type (stream) + +-- Open directory second time: -- +resource(%d) of type (stream) + +New resource created +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation4.phpt b/ext/standard/tests/dir/opendir_variation4.phpt new file mode 100644 index 000000000..b20641740 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation4.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test opendir() function : usage variations - different relative paths +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Test opendir() with different relative paths as $path argument + */ + +echo "*** Testing opendir() : usage variation ***\n"; + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_name = "level_one"; +$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; + +$level_two_dir_name = "level_two"; +$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; + +// create directories +mkdir($level_one_dir_path); +mkdir($level_two_dir_path); + +echo "\n-- \$path = './level_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump($dh = opendir("./$level_one_dir_name")); +clean_dh($dh); + +echo "\n-- \$path = 'level_one/level_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name")); +clean_dh($dh); + +echo "\n-- \$path = '..': --\n"; +var_dump($dh = opendir('..')); +clean_dh($dh); + +echo "\n-- \$path = 'level_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir('.')); +clean_dh($dh); + +echo "\n-- \$path = '../': --\n"; +var_dump($dh = opendir('../')); +clean_dh($dh); + +echo "\n-- \$path = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir('./')); +clean_dh($dh); + +echo "\n-- \$path = '../../'level_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump($dh = opendir("../../$level_one_dir_name")); +clean_dh($dh); + +/* + * function to remove directory handle before re-using variable name in test + * and to ensure directory is not in use at CLEAN section so can me removed + */ +function clean_dh($dh){ + if (is_resource($dh)) { + closedir($dh); + } + unset($dh); +} +?> +===DONE=== +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +rmdir("$file_path/level_one/level_two"); +rmdir("$file_path/level_one"); +?> +--EXPECTF-- +*** Testing opendir() : usage variation *** + +-- $path = './level_one': -- +bool(true) +resource(%d) of type (stream) + +-- $path = 'level_one/level_two': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '..': -- +resource(%d) of type (stream) + +-- $path = 'level_two', '.': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../': -- +resource(%d) of type (stream) + +-- $path = './': -- +bool(true) +resource(%d) of type (stream) + +-- $path = '../../'level_one': -- +bool(true) +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation5.phpt b/ext/standard/tests/dir/opendir_variation5.phpt new file mode 100644 index 000000000..f9bb38c68 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation5.phpt @@ -0,0 +1,103 @@ +--TEST-- +Test opendir() function : usage variations - directories with restricted permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/dir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * remove the execute permission from the parent dir and test opendir() on child dir + * 1) remove write & execute permission from the 1st parent and test opendir() + * 2) remove execute permission from 2nd parent and test opendir() + */ + +echo "*** Testing opendir() : usage variations ***\n"; + +/* create the temporary directory : + * opendir_variation5 ( parent ) + * |-> sub_dir ( sub parent ) + * |-> child_dir ( child dir) + */ + +$parent_dir_path = dirname(__FILE__) . "/opendir_variation5"; +mkdir($parent_dir_path); +chmod($parent_dir_path, 0777); + +// create sub_dir +$sub_dir_path = $parent_dir_path . "/sub_dir"; +mkdir($sub_dir_path); +chmod($sub_dir_path, 0777); + +//create sub_sub_dir +$child_dir_path = $sub_dir_path."/child_dir"; +mkdir($child_dir_path); + +// remove the write and execute permisson from sub parent +chmod($sub_dir_path, 0444); + +echo "\n-- After restricting 1st level parent directory --\n"; +$dir_handle1 = opendir($child_dir_path); +var_dump( $dir_handle1 ); + +// remove the execute permisson from parent dir, allowing all permission for sub dir +chmod($sub_dir_path, 0777); // all permisson to sub dir +chmod($parent_dir_path, 0666); // restricting parent directory + +echo "\n-- After restricting parent directory --\n"; +$dir_handle2 = opendir($child_dir_path); // try to open, expected failure +var_dump( $dir_handle2 ); // dump it + +if (is_resource($dir_handle1)) { + closedir($dir_handle1); +} +if (is_resource($dir_handle2)) { + closedir($dir_handle2); +} +?> +===DONE=== +--CLEAN-- +<?php +$parent_dir_path = dirname(__FILE__) . "/opendir_variation5"; +$sub_dir_path = $parent_dir_path."/sub_dir"; +$child_dir_path = $sub_dir_path."/child_dir"; + +// changing permissions for each temporary directory to delete them +chmod($parent_dir_path, 0777); +chmod($sub_dir_path, 0777); +chmod($child_dir_path, 0777); + +rmdir($child_dir_path); +rmdir($sub_dir_path); +rmdir($parent_dir_path); +?> + +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- After restricting 1st level parent directory -- + +Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d +bool(false) + +-- After restricting parent directory -- + +Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation6.phpt b/ext/standard/tests/dir/opendir_variation6.phpt new file mode 100644 index 000000000..01e8225d5 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation6.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test opendir() function : usage variations - Different wildcards +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass paths containing wildcards to test if opendir() recognises them + */ + +echo "*** Testing opendir() : usage variations ***\n"; +// create the temporary directories +$file_path = dirname(__FILE__); +$dir_path = $file_path . "/opendir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +mkdir($dir_path); +mkdir($sub_dir_path); + +// with different wildcard characters + +echo "\n-- Wildcard = '*' --\n"; +var_dump( opendir($file_path . "/opendir_var*") ); +var_dump( opendir($file_path . "/*") ); + +echo "\n-- Wildcard = '?' --\n"; +var_dump( opendir($dir_path . "/sub_dir?") ); +var_dump( opendir($dir_path . "/sub?dir1") ); + +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/opendir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +rmdir($sub_dir_path); +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Wildcard = '*' -- + +Warning: opendir(%s/opendir_var*): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(%s/*): failed to open dir: %s in %s on line %d +bool(false) + +-- Wildcard = '?' -- + +Warning: opendir(%s/opendir_variation6/sub_dir?): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(%s/opendir_variation6/sub?dir1): failed to open dir: %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/opendir_variation7.phpt b/ext/standard/tests/dir/opendir_variation7.phpt new file mode 100644 index 000000000..2ad41b1d3 --- /dev/null +++ b/ext/standard/tests/dir/opendir_variation7.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test opendir() function : usage variations - different directory permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__) . "/opendir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* Prototype : mixed opendir(string $path[, resource $context]) + * Description: Open a directory and return a dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open a directory using opendir() with different directory permissions + */ + +echo "*** Testing opendir() : usage variations ***\n"; + +// create the temporary directory +$file_path = dirname(__FILE__); +$dir_path = $file_path . "/opendir_variation7"; +mkdir($dir_path); + +/* different values for directory permissions */ +$permission_values = array( +/*1*/ 0477, // owner has read only, other and group has rwx + 0677, // owner has rw only, other and group has rwx + +/*3*/ 0444, // all have read only + 0666, // all have rw only + +/*5*/ 0400, // owner has read only, group and others have no permission + 0600, // owner has rw only, group and others have no permission + +/*7*/ 0470, // owner has read only, group has rwx & others have no permission + 0407, // owner has read only, other has rwx & group has no permission + +/*9*/ 0670, // owner has rw only, group has rwx & others have no permission +/*10*/ 0607 // owner has rw only, group has no permission and others have rwx +); + +// Open directory with different permission values, read and close, expected: none of them to succeed. + +$iterator = 1; +foreach ($permission_values as $perm) { + + echo "\n-- Iteration $iterator --\n"; + // try to remove the dir if exists & create + if (is_dir($dir_path)){ + chmod ($dir_path, 0777); // change dir permission to allow all operation + rmdir ($dir_path); + } + mkdir($dir_path); + + // change the dir permisson to test dir on it + var_dump( chmod($dir_path, $perm) ); + + var_dump($dh = opendir($dir_path)); + + if (is_resource($dh)) { + closedir($dh); + } + $iterator++; +} +?> +===DONE=== +--CLEAN-- +<?php +// deleting temporary directory +$dir_path = dirname(__FILE__) . "/opendir_variation7"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing opendir() : usage variations *** + +-- Iteration 1 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 2 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 3 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 4 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 5 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 6 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 7 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 8 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 9 -- +bool(true) +resource(%d) of type (stream) + +-- Iteration 10 -- +bool(true) +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/dir/readdir_basic.phpt b/ext/standard/tests/dir/readdir_basic.phpt new file mode 100644 index 000000000..572a9a079 --- /dev/null +++ b/ext/standard/tests/dir/readdir_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test readdir() function : basic functionality +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.C + */ + +/* + * Test basic functionality of readdir() + */ + +echo "*** Testing readdir() : basic functionality ***\n"; + +// include the file.inc for Function: function create_files() +chdir(dirname(__FILE__)); +include(dirname(__FILE__)."/../file/file.inc"); + +$path = dirname(__FILE__) . '/readdir_basic'; +mkdir($path); +create_files($path, 3); + +echo "\n-- Call readdir() with \$path argument --\n"; +var_dump($dh = opendir($path)); +$a = array(); +while( FALSE !== ($file = readdir($dh)) ) { + $a[] = $file; +} +sort($a); +foreach($a as $file) { + var_dump($file); +} + +echo "\n-- Call readdir() without \$path argument --\n"; +var_dump($dh = opendir($path)); +$a = array(); +while( FALSE !== ( $file = readdir() ) ) { + $a[] = $file; +} +sort($a); +foreach($a as $file) { + var_dump($file); +} + +delete_files($path, 3); +closedir($dh); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . '/readdir_basic'; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : basic functionality *** + +-- Call readdir() with $path argument -- +resource(%d) of type (stream) +string(1) "." +string(2) ".." +string(9) "file1.tmp" +string(9) "file2.tmp" +string(9) "file3.tmp" + +-- Call readdir() without $path argument -- +resource(%d) of type (stream) +string(1) "." +string(2) ".." +string(9) "file1.tmp" +string(9) "file2.tmp" +string(9) "file3.tmp" +===DONE=== diff --git a/ext/standard/tests/dir/readdir_error.phpt b/ext/standard/tests/dir/readdir_error.phpt new file mode 100644 index 000000000..4b4011a13 --- /dev/null +++ b/ext/standard/tests/dir/readdir_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test readdir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to readdir() to test behaviour + */ + +echo "*** Testing readdir() : error conditions ***\n"; + + +//Test readdir with one more than the expected number of arguments +echo "\n-- Testing readdir() function with more than expected no. of arguments --\n"; + +$path = dirname(__FILE__) . "/readdir_error"; +mkdir($path); +$dir_handle = opendir($path); +$extra_arg = 10; + +var_dump( readdir($dir_handle, $extra_arg) ); + +// close the handle so can remove dir in CLEAN section +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . "/readdir_error"; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : error conditions *** + +-- Testing readdir() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for readdir() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation1.phpt b/ext/standard/tests/dir/readdir_variation1.phpt new file mode 100644 index 000000000..b9cd85b28 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation1.phpt @@ -0,0 +1,210 @@ +--TEST-- +Test readdir() function : usage variations - different data types as $dir_handle arg +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $dir_handle argument to readdir() to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $dir_handle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of readdir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( readdir($input) ); + $iterator++; +}; +?> +===DONE=== +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Iteration 1 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: readdir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation2.phpt b/ext/standard/tests/dir/readdir_variation2.phpt new file mode 100644 index 000000000..6809ac2f2 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation2.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test readdir() function : usage variations - empty directories +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass readdir() a directory handle pointing to an empty directory to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +$path = dirname(__FILE__) . '/readdir_variation2'; +mkdir($path); +$dir_handle = opendir($path); + +echo "\n-- Pass an empty directory to readdir() --\n"; +while(FALSE !== ($file = readdir($dir_handle))){ + var_dump($file); +} + +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$path = dirname(__FILE__) . '/readdir_variation2'; +rmdir($path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Pass an empty directory to readdir() -- +string(1) "." +string(2) ".." +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation3.phpt b/ext/standard/tests/dir/readdir_variation3.phpt new file mode 100644 index 000000000..a598462e3 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation3.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test readdir() function : usage variations - sub-directories +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory handle pointing to a directory that has a sub-directory + * to test behaviour of readdir() + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// include the file.inc for Function: function create_files() +chdir(dirname(__FILE__)); +include(dirname(__FILE__)."/../file/file.inc"); + +$path_top = dirname(__FILE__) . '/readdir_variation3'; +$path_sub = $path_top . '/sub_folder'; +mkdir($path_top); +mkdir($path_sub); + +create_files($path_top, 2); +create_files($path_sub, 2); + +$dir_handle = opendir($path_top); +$contents = array(); +while(FALSE !== ($file = readdir($dir_handle))) { + // different OS order files differently so will + // store file names into an array so can use sorted in expected output + $contents[] = $file; +} + +// more important to check that all contents are present than order they are returned in +sort($contents); +var_dump($contents); + +delete_files($path_top, 2); +delete_files($path_sub, 2); + +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$path_top = dirname(__FILE__) . '/readdir_variation3'; +$path_sub = $path_top . '/sub_folder'; +rmdir($path_sub); +rmdir($path_top); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" + [3]=> + string(9) "file2.tmp" + [4]=> + string(10) "sub_folder" +} +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation4.phpt b/ext/standard/tests/dir/readdir_variation4.phpt new file mode 100644 index 000000000..770cdf6b0 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation4.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test readdir() function : usage variations - different file names +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory handle pointing to a directory that contains + * files with different file names to test how readdir() reads them + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . "/readdir_variation4/"; +mkdir($dir_path); + +// heredoc string +$heredoc = <<<EOT +hd_file +EOT; + +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // empty data +/*10*/ "", + array(), + + // string data +/*12*/ "double_file", + 'single_file', + $heredoc, +); + +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + $handle = "fp{$iterator}"; + var_dump( $$handle = fopen($dir_path . $input . '.tmp', 'w') ); + var_dump( fwrite($$handle, $key)); + fclose($$handle); + $iterator++; +}; + +echo "\n-- Call to readdir() --\n"; +$dir_handle = opendir($dir_path); +$contents = array(); +while(FALSE !== ($file = readdir($dir_handle))){ + + // different OS order files differently so will + // store file names into an array so can use sorted in expected output + $contents[] = $file; + + // remove files while going through directory + @unlink($dir_path . $file); +} + +// more important to check that all contents are present than order they are returned in +sort($contents); +var_dump($contents); + +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/readdir_variation4/"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Iteration 1 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 2 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 3 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 4 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 5 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 6 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 7 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 8 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 9 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 10 -- +resource(%d) of type (stream) +int(1) + +-- Iteration 11 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 12 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 13 -- +resource(%d) of type (stream) +int(2) + +-- Iteration 14 -- +resource(%d) of type (stream) +int(2) + +-- Call to readdir() -- +array(16) { + [0]=> + string(9) "-10.5.tmp" + [1]=> + string(9) "-2345.tmp" + [2]=> + string(1) "." + [3]=> + string(2) ".." + [4]=> + string(4) ".tmp" + [5]=> + string(7) "0.5.tmp" + [6]=> + string(5) "0.tmp" + [7]=> + string(17) "1.23456789E-9.tmp" + [8]=> + string(5) "1.tmp" + [9]=> + string(8) "10.5.tmp" + [10]=> + string(9) "12345.tmp" + [11]=> + string(16) "123456789000.tmp" + [12]=> + string(9) "Array.tmp" + [13]=> + string(15) "double_file.tmp" + [14]=> + string(11) "hd_file.tmp" + [15]=> + string(15) "single_file.tmp" +} +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation5.phpt b/ext/standard/tests/dir/readdir_variation5.phpt new file mode 100644 index 000000000..8c12f13df --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation5.phpt @@ -0,0 +1,144 @@ +--TEST-- +Test readdir() function : usage variations - different permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/readdir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open a directory with different premissions then try to read it + * to test behaviour of readdir() + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// create the temporary directory +$dir_path = dirname(__FILE__) . "/readdir_variation5"; +mkdir($dir_path); + +/* different values for directory permissions */ +$permission_values = array( +/*1*/ 0477, // owner has read only, other and group has rwx + 0677, // owner has rw only, other and group has rwx + +/*3*/ 0444, // all have read only + 0666, // all have rw only + +/*5*/ 0400, // owner has read only, group and others have no permission + 0600, // owner has rw only, group and others have no permission + +/*7*/ 0470, // owner has read only, group has rwx & others have no permission + 0407, // owner has read only, other has rwx & group has no permission + +/*9*/ 0670, // owner has rw only, group has rwx & others have no permission +/*10*/ 0607 // owner has rw only, group has no permission and others have rwx +); + +// Open directory with different permission values, read and close, expected: none of them to succeed. +$iterator = 1; +foreach($permission_values as $perm) { + echo "\n-- Iteration $iterator --\n"; + + if (is_dir($dir_path)) { + chmod ($dir_path, 0777); // change dir permission to allow all operation + rmdir ($dir_path); + } + mkdir($dir_path); + + // change the dir permisson to test dir on it + var_dump( chmod($dir_path, $perm) ); + var_dump($dh = opendir($dir_path)); + + echo "-- Calling readdir() --\n"; + var_dump(readdir($dh)); + + closedir($dh); + $iterator++; +} +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/readdir_variation5"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Iteration 1 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 2 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 3 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 4 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 5 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 6 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 7 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 8 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 9 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" + +-- Iteration 10 -- +bool(true) +resource(%d) of type (stream) +-- Calling readdir() -- +string(%d) "%s" +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation6.phpt b/ext/standard/tests/dir/readdir_variation6.phpt new file mode 100644 index 000000000..eec673e73 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation6.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test readdir() function : usage variations - operate on previously opened directory +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open two directory handles on the same directory and pass both + * to readdir() to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// include the file.inc for Function: function create_files() +include( dirname(__FILE__)."/../file/file.inc"); + +// create the temporary directory +$dir_path = dirname(__FILE__) . "/readdir_variation6"; +mkdir($dir_path); + +// create files within the temporary directory +create_files($dir_path, 3, "alphanumeric", 0755, 1, "w", "readdir_variation6"); + +// open the directory +$dir_handle1 = opendir($dir_path); + +// open the same directory again without closing it +opendir($dir_path); + +echo "\n-- Reading Directory Contents with Previous Handle --\n"; +$a = array(); +while (FALSE !== ($file = readdir($dir_handle1))) { + $a[] = $file; +} +sort($a); +foreach ($a as $file) { + var_dump($file); +} + +echo "\n-- Reading Directory Contents with Current Handle (no arguments supplied) --\n"; +$a = array(); +while (FALSE !== ($file = readdir())) { + $a[] = $file; +} +sort($a); +foreach ($a as $file) { + var_dump($file); +} + +// delete temporary files +delete_files($dir_path, 3, "readdir_variation6"); +closedir($dir_handle1); +closedir(); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/readdir_variation6"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing readdir() : usage variations *** + +-- Reading Directory Contents with Previous Handle -- +string(1) "." +string(2) ".." +string(23) "readdir_variation61.tmp" +string(23) "readdir_variation62.tmp" +string(23) "readdir_variation63.tmp" + +-- Reading Directory Contents with Current Handle (no arguments supplied) -- +string(1) "." +string(2) ".." +string(23) "readdir_variation61.tmp" +string(23) "readdir_variation62.tmp" +string(23) "readdir_variation63.tmp" +===DONE=== diff --git a/ext/standard/tests/dir/readdir_variation7.phpt b/ext/standard/tests/dir/readdir_variation7.phpt new file mode 100644 index 000000000..86bd43061 --- /dev/null +++ b/ext/standard/tests/dir/readdir_variation7.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test readdir() function : usage variations - use file pointers +--FILE-- +<?php +/* Prototype : string readdir([resource $dir_handle]) + * Description: Read directory entry from dir_handle + * Source code: ext/standard/dir.c + */ + +/* + * Open a file pointer using fopen and pass to readdir() to test behaviour + */ + +echo "*** Testing readdir() : usage variations ***\n"; + +// get a resource variable +var_dump($fp = fopen(__FILE__, "r")); +var_dump( readdir($fp) ); + +// get file length over 256 characters +<<<EOT +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +123456789012345678901234567890 +EOT; +?> +===DONE=== +--EXPECTF-- +*** Testing readdir() : usage variations *** +resource(%d) of type (stream) + +Warning: readdir(): %d is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_basic.phpt b/ext/standard/tests/dir/rewinddir_basic.phpt new file mode 100644 index 000000000..e9c027818 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_basic.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test rewinddir() function : basic functionality +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Test basic functionality of rewinddir() + */ + +echo "*** Testing rewinddir() : basic functionality ***\n"; + +// include file.inc for create_files function +include(dirname(__FILE__) . "/../file/file.inc"); + +$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1"; +$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2"; +mkdir($dir_path1); +mkdir($dir_path2); + +@create_files($dir_path1, 1); +@create_files($dir_path2, 1, 'numeric', 0755, 1, 'w', 'file', 2); +var_dump($dh1 = opendir($dir_path1)); +var_dump($dh2 = opendir($dir_path2)); + +$data = array(); +echo "\n-- Read and rewind first directory (argument supplied) --\n"; +while(FALSE !== $file1 = readdir($dh1)) { + $data[] = $file1; +} +sort($data); +var_dump($data); + +var_dump(rewinddir($dh1)); +var_dump(readdir($dh1)); + +$data = array(); +echo "\n-- Read and rewind second directory (no argument supplied) --\n"; +while(FALSE !== $file2 = readdir()) { + $data[] = $file2; +} +sort($data); +var_dump($data); + +var_dump(rewinddir()); +var_dump(readdir()); + +closedir($dh1); +closedir($dh2); + +delete_files($dir_path1, 1); +delete_files($dir_path2, 1, 'file', 2); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1"; +$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2"; +rmdir($dir_path1); +rmdir($dir_path2); +?> +--EXPECTF-- +*** Testing rewinddir() : basic functionality *** +resource(%d) of type (stream) +resource(%d) of type (stream) + +-- Read and rewind first directory (argument supplied) -- +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" +} +NULL +string(1) "." + +-- Read and rewind second directory (no argument supplied) -- +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file2.tmp" +} +NULL +string(1) "." +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_error.phpt b/ext/standard/tests/dir/rewinddir_error.phpt new file mode 100644 index 000000000..d66b24b93 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test rewinddir() function : error conditions - incorrect number of args +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Pass incorrect number of arguments to rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : error conditions ***\n"; + + +//Test rewinddir with one more than the expected number of arguments +echo "\n-- Testing rewinddir() function with more than expected no. of arguments --\n"; + +$dir_path = dirname(__FILE__) . "/rewinddir_error"; +mkdir($dir_path); +$dir_handle = opendir($dir_path); +$extra_arg = 10; + +var_dump( rewinddir($dir_handle, $extra_arg) ); +closedir($dir_handle); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/rewinddir_error"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing rewinddir() : error conditions *** + +-- Testing rewinddir() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for rewinddir() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation1.phpt b/ext/standard/tests/dir/rewinddir_variation1.phpt new file mode 100644 index 000000000..e1fa002c1 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_variation1.phpt @@ -0,0 +1,211 @@ +--TEST-- +Test rewinddir() function : usage variations - different data types as $dir_handle arg +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Pass different data types as $dir_handle argument to rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $dir_handle argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of rewinddir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( rewinddir($input) ); + $iterator++; +}; +?> +===DONE=== +--EXPECTF-- +*** Testing rewinddir() : usage variations *** + +-- Iteration 1 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation2.phpt b/ext/standard/tests/dir/rewinddir_variation2.phpt new file mode 100644 index 000000000..37ff324ee --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_variation2.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test rewinddir() function : usage variations - operate on a closed directory +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Open and close a directory handle then call rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . '/rewinddir_variation2'; +mkdir($dir_path); + +echo "\n-- Create the directory handle, read and close the directory --\n"; +var_dump($dir_handle = opendir($dir_path)); +var_dump(readdir($dir_handle)); +closedir($dir_handle); + +echo "\n-- Call to rewinddir() --\n"; +var_dump(rewinddir($dir_handle)); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . '/rewinddir_variation2'; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing rewinddir() : usage variations *** + +-- Create the directory handle, read and close the directory -- +resource(%d) of type (stream) +string(1) "." + +-- Call to rewinddir() -- + +Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/rewinddir_variation3.phpt b/ext/standard/tests/dir/rewinddir_variation3.phpt new file mode 100644 index 000000000..2a2af89e6 --- /dev/null +++ b/ext/standard/tests/dir/rewinddir_variation3.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test rewinddir() function : usage variations - file pointers +--FILE-- +<?php +/* Prototype : void rewinddir([resource $dir_handle]) + * Description: Rewind dir_handle back to the start + * Source code: ext/standard/dir.c + * Alias to functions: rewind + */ + +/* + * Pass a file pointer to rewinddir() to test behaviour + */ + +echo "*** Testing rewinddir() : usage variations ***\n"; + +echo "\n-- Open a file using fopen --\n"; +var_dump($fp = fopen(__FILE__, 'r')); + +$result1 = fread($fp, 5); +var_dump(rewinddir($fp)); +$result2 = fread($fp, 5); + +echo "\n-- Check if rewinddir() has repositioned the file pointer --\n"; +if ($result1 === $result2) { + echo "rewinddir() works on file pointers\n"; +} else { + echo "rewinddir() does not work on file pointers\n"; +} +?> +===DONE=== +--EXPECTF-- +*** Testing rewinddir() : usage variations *** + +-- Open a file using fopen -- +resource(%d) of type (stream) + +Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d +bool(false) + +-- Check if rewinddir() has repositioned the file pointer -- +rewinddir() does not work on file pointers +===DONE=== diff --git a/ext/standard/tests/dir/scandir_basic.phpt b/ext/standard/tests/dir/scandir_basic.phpt new file mode 100644 index 000000000..25700a7a4 --- /dev/null +++ b/ext/standard/tests/dir/scandir_basic.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test scandir() function : basic functionality +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Test basic functionality of scandir() + */ + +echo "*** Testing scandir() : basic functionality ***\n"; + +// include file.inc for create_files function +include (dirname(__FILE__) . '/../file/file.inc'); + +// set up directory +$directory = dirname(__FILE__) . '/scandir_basic'; +mkdir($directory); +create_files($directory, 3); + +echo "\n-- scandir() with mandatory arguments --\n"; +var_dump(scandir($directory)); + +echo "\n-- scandir() with all arguments --\n"; +$sorting_order = 1; +$context = stream_context_create(); +var_dump(scandir($directory, $sorting_order, $context)); + +delete_files($directory, 3); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . '/scandir_basic'; +rmdir($directory); +?> +--EXPECTF-- +*** Testing scandir() : basic functionality *** + +-- scandir() with mandatory arguments -- +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" + [3]=> + string(9) "file2.tmp" + [4]=> + string(9) "file3.tmp" +} + +-- scandir() with all arguments -- +array(5) { + [0]=> + string(9) "file3.tmp" + [1]=> + string(9) "file2.tmp" + [2]=> + string(9) "file1.tmp" + [3]=> + string(2) ".." + [4]=> + string(1) "." +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_error1.phpt b/ext/standard/tests/dir/scandir_error1.phpt new file mode 100644 index 000000000..7fbffba0c --- /dev/null +++ b/ext/standard/tests/dir/scandir_error1.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test scandir() function : error conditions - Incorrect number of args +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass incorrect number of arguments to scandir() to test behaviour + */ + +echo "*** Testing scandir() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing scandir() function with Zero arguments --\n"; +var_dump( scandir() ); + +//Test scandir with one more than the expected number of arguments +echo "\n-- Testing scandir() function with more than expected no. of arguments --\n"; +$dir = dirname(__FILE__) . '/scandir_error'; +mkdir($dir); +$sorting_order = 10; +$context = stream_context_create(); +$extra_arg = 10; +var_dump( scandir($dir, $sorting_order, $context, $extra_arg) ); +?> +===DONE=== +--CLEAN-- +<?php +$directory = dirname(__FILE__) . '/scandir_error'; +rmdir($directory); +?> +--EXPECTF-- +*** Testing scandir() : error conditions *** + +-- Testing scandir() function with Zero arguments -- + +Warning: scandir() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing scandir() function with more than expected no. of arguments -- + +Warning: scandir() expects at most 3 parameters, 4 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/scandir_error2.phpt b/ext/standard/tests/dir/scandir_error2.phpt new file mode 100644 index 000000000..1e99a578a --- /dev/null +++ b/ext/standard/tests/dir/scandir_error2.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test scandir() function : error conditions - Non-existent directory +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory that does not exist to scandir() to test error messages + */ + +echo "*** Testing scandir() : error conditions ***\n"; + +$directory = dirname(__FILE__) . '/idonotexist'; + +echo "\n-- Pass scandir() an absolute path that does not exist --\n"; +var_dump(scandir($directory)); + +echo "\n-- Pass scandir() a relative path that does not exist --\n"; +var_dump(scandir('/idonotexist')); +?> +===DONE=== +--EXPECTF-- +*** Testing scandir() : error conditions *** + +-- Pass scandir() an absolute path that does not exist -- + +Warning: scandir(%s/idonotexist): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Pass scandir() a relative path that does not exist -- + +Warning: scandir(/idonotexist): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation1.phpt b/ext/standard/tests/dir/scandir_variation1.phpt new file mode 100644 index 000000000..84b3565f7 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation1.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test scandir() function : usage variations - different data types as $dir arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $dir argument to test behaviour of scandir() + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $dir argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of scandir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( scandir($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- + +Warning: scandir(0): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: scandir(1): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: scandir(12345): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: scandir(-2345): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: scandir(10.5): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: scandir(-10.5): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: scandir(123456789000): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: scandir(1.23456789E-9): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: scandir(0.5): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: scandir(1): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: scandir(1): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: scandir() expects parameter 1 to be string, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: scandir(string): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: scandir(string): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: scandir(hello world): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: scandir(Class A object): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: scandir(): Directory name cannot be empty in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: scandir() expects parameter 1 to be string, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation2.phpt b/ext/standard/tests/dir/scandir_variation2.phpt new file mode 100644 index 000000000..e6033f256 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation2.phpt @@ -0,0 +1,283 @@ +--TEST-- +Test scandir() function : usage variations - diff data types as $sorting_order arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $sorting_order argument to test how scandir() behaves + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$dir = dirname(__FILE__) . '/scandir_variation2'; +mkdir($dir); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $sorting_order argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of scandir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( scandir($dir, $input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/scandir_variation2'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 2 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 3 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 4 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 6 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 8 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 9 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 10 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 11 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 12 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 13 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 14 -- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "." +} + +-- Iteration 15 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 16 -- + +Warning: scandir() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: scandir() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: scandir() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: scandir() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: scandir() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: scandir() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: scandir() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 23 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 24 -- +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 25 -- + +Warning: scandir() expects parameter 2 to be long, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation3.phpt b/ext/standard/tests/dir/scandir_variation3.phpt new file mode 100644 index 000000000..8e23faf2d --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation3.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test scandir() function : usage variations - diff data types as $context arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different data types as $context argument to test how scandir() behaves + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$dir = dirname(__FILE__) . '/scandir_variation3'; +mkdir($dir); +$sorting_order = 0; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $context argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of scandir() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( scandir($dir, $sorting_order, $input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/scandir_variation3'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: scandir() expects parameter 3 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: scandir() expects parameter 3 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: scandir() expects parameter 3 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: scandir() expects parameter 3 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: scandir() expects parameter 3 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: scandir() expects parameter 3 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: scandir() expects parameter 3 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: scandir() expects parameter 3 to be resource, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: scandir() expects parameter 3 to be resource, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: scandir() expects parameter 3 to be resource, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: scandir() expects parameter 3 to be resource, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: scandir(): supplied resource is not a valid Stream-Context resource in %s on line %d +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation4.phpt b/ext/standard/tests/dir/scandir_variation4.phpt new file mode 100644 index 000000000..f756cf1ee --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation4.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test scandir() function : usage variations - different relative paths +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Test scandir() with relative paths as $dir argument + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// include for create_files/delete_files functions +include (dirname(__FILE__) . '/../file/file.inc'); + +$base_dir_path = dirname(__FILE__); + +$level_one_dir_path = "$base_dir_path/level_one"; +$level_two_dir_path = "$level_one_dir_path/level_two"; + +// create directories and files +mkdir($level_one_dir_path); +create_files($level_one_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_one', 1); +mkdir($level_two_dir_path); +create_files($level_two_dir_path, 2, 'numeric', 0755, 1, 'w', 'level_two', 1); + +echo "\n-- \$path = './level_one': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(scandir('./level_one')); + +echo "\n-- \$path = 'level_one/level_two': --\n"; +var_dump(chdir($base_dir_path)); +var_dump(scandir('level_one/level_two')); + +echo "\n-- \$path = '..': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('..')); + +echo "\n-- \$path = 'level_two', '.': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('.')); + +echo "\n-- \$path = '../': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('../')); + +echo "\n-- \$path = './': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('./')); + +echo "\n-- \$path = '../../'level_one': --\n"; +var_dump(chdir($level_two_dir_path)); +var_dump(scandir('../../level_one')); + +@delete_files($level_one_dir_path, 2, 'level_one'); +@delete_files($level_two_dir_path, 2, 'level_two'); +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__); +rmdir("$dir_path/level_one/level_two"); +rmdir("$dir_path/level_one"); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- $path = './level_one': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_one1.tmp" + [3]=> + string(14) "level_one2.tmp" + [4]=> + string(9) "level_two" +} + +-- $path = 'level_one/level_two': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_two1.tmp" + [3]=> + string(14) "level_two2.tmp" +} + +-- $path = '..': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_one1.tmp" + [3]=> + string(14) "level_one2.tmp" + [4]=> + string(9) "level_two" +} + +-- $path = 'level_two', '.': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_two1.tmp" + [3]=> + string(14) "level_two2.tmp" +} + +-- $path = '../': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_one1.tmp" + [3]=> + string(14) "level_one2.tmp" + [4]=> + string(9) "level_two" +} + +-- $path = './': -- +bool(true) +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_two1.tmp" + [3]=> + string(14) "level_two2.tmp" +} + +-- $path = '../../'level_one': -- +bool(true) +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(14) "level_one1.tmp" + [3]=> + string(14) "level_one2.tmp" + [4]=> + string(9) "level_two" +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation5.phpt b/ext/standard/tests/dir/scandir_variation5.phpt new file mode 100644 index 000000000..d6d3c79e4 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation5.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test scandir() function : usage variations - different directory permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__)."/dir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * remove the execute permission from the parent dir and test scandir() on child dir + * 1. remove write & execute permission from the 1st parent and test scandir() + * 2. remove execute permission from 2nd parent and test scandir() + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +/* + * create the temporary directory : + * scandir_variation5 ( parent ) + * |-> sub_dir ( sub parent ) + * |-> child_dir ( child dir) + */ + +$parent_dir_path = dirname(__FILE__) . "/scandir_variation5"; +mkdir($parent_dir_path); +chmod($parent_dir_path, 0777); + +// create sub_dir +$sub_dir_path = $parent_dir_path . "/sub_dir"; +mkdir($sub_dir_path); +chmod($sub_dir_path, 0777); + +//create sub_sub_dir +$child_dir_path = $sub_dir_path."/child_dir"; +mkdir($child_dir_path); + +// remove the write and execute permisson from sub parent +chmod($sub_dir_path, 0444); + +echo "\n-- After restricting 1st level parent directory --\n"; +var_dump(scandir($child_dir_path)); + +// remove the execute permisson from parent dir, allowing all permission for sub dir +chmod($sub_dir_path, 0777); // all permisson to sub dir +chmod($parent_dir_path, 0666); // restricting parent directory + +echo "\n-- After restricting parent directory --\n"; +var_dump(scandir($child_dir_path)); +?> +===DONE=== +--CLEAN-- +<?php +$parent_dir_path = dirname(__FILE__) . "/scandir_variation5"; +$sub_dir_path = $parent_dir_path."/sub_dir"; +$child_dir_path = $sub_dir_path."/child_dir"; + +// changing permissions for each temporary directory to delete them +chmod($parent_dir_path, 0777); +chmod($sub_dir_path, 0777); +chmod($child_dir_path, 0777); + +rmdir($child_dir_path); +rmdir($sub_dir_path); +rmdir($parent_dir_path); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- After restricting 1st level parent directory -- + +Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- After restricting parent directory -- + +Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation6.phpt b/ext/standard/tests/dir/scandir_variation6.phpt new file mode 100644 index 000000000..5cb595fe7 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation6.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test scandir() function : usage variations - Wildcards in directory path +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory path using wildcards as $dir argument to test how scandir() behaves + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// create the temporary directories +$file_path = dirname(__FILE__); +$dir_path = $file_path . "/scandir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +mkdir($dir_path); +mkdir($sub_dir_path); + +// with different wildcard characters + +echo "\n-- Wildcard = '*' --\n"; +var_dump( scandir($file_path . "/scandir_var*") ); +var_dump( scandir($file_path . "/*") ); + +echo "\n-- Wildcard = '?' --\n"; +var_dump( scandir($dir_path . "/sub_dir?") ); +var_dump( scandir($dir_path . "/sub?dir1") ); + +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/scandir_variation6"; +$sub_dir_path = $dir_path . "/sub_dir1"; + +rmdir($sub_dir_path); +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Wildcard = '*' -- + +Warning: scandir(%s/scandir_var*): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +Warning: scandir(%s/*): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +-- Wildcard = '?' -- + +Warning: scandir(%s/scandir_variation6/sub_dir?): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) + +Warning: scandir(%s/scandir_variation6/sub?dir1): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno %d): %s in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation7.phpt b/ext/standard/tests/dir/scandir_variation7.phpt new file mode 100644 index 000000000..c7f77651d --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation7.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test scandir() function : usage variations - different directory permissions +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows'); +} +// Skip if being run by root (files are always readable, writeable and executable) +$filename = dirname(__FILE__) . "/dir_root_check.tmp"; +$fp = fopen($filename, 'w'); +fclose($fp); +if(fileowner($filename) == 0) { + unlink ($filename); + die('skip...cannot be run as root\n'); +} +unlink($filename); +?> +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Create directories with different permissions to test whether scandir() can access them + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// create the temporary directory +$dir_path = dirname(__FILE__) . "/scandir_variation7"; +mkdir($dir_path); + +// different values for directory permissions +$permission_values = array( +/*1*/ 0477, // owner has read only, other and group has rwx + 0677, // owner has rw only, other and group has rwx + +/*3*/ 0444, // all have read only + 0666, // all have rw only + +/*5*/ 0400, // owner has read only, group and others have no permission + 0600, // owner has rw only, group and others have no permission + +/*7*/ 0470, // owner has read only, group has rwx & others have no permission + 0407, // owner has read only, other has rwx & group has no permission + +/*9*/ 0670, // owner has rw only, group has rwx & others have no permission +/*10*/ 0607 // owner has rw only, group has no permission and others have rwx +); + +$iterator = 1; +foreach ($permission_values as $perm) { + echo "\n-- Iteration $iterator --\n"; + + // Remove the directory if already exists + if (is_dir($dir_path)){ + chmod ($dir_path, 0777); // change dir permission to allow all operation + rmdir ($dir_path); + } + mkdir($dir_path); + + // change the dir permisson to test dir on it + var_dump( chmod($dir_path, $perm) ); + + var_dump(scandir($dir_path)); + $iterator++; +} +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/scandir_variation7"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 2 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 3 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 4 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 5 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 6 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 7 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 8 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 9 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} + +-- Iteration 10 -- +bool(true) +array(2) { + [0]=> + string(1) "." + [1]=> + string(2) ".." +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation8.phpt b/ext/standard/tests/dir/scandir_variation8.phpt new file mode 100644 index 000000000..36ae88c8f --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation8.phpt @@ -0,0 +1,154 @@ +--TEST-- +Test scandir() function : usage variations - different file names +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass a directory containing files with different types of names to test how scandir() + * reads them + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +$dir_path = dirname(__FILE__) . "/scandir_variation8/"; +mkdir($dir_path); + +// heredoc string +$heredoc = <<<EOT +hd_file +EOT; + +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // empty data +/*10*/ "", + array(), + + // string data +/*12*/ "double_file", + 'single_file', + $heredoc, +); + +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + $handle = "fp{$iterator}"; + var_dump( $$handle = fopen($dir_path . $input . '.tmp', 'w') ); + fclose($$handle); + $iterator++; +}; + +echo "\n-- Call to scandir() --\n"; +var_dump($content = scandir($dir_path)); + +// remove all files in directory so can remove directory in CLEAN section +foreach ($content as $file_name) { + // suppress errors as won't be able to remove "." and ".." entries + @unlink($dir_path . $file_name); +} +?> +===DONE=== +--CLEAN-- +<?php +$dir_path = dirname(__FILE__) . "/scandir_variation8"; +rmdir($dir_path); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** + +-- Iteration 1 -- +resource(%d) of type (stream) + +-- Iteration 2 -- +resource(%d) of type (stream) + +-- Iteration 3 -- +resource(%d) of type (stream) + +-- Iteration 4 -- +resource(%d) of type (stream) + +-- Iteration 5 -- +resource(%d) of type (stream) + +-- Iteration 6 -- +resource(%d) of type (stream) + +-- Iteration 7 -- +resource(%d) of type (stream) + +-- Iteration 8 -- +resource(%d) of type (stream) + +-- Iteration 9 -- +resource(%d) of type (stream) + +-- Iteration 10 -- +resource(%d) of type (stream) + +-- Iteration 11 -- +resource(%d) of type (stream) + +-- Iteration 12 -- +resource(%d) of type (stream) + +-- Iteration 13 -- +resource(%d) of type (stream) + +-- Iteration 14 -- +resource(%d) of type (stream) + +-- Call to scandir() -- +array(16) { + [0]=> + string(9) "-10.5.tmp" + [1]=> + string(9) "-2345.tmp" + [2]=> + string(1) "." + [3]=> + string(2) ".." + [4]=> + string(4) ".tmp" + [5]=> + string(7) "0.5.tmp" + [6]=> + string(5) "0.tmp" + [7]=> + string(17) "1.23456789E-9.tmp" + [8]=> + string(5) "1.tmp" + [9]=> + string(8) "10.5.tmp" + [10]=> + string(9) "12345.tmp" + [11]=> + string(16) "123456789000.tmp" + [12]=> + string(9) "Array.tmp" + [13]=> + string(15) "double_file.tmp" + [14]=> + string(11) "hd_file.tmp" + [15]=> + string(15) "single_file.tmp" +} +===DONE=== diff --git a/ext/standard/tests/dir/scandir_variation9.phpt b/ext/standard/tests/dir/scandir_variation9.phpt new file mode 100644 index 000000000..2b1904c98 --- /dev/null +++ b/ext/standard/tests/dir/scandir_variation9.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test scandir() function : usage variations - different ints as $sorting_order arg +--FILE-- +<?php +/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) + * Description: List files & directories inside the specified path + * Source code: ext/standard/dir.c + */ + +/* + * Pass different integers as $sorting_order argument to test how scandir() + * re-orders the array + */ + +echo "*** Testing scandir() : usage variations ***\n"; + +// include for create_files/delete_files functions +include(dirname(__FILE__) . '/../file/file.inc'); + +// create directory and files +$dir = dirname(__FILE__) . '/scandir_variation9'; +mkdir($dir); +@create_files($dir, 2); + +// different ints to pass as $sorting_order argument +$ints = array (PHP_INT_MAX, -PHP_INT_MAX, 0); + +foreach($ints as $sorting_order) { + var_dump( scandir($dir, $sorting_order) ); +} + +delete_files($dir, 2); +?> +===DONE=== +--CLEAN-- +<?php +$dir = dirname(__FILE__) . '/scandir_variation9'; +rmdir($dir); +?> +--EXPECTF-- +*** Testing scandir() : usage variations *** +array(4) { + [0]=> + string(9) "file2.tmp" + [1]=> + string(9) "file1.tmp" + [2]=> + string(2) ".." + [3]=> + string(1) "." +} +array(4) { + [0]=> + string(9) "file2.tmp" + [1]=> + string(9) "file1.tmp" + [2]=> + string(2) ".." + [3]=> + string(1) "." +} +array(4) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" + [3]=> + string(9) "file2.tmp" +} +===DONE=== diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt index b60b865e7..f5036daa8 100644 --- a/ext/standard/tests/file/bug22414.phpt +++ b/ext/standard/tests/file/bug22414.phpt @@ -8,20 +8,21 @@ output_handler= $php = getenv('TEST_PHP_EXECUTABLE'); $tmpfile = tempnam('/tmp', 'phpt'); + $args = ' -n -dsafe_mode=off '; /* Regular Data Test */ - passthru($php . ' -n -r " echo \"HELLO\"; "'); + passthru($php . $args . ' -r " echo \"HELLO\"; "'); echo "\n"; /* Binary Data Test */ if (substr(PHP_OS, 0, 3) != 'WIN') { - $cmd = $php . ' -n -r \"readfile(@getenv(\'TEST_PHP_EXECUTABLE\')); \"'; - $cmd = $php . ' -n -r \' passthru("'.$cmd.'"); \' > '.$tmpfile ; + $cmd = $php . $args . ' -r \"readfile(@getenv(\'TEST_PHP_EXECUTABLE\')); \"'; + $cmd = $php . $args . ' -r \' passthru("'.$cmd.'"); \' > '.$tmpfile ; } else { - $cmd = $php . ' -n -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"'; - $cmd = $php . ' -n -r " passthru(\''.$cmd.'\');" > '.$tmpfile ; + $cmd = $php . $args . ' -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"'; + $cmd = $php . $args . ' -r " passthru(\''.$cmd.'\');" > '.$tmpfile ; } exec($cmd); diff --git a/ext/standard/tests/file/bug41655_2.phpt b/ext/standard/tests/file/bug41655_2.phpt index 23086661f..d406f1ba0 100644 --- a/ext/standard/tests/file/bug41655_2.phpt +++ b/ext/standard/tests/file/bug41655_2.phpt @@ -5,13 +5,11 @@ open_basedir=/ --FILE-- <?php $dir = dirname(__FILE__); - $a=glob($dir . "/bug41655*.*"); + $a=glob($dir . "/test.*"); print_r($a); ?> --EXPECTF-- Array ( - [0] => %sbug41655_1.phpt - [1] => %sbug41655_2.php - [2] => %sbug41655_2.phpt + [0] => %stest.csv ) diff --git a/ext/standard/tests/file/bug43216.phpt b/ext/standard/tests/file/bug43216.phpt new file mode 100755 index 000000000..b7e42534c --- /dev/null +++ b/ext/standard/tests/file/bug43216.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43216 (stream_is_local() returns false on file://) +--FILE-- +<?php +var_dump(stream_is_local("file://")); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/file/bug43248.phpt b/ext/standard/tests/file/bug43248.phpt new file mode 100755 index 000000000..a20e0e06c --- /dev/null +++ b/ext/standard/tests/file/bug43248.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43248 backward compatibility break in realpath() +--FILE-- +<?php +echo realpath(dirname(__FILE__) . '/../file/'); +?> +--EXPECTF-- +%sfile diff --git a/ext/standard/tests/file/bug43522.phpt b/ext/standard/tests/file/bug43522.phpt new file mode 100644 index 000000000..10e44fc35 --- /dev/null +++ b/ext/standard/tests/file/bug43522.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #43522 (stream_get_line() eats additional characters) +--FILE-- +<?php // 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ + +$fp = fopen(__FILE__, 'r'); // Open self + +DoTest($fp, 'ZZZ'); // test multi-char delimiter +DoTest($fp, "Z"); // test single-char delimiter + +function DoTest($fp, $delim) { + echo "Delimiter: " . $delim . "\n"; + rewind($fp); + echo "\t" . stream_get_line($fp, 10, $delim) . "\n"; + echo "\t" . stream_get_line($fp, 10, $delim) . "\n"; +} + +?> +--EXPECT-- +Delimiter: ZZZ + <?php // 1 + 234567890A +Delimiter: Z + <?php // 1 + 234567890A diff --git a/ext/standard/tests/file/fgetc_basic.phpt b/ext/standard/tests/file/fgetc_basic.phpt index d82110f78..7851e432f 100644 --- a/ext/standard/tests/file/fgetc_basic.phpt +++ b/ext/standard/tests/file/fgetc_basic.phpt @@ -69,475 +69,475 @@ echo "Done\n"; string(1) "2" int(1) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(8) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using rb mode -- string(1) "2" int(1) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(9) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using rt mode -- string(1) "2" int(1) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(10) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "2" int(1) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(11) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "2" int(1) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(12) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 1 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "2" int(1) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(2) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(3) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(4) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(5) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) string(1) "2" int(6) bool(false) -resource(13) of type (stream) +resource(%d) of type (stream) --- Outerloop iteration 2 --- -- Innerloop iteration 1 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r mode -- string(1) "t" int(1) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(16) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using rb mode -- string(1) "t" int(1) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(17) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using rt mode -- string(1) "t" int(1) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(18) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "t" int(1) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(19) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "t" int(1) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(20) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 2 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "t" int(1) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "e" int(2) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "x" int(3) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "t" int(4) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) string(1) "t" int(6) bool(false) -resource(21) of type (stream) +resource(%d) of type (stream) --- Outerloop iteration 3 --- -- Innerloop iteration 1 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r mode -- string(1) "l" int(1) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(24) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 2 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using rb mode -- string(1) "l" int(1) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(25) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 3 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using rt mode -- string(1) "l" int(1) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(26) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 4 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+ mode -- string(1) "l" int(1) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(27) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 5 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+b mode -- string(1) "l" int(1) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(28) of type (stream) +resource(%d) of type (stream) -- Innerloop iteration 6 of Outerloop Iteration 3 -- -- Testing fgetc() : file opened using r+t mode -- string(1) "l" int(1) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "i" int(2) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "n" int(3) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "e" int(4) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) " " int(5) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) string(1) "l" int(6) bool(false) -resource(29) of type (stream) +resource(%d) of type (stream) Done
\ No newline at end of file diff --git a/ext/standard/tests/file/fgetc_variation2.phpt b/ext/standard/tests/file/fgetc_variation2.phpt index d733c2909..e7f22b304 100644 --- a/ext/standard/tests/file/fgetc_variation2.phpt +++ b/ext/standard/tests/file/fgetc_variation2.phpt @@ -41,20 +41,7 @@ echo "Done"; *** Testing fgetc() : usage variations *** -- Testing fgetc() with closed handle -- -Warning: fgetc(): 6 is not a valid stream resource in %s on line %d -bool(false) --- Testing fgetc() with unset handle -- - -Notice: Undefined variable: file_handle in %s on line %d - -Warning: fgetc(): supplied argument is not a valid stream resource in %s on line %d -bool(false) -Done ---UEXPECTF-- -*** Testing fgetc() : usage variations *** --- Testing fgetc() with closed handle -- - -Warning: fgetc(): 6 is not a valid stream resource in %s on line %d +Warning: fgetc(): %d is not a valid stream resource in %s on line %d bool(false) -- Testing fgetc() with unset handle -- diff --git a/ext/standard/tests/file/fopen_variation1.phpt b/ext/standard/tests/file/fopen_variation1.phpt new file mode 100644 index 000000000..53f635b6e --- /dev/null +++ b/ext/standard/tests/file/fopen_variation1.phpt @@ -0,0 +1,14 @@ +--TEST-- +fopen() with relative path on a file in the script directory +--FILE-- +<?php + +$file = basename(__FILE__); + +$fd = fopen($file, "r", true); +var_dump($fd); +fclose($fd); + +?> +--EXPECTF-- +resource(%d) of type (stream) diff --git a/ext/standard/tests/file/fread_socket_variation1.phpt b/ext/standard/tests/file/fread_socket_variation1.phpt new file mode 100644 index 000000000..bd3d23ac5 --- /dev/null +++ b/ext/standard/tests/file/fread_socket_variation1.phpt @@ -0,0 +1,16 @@ +--TEST-- +Testing fread() on a TCP server socket +--FILE-- +<?php + +$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337'); + +socket_set_timeout($tcp_socket, 1); + +var_dump(fread($tcp_socket, 1)); + +fclose($tcp_socket); + +?> +--EXPECT-- +string(0) "" diff --git a/ext/standard/tests/file/fseek_dir_basic.phpt b/ext/standard/tests/file/fseek_dir_basic.phpt new file mode 100644 index 000000000..c6d0816e9 --- /dev/null +++ b/ext/standard/tests/file/fseek_dir_basic.phpt @@ -0,0 +1,96 @@ +--TEST-- +Testing fseek() on a directory stream +--FILE-- +<?php + +// include the file.inc for Function: function create_files() +require(dirname(__FILE__) . '/file.inc'); + +$path = dirname(__FILE__) . '/fseek_dir_basic'; +mkdir($path); +create_files($path, 3); + +echo "call readdir():\n"; +var_dump($dh = opendir($path)); +$files = array(); +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); +$files = array(); + +echo "\ncall fseek() on directory resource:\n"; +var_dump(fseek($dh, 20)); + +echo "call readdir():\n"; +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); +$files = array(); + +echo "\ncall fseek() with different arguments on directory resource:\n"; +var_dump(fseek($dh, 20, SEEK_END)); + +echo "call readdir():\n"; +while( FALSE !== ($files[] = readdir($dh)) ) {} +sort($files); +var_dump($files); + +delete_files($path, 3); +closedir($dh); +var_dump(rmdir($path)); + +?> +--EXPECTF-- +call readdir(): +resource(12) of type (stream) +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} + +call fseek() on directory resource: +int(0) +call readdir(): +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} + +call fseek() with different arguments on directory resource: +int(0) +call readdir(): +array(6) { + [0]=> + bool(false) + [1]=> + string(1) "." + [2]=> + string(2) ".." + [3]=> + string(9) "file1.tmp" + [4]=> + string(9) "file2.tmp" + [5]=> + string(9) "file3.tmp" +} +bool(true) diff --git a/ext/standard/tests/file/glob_variation2.phpt b/ext/standard/tests/file/glob_variation2.phpt new file mode 100644 index 000000000..f95fd17e7 --- /dev/null +++ b/ext/standard/tests/file/glob_variation2.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test glob() function with relative path +--FILE-- +<?php +/* Prototype: array glob ( string $pattern [, int $flags] ); + Description: Find pathnames matching a pattern +*/ + +$file_path = dirname(__FILE__); + +// temp dirname used here +$dir_name = 'glob_test'; + +// create temp directory +mkdir("$file_path/$dir_name"); + +// create temp file +$fp = fopen("$file_path/$dir_name/file.text", "w"); +fclose($fp); + +echo "Testing glob() with relative paths:\n"; + +chdir("$file_path/$dir_name"); +var_dump( glob("./*") ); +var_dump( glob("../$dir_name/*")); + +chdir("$file_path"); +var_dump( glob("$dir_name/*")); +var_dump( glob("$dir_name")); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink("$file_path/glob_test/file.text"); +rmdir("$file_path/glob_test/"); +?> +--EXPECT-- +Testing glob() with relative paths: +array(1) { + [0]=> + string(11) "./file.text" +} +array(1) { + [0]=> + string(22) "../glob_test/file.text" +} +array(1) { + [0]=> + string(19) "glob_test/file.text" +} +array(1) { + [0]=> + string(9) "glob_test" +} +Done diff --git a/ext/standard/tests/file/is_dir_variation2.phpt b/ext/standard/tests/file/is_dir_variation2.phpt index df2464d3c..70fe94e44 100644 --- a/ext/standard/tests/file/is_dir_variation2.phpt +++ b/ext/standard/tests/file/is_dir_variation2.phpt @@ -70,7 +70,7 @@ bool(true) -- With symlink -- bool(true) -- With hardlink -- -Warning: link(): Operation not permitted in %s on line %d +Warning: link(): %s in %s on line %d bool(false) *** Testing is_dir() with file and links to a file *** diff --git a/ext/standard/tests/file/open_basedir.inc b/ext/standard/tests/file/open_basedir.inc new file mode 100644 index 000000000..7fd0afc8b --- /dev/null +++ b/ext/standard/tests/file/open_basedir.inc @@ -0,0 +1,133 @@ +<?php + +// This file contains helper functions for testing open_basedir configuration +// Care must be taken with where the directories are created because different +// SAPIs set the working directory differently. So simply creating a directory +// relative to the current working directory like this: mkdir("blah") might +// actually create it in several different places depending on the SAPI..! +// +// Note also depending on the version of php being tested, so the open_basedir +// configuration may or may not be changeable from a script (PHP_INI_SYSTEM). +// +// For this reason we set the open_basedir to . (current directory) and then +// move around to various directories for testing using chdir(). This is NOT +// recommended for production use as . bypasses all semblence of security..! +// +// Although safe mode has been removed in php 6.0, open_basedir is still valid. +// See http://www.php.net/features.safe-mode for more information + +function recursive_delete_directory($directory) { + + // Remove any trailing slash first + if (substr($directory, -1) == '/') { + $directory = substr($directory, 0, -1); + } + + // Make sure the directory is valid + if (is_dir($directory) == FALSE) { + return FALSE; + } + + // Check we can access the directory + if (is_readable($directory) == FALSE) { + return FALSE; + } + + $handle = opendir($directory); + + // Scan through the directory contents + while (FALSE !== ($item = readdir($handle))) { + if ($item != '.') { + if ($item != '..') { + $path = ($directory.'/'.$item); + if (is_dir($path) == TRUE) { + recursive_delete_directory($path); + } else { + @chmod($path, 0777); + unlink($path); + } + } + } + } + + closedir($handle); + @chmod($directory, 0777); + rmdir($directory); + + return TRUE; +} + +function create_directories() { + delete_directories(); + $directory = dirname(__FILE__); + + var_dump(mkdir($directory."/test")); + var_dump(mkdir($directory."/test/ok")); + var_dump(mkdir($directory."/test/bad")); + file_put_contents($directory."/test/ok/ok.txt", "Hello World!"); + file_put_contents($directory."/test/bad/bad.txt", "Hello World!"); +} + +function delete_directories() { + $directory = (dirname(__FILE__)."/test"); + recursive_delete_directory($directory); +} + +function test_open_basedir_error($function) { + var_dump($function("../bad")); + var_dump($function("../bad/bad.txt")); + var_dump($function("..")); + var_dump($function("../")); + var_dump($function("/")); + var_dump($function("../bad/.")); + $directory = dirname(__FILE__); + var_dump($function($directory."/test/bad/bad.txt")); + var_dump($function($directory."/test/bad/../bad/bad.txt")); +} + +function test_open_basedir_before($function, $change = TRUE) { + echo "*** Testing open_basedir configuration [$function] ***\n"; + $directory = dirname(__FILE__); + var_dump(chdir($directory)); + create_directories(); + + // Optionally change directory + if ($change == TRUE) { + var_dump(chdir($directory."/test/ok")); + } +} + +// Delete directories using a --CLEAN-- section! +function test_open_basedir_after($function) { + echo "*** Finished testing open_basedir configuration [$function] ***\n"; +} + +// This is used by functions that return an array on success +function test_open_basedir_array($function) { + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump(is_array($function("./../."))); + var_dump(is_array($function("../ok"))); + var_dump(is_array($function("ok.txt"))); + var_dump(is_array($function("../ok/ok.txt"))); + $directory = dirname(__FILE__); + var_dump(is_array($function($directory."/test/ok/ok.txt"))); + var_dump(is_array($function($directory."/test/ok/../ok/ok.txt"))); + test_open_basedir_after($function); +} + +function test_open_basedir($function) { + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump($function("./../.")); + var_dump($function("../ok")); + var_dump($function("ok.txt")); + var_dump($function("../ok/ok.txt")); + $directory = dirname(__FILE__); + var_dump($function($directory."/test/ok/ok.txt")); + var_dump($function($directory."/test/ok/../ok/ok.txt")); + test_open_basedir_after($function); +} + +?> + diff --git a/ext/standard/tests/file/open_basedir_chdir.phpt b/ext/standard/tests/file/open_basedir_chdir.phpt new file mode 100644 index 000000000..32ed4eb1e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_chdir.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("chdir"); +$directory = dirname(__FILE__); + +var_dump(chdir("../bad")); +var_dump(chdir("..")); +var_dump(chdir("../")); +var_dump(chdir("/")); +var_dump(chdir("../bad/.")); +var_dump(chdir("./../.")); + +test_open_basedir_after("chdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [chdir] *** + diff --git a/ext/standard/tests/file/open_basedir_chmod.phpt b/ext/standard/tests/file/open_basedir_chmod.phpt new file mode 100644 index 000000000..02fdce5a1 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_chmod.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("chmod"); +$directory = dirname(__FILE__); + +var_dump(chmod("../bad", 0600)); +var_dump(chmod("../bad/bad.txt", 0600)); +var_dump(chmod("..", 0600)); +var_dump(chmod("../", 0600)); +var_dump(chmod("/", 0600)); +var_dump(chmod("../bad/.", 0600)); +var_dump(chmod("../bad/./bad.txt", 0600)); +var_dump(chmod("./../.", 0600)); + +var_dump(chmod($directory."/test/ok/ok.txt", 0600)); +var_dump(chmod("./ok.txt", 0600)); +var_dump(chmod("ok.txt", 0600)); +var_dump(chmod("../ok/ok.txt", 0600)); +var_dump(chmod("../ok/./ok.txt", 0600)); +chmod($directory."/test/ok/ok.txt", 0777); + +test_open_basedir_after("chmod"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chmod] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chmod(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [chmod] *** + diff --git a/ext/standard/tests/file/open_basedir_copy.phpt b/ext/standard/tests/file/open_basedir_copy.phpt new file mode 100644 index 000000000..8f0f7a91f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_copy.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); +$directory = dirname(__FILE__); + +var_dump(copy("ok.txt", "../bad")); +var_dump(copy("ok.txt", "../bad/bad.txt")); +var_dump(copy("ok.txt", "..")); +var_dump(copy("ok.txt", "../")); +var_dump(copy("ok.txt", "/")); +var_dump(copy("ok.txt", "../bad/.")); +var_dump(copy("ok.txt", "../bad/./bad.txt")); +var_dump(copy("ok.txt", "./../.")); + +var_dump(copy("ok.txt", "copy.txt")); +var_dump(unlink("copy.txt")); +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(./../.): failed to open stream: Operation not permitted in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/ext/standard/tests/file/open_basedir_copy_variation1.phpt b/ext/standard/tests/file/open_basedir_copy_variation1.phpt new file mode 100644 index 000000000..de532e12c --- /dev/null +++ b/ext/standard/tests/file/open_basedir_copy_variation1.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); +$directory = dirname(__FILE__); + +var_dump(copy("../bad/bad.txt", "copy.txt")); +var_dump(unlink("copy.txt")); + +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(copy.txt): No such file or directory in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/ext/standard/tests/file/open_basedir_disk_free_space.phpt b/ext/standard/tests/file/open_basedir_disk_free_space.phpt new file mode 100644 index 000000000..e3e36e670 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_disk_free_space.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; + +test_open_basedir_before("disk_free_space"); +test_open_basedir_error("disk_free_space"); +$directory = dirname(__FILE__); +var_dump(disk_free_space($directory."/test/ok")); +test_open_basedir_after("disk_free_space"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [disk_free_space] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +float(%s) +*** Finished testing open_basedir configuration [disk_free_space] *** diff --git a/ext/standard/tests/file/open_basedir_file.phpt b/ext/standard/tests/file/open_basedir_file.phpt new file mode 100644 index 000000000..fbc841e3f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$directory = dirname(__FILE__); +test_open_basedir_before("file"); +test_open_basedir_error("file"); + +var_dump(file("ok.txt")); +var_dump(file("../ok/ok.txt")); +var_dump(file($directory."/test/ok/ok.txt")); +var_dump(file($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +*** Finished testing open_basedir configuration [file] *** + diff --git a/ext/standard/tests/file/open_basedir_file_exists.phpt b/ext/standard/tests/file/open_basedir_file_exists.phpt new file mode 100644 index 000000000..c249fc116 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_exists.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("file_exists"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_exists] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [file_exists] *** + diff --git a/ext/standard/tests/file/open_basedir_file_get_contents.phpt b/ext/standard/tests/file/open_basedir_file_get_contents.phpt new file mode 100644 index 000000000..637c499ea --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_get_contents.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$directory = dirname(__FILE__); +test_open_basedir_before("file_get_contents"); +test_open_basedir_error("file_get_contents"); + +var_dump(file_get_contents("ok.txt")); +var_dump(file_get_contents("../ok/ok.txt")); +var_dump(file_get_contents($directory."/test/ok/ok.txt")); +var_dump(file_get_contents($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file_get_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_get_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +*** Finished testing open_basedir configuration [file_get_contents] *** diff --git a/ext/standard/tests/file/open_basedir_file_put_contents.phpt b/ext/standard/tests/file/open_basedir_file_put_contents.phpt new file mode 100644 index 000000000..d4bd417b5 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_file_put_contents.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("file_put_contents"); +$directory = dirname(__FILE__); + +var_dump(file_put_contents("../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents(".././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("../bad/../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("./.././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents($directory."/test/bad/bad.txt", "Hello World!")); + +test_open_basedir_after("file_put_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_put_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(.././bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(./.././bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents%s/test/bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [file_put_contents] *** + diff --git a/ext/standard/tests/file/open_basedir_fileatime.phpt b/ext/standard/tests/file/open_basedir_fileatime.phpt new file mode 100644 index 000000000..02cc94f83 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileatime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileatime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileatime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileatime] *** + diff --git a/ext/standard/tests/file/open_basedir_filectime.phpt b/ext/standard/tests/file/open_basedir_filectime.phpt new file mode 100644 index 000000000..542c8423e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filectime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filectime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filectime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filectime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filectime] *** + diff --git a/ext/standard/tests/file/open_basedir_filegroup.phpt b/ext/standard/tests/file/open_basedir_filegroup.phpt new file mode 100644 index 000000000..5f6279aa8 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filegroup.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filegroup"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filegroup] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filegroup] *** + diff --git a/ext/standard/tests/file/open_basedir_fileinode.phpt b/ext/standard/tests/file/open_basedir_fileinode.phpt new file mode 100644 index 000000000..070c2c806 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileinode.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileinode"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileinode] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileinode] *** + diff --git a/ext/standard/tests/file/open_basedir_filemtime.phpt b/ext/standard/tests/file/open_basedir_filemtime.phpt new file mode 100644 index 000000000..7213ddb5b --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filemtime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filemtime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filemtime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filemtime] *** + diff --git a/ext/standard/tests/file/open_basedir_fileowner.phpt b/ext/standard/tests/file/open_basedir_fileowner.phpt new file mode 100644 index 000000000..b363b7e0e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileowner.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileowner"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileowner] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileowner] *** + diff --git a/ext/standard/tests/file/open_basedir_fileperms.phpt b/ext/standard/tests/file/open_basedir_fileperms.phpt new file mode 100644 index 000000000..a1e6511b0 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fileperms.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileperms"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileperms] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileperms] *** + diff --git a/ext/standard/tests/file/open_basedir_filesize.phpt b/ext/standard/tests/file/open_basedir_filesize.phpt new file mode 100644 index 000000000..a335dfd17 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filesize.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filesize"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filesize] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filesize(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filesize] *** + diff --git a/ext/standard/tests/file/open_basedir_filetype.phpt b/ext/standard/tests/file/open_basedir_filetype.phpt new file mode 100644 index 000000000..5091db56f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_filetype.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filetype"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filetype] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filetype(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(3) "dir" +string(4) "file" +string(4) "file" +string(4) "file" +string(4) "file" +*** Finished testing open_basedir configuration [filetype] *** + diff --git a/ext/standard/tests/file/open_basedir_fopen.phpt b/ext/standard/tests/file/open_basedir_fopen.phpt new file mode 100644 index 000000000..c6c9a253f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_fopen.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("fopen"); +$directory = dirname(__FILE__); + +var_dump(fopen("../bad", "r")); +var_dump(fopen("../bad/bad.txt", "r")); +var_dump(fopen("..", "r")); +var_dump(fopen("../", "r")); +var_dump(fopen("/", "r")); +var_dump(fopen("../bad/.", "r")); +var_dump(fopen("../bad/./bad.txt", "r")); +var_dump(fopen("./../.", "r")); + +var_dump(fopen($directory."/test/ok/ok.txt", "r")); +var_dump(fopen("./ok.txt", "r")); +var_dump(fopen("ok.txt", "r")); +var_dump(fopen("../ok/ok.txt", "r")); +var_dump(fopen("../ok/./ok.txt", "r")); + +test_open_basedir_after("fopen"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fopen] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fopen(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(/): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line 12 +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(./../.): failed to open stream: Operation not permitted in %s on line %d +bool(false) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +*** Finished testing open_basedir configuration [fopen] *** + diff --git a/ext/standard/tests/file/open_basedir_glob-win32.phpt b/ext/standard/tests/file/open_basedir_glob-win32.phpt new file mode 100644 index 000000000..3fa19afa3 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_glob-win32.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +array(0) { +} +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/ext/standard/tests/file/open_basedir_glob.phpt b/ext/standard/tests/file/open_basedir_glob.phpt new file mode 100644 index 000000000..591cd8f4f --- /dev/null +++ b/ext/standard/tests/file/open_basedir_glob.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/ext/standard/tests/file/open_basedir_is_dir.phpt b/ext/standard/tests/file/open_basedir_is_dir.phpt new file mode 100644 index 000000000..e4ad620d7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_dir.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_dir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_dir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_dir] *** + diff --git a/ext/standard/tests/file/open_basedir_is_executable.phpt b/ext/standard/tests/file/open_basedir_is_executable.phpt new file mode 100644 index 000000000..1bab86055 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_executable.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("is_executable"); +test_open_basedir_error("is_executable"); + +var_dump(is_executable("ok.txt")); +var_dump(is_executable("../ok/ok.txt")); +$directory = dirname(__FILE__); +var_dump(is_executable($directory."/test/ok/ok.txt")); +var_dump(is_executable($directory."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("is_executable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_executable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_executable] *** diff --git a/ext/standard/tests/file/open_basedir_is_file.phpt b/ext/standard/tests/file/open_basedir_is_file.phpt new file mode 100644 index 000000000..51ef0a2d1 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_file.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_file] *** + diff --git a/ext/standard/tests/file/open_basedir_is_link.phpt b/ext/standard/tests/file/open_basedir_is_link.phpt new file mode 100644 index 000000000..5d12148d8 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_link.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_link(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_link] *** + diff --git a/ext/standard/tests/file/open_basedir_is_readable.phpt b/ext/standard/tests/file/open_basedir_is_readable.phpt new file mode 100644 index 000000000..951a19ac7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_readable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_readable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_readable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_readable] *** + diff --git a/ext/standard/tests/file/open_basedir_is_writable.phpt b/ext/standard/tests/file/open_basedir_is_writable.phpt new file mode 100644 index 000000000..25ce1c63a --- /dev/null +++ b/ext/standard/tests/file/open_basedir_is_writable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_writable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_writable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_writable] *** + diff --git a/ext/standard/tests/file/open_basedir_link.phpt b/ext/standard/tests/file/open_basedir_link.phpt new file mode 100644 index 000000000..a54c22f4b --- /dev/null +++ b/ext/standard/tests/file/open_basedir_link.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no links on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("link"); +$directory = dirname(__FILE__); + +$target = ($directory."/test/ok/ok.txt"); +var_dump(link($target, "../bad/link.txt")); +var_dump(link($target, "../link.txt")); +var_dump(link($target, "../bad/./link.txt")); +var_dump(link($target, "./.././link.txt")); + +$link = ($directory."/test/ok/link.txt"); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("../bad", $link)); +var_dump(link("../bad/./bad.txt", $link)); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("./.././bad", $link)); + +$target = ($directory."/test/ok/ok.txt"); + +var_dump(link($target, $link)); +var_dump(unlink($link)); +test_open_basedir_after("link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [link] *** + diff --git a/ext/standard/tests/file/open_basedir_linkinfo.phpt b/ext/standard/tests/file/open_basedir_linkinfo.phpt new file mode 100644 index 000000000..ab12a5149 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_linkinfo.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("linkinfo", FALSE); +$directory = dirname(__FILE__); + +chdir($directory); + +$target = ($directory."/test/bad/bad.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($directory."/test/ok"); + +var_dump(linkinfo("symlink.txt")); +var_dump(linkinfo("../ok/symlink.txt")); +var_dump(linkinfo("../ok/./symlink.txt")); +var_dump(linkinfo("./symlink.txt")); +var_dump(linkinfo($directory."/test/ok/symlink.txt")); + +$target = ($directory."/test/ok/ok.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(linkinfo($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("linkinfo"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [linkinfo] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [linkinfo] *** + diff --git a/ext/standard/tests/file/open_basedir_lstat.phpt b/ext/standard/tests/file/open_basedir_lstat.phpt new file mode 100644 index 000000000..35e5a2201 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_lstat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("lstat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [lstat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: lstat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [lstat] *** + diff --git a/ext/standard/tests/file/open_basedir_mkdir.phpt b/ext/standard/tests/file/open_basedir_mkdir.phpt new file mode 100644 index 000000000..253818ccf --- /dev/null +++ b/ext/standard/tests/file/open_basedir_mkdir.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("mkdir"); +$directory = dirname(__FILE__); + +var_dump(mkdir("../bad/blah")); +var_dump(mkdir("../blah")); +var_dump(mkdir("../bad/./blah")); +var_dump(mkdir("./.././blah")); + +var_dump(mkdir($directory."/test/ok/blah")); +var_dump(rmdir($directory."/test/ok/blah")); +test_open_basedir_after("mkdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [mkdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/./blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(./.././blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [mkdir] *** diff --git a/ext/standard/tests/file/open_basedir_parse_ini_file.phpt b/ext/standard/tests/file/open_basedir_parse_ini_file.phpt new file mode 100644 index 000000000..dadddac98 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_parse_ini_file.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("parse_ini_file"); +$directory = dirname(__FILE__); + +var_dump(parse_ini_file("../bad")); +var_dump(parse_ini_file("../bad/bad.txt")); +var_dump(parse_ini_file("..")); +var_dump(parse_ini_file("../")); +var_dump(parse_ini_file("../bad/.")); +var_dump(parse_ini_file("../bad/./bad.txt")); +var_dump(parse_ini_file("./../.")); + +test_open_basedir_after("parse_ini_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [parse_ini_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(..): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/.): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} + +Warning: parse_ini_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(./../.): failed to open stream: Operation not permitted in %s on line %d +array(0) { +} +*** Finished testing open_basedir configuration [parse_ini_file] *** + diff --git a/ext/standard/tests/file/open_basedir_readlink.phpt b/ext/standard/tests/file/open_basedir_readlink.phpt new file mode 100644 index 000000000..cbba4307e --- /dev/null +++ b/ext/standard/tests/file/open_basedir_readlink.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("readlink", FALSE); +$directory = dirname(__FILE__); + +chdir($directory); + +$target = ($directory."/test/bad/bad.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($directory."/test/ok"); + +var_dump(readlink("symlink.txt")); +var_dump(readlink("../ok/symlink.txt")); +var_dump(readlink("../ok/./symlink.txt")); +var_dump(readlink("./symlink.txt")); +var_dump(readlink($directory."/test/ok/symlink.txt")); + +$target = ($directory."/test/ok/ok.txt"); +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(readlink($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("readlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [readlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: readlink(): open_basedir restriction in effect. File(symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [readlink] *** + diff --git a/ext/standard/tests/file/open_basedir_realpath.phpt b/ext/standard/tests/file/open_basedir_realpath.phpt new file mode 100644 index 000000000..8cae890e9 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_realpath.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip only run on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("realpath"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [realpath] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s\test\ok" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +*** Finished testing open_basedir configuration [realpath] *** + diff --git a/ext/standard/tests/file/open_basedir_rename.phpt b/ext/standard/tests/file/open_basedir_rename.phpt new file mode 100644 index 000000000..428e7a070 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_rename.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("rename"); +$directory = dirname(__FILE__); + +var_dump(rename("../bad/bad.txt", "rename.txt")); +var_dump(rename(".././bad/bad.txt", "rename.txt")); +var_dump(rename("../bad/../bad/bad.txt", "rename.txt")); +var_dump(rename("./.././bad/bad.txt", "rename.txt")); +var_dump(rename($directory."/test/bad/bad.txt", "rename.txt")); + +test_open_basedir_after("rename"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rename] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rename(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rename] *** + diff --git a/ext/standard/tests/file/open_basedir_rmdir.phpt b/ext/standard/tests/file/open_basedir_rmdir.phpt new file mode 100644 index 000000000..b4d61f8b7 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_rmdir.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("rmdir"); +$directory = dirname(__FILE__); + +var_dump(rmdir("../bad")); +var_dump(rmdir(".././bad")); +var_dump(rmdir("../bad/../bad")); +var_dump(rmdir("./.././bad")); +var_dump(rmdir($directory."/test/bad")); + +test_open_basedir_after("rmdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rmdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad/../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(./.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rmdir] *** + diff --git a/ext/standard/tests/file/open_basedir_stat.phpt b/ext/standard/tests/file/open_basedir_stat.phpt new file mode 100644 index 000000000..b80b854d6 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_stat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("stat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [stat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: stat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [stat] *** + diff --git a/ext/standard/tests/file/open_basedir_symlink.phpt b/ext/standard/tests/file/open_basedir_symlink.phpt new file mode 100644 index 000000000..3b3f1d571 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_symlink.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("symlink"); +$directory = dirname(__FILE__); + +$target = ($directory."/test/ok/ok.txt"); +var_dump(symlink($target, "../bad/symlink.txt")); +var_dump(symlink($target, "../symlink.txt")); +var_dump(symlink($target, "../bad/./symlink.txt")); +var_dump(symlink($target, "./.././symlink.txt")); + +$symlink = ($directory."/test/ok/symlink.txt"); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("../bad", $symlink)); +var_dump(symlink("../bad/./bad.txt", $symlink)); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("./.././bad", $symlink)); + +$target = ($directory."/test/ok/ok.txt"); + +var_dump(symlink($target, $symlink)); +var_dump(unlink($symlink)); +test_open_basedir_after("symlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [symlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [symlink] *** + diff --git a/ext/standard/tests/file/open_basedir_tempnam.phpt b/ext/standard/tests/file/open_basedir_tempnam.phpt new file mode 100644 index 000000000..247ac88d5 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_tempnam.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("tempnam"); +$directory = dirname(__FILE__); + +var_dump(tempnam("../bad", "test")); +var_dump(tempnam("..", "test")); +var_dump(tempnam("../", "test")); +var_dump(tempnam("/", "test")); +var_dump(tempnam("../bad/.", "test")); +var_dump(tempnam("./../.", "test")); + +$file = tempnam($directory."/test/ok", "test"); +var_dump($file); +var_dump(unlink($file)); + +test_open_basedir_after("tempnam"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [tempnam] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s" +bool(true) +*** Finished testing open_basedir configuration [tempnam] *** + diff --git a/ext/standard/tests/file/open_basedir_touch.phpt b/ext/standard/tests/file/open_basedir_touch.phpt new file mode 100644 index 000000000..b0a5aee61 --- /dev/null +++ b/ext/standard/tests/file/open_basedir_touch.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("touch"); +$directory = dirname(__FILE__); + +var_dump(touch("../bad")); +var_dump(touch("../bad/bad.txt")); +var_dump(touch("..")); +var_dump(touch("../")); +var_dump(touch("/")); +var_dump(touch("../bad/.")); +var_dump(touch("../bad/./bad.txt")); +var_dump(touch("./../.")); + +var_dump(touch($directory."/test/ok/ok.txt")); +var_dump(touch("./ok.txt")); +var_dump(touch("ok.txt")); +var_dump(touch("../ok/ok.txt")); +var_dump(touch("../ok/./ok.txt")); + +test_open_basedir_after("touch"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [touch] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: touch(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [touch] *** + diff --git a/ext/standard/tests/file/open_basedir_unlink.phpt b/ext/standard/tests/file/open_basedir_unlink.phpt new file mode 100644 index 000000000..75b0f3f4a --- /dev/null +++ b/ext/standard/tests/file/open_basedir_unlink.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("unlink"); +$directory = dirname(__FILE__); + +var_dump(unlink("../bad/bad.txt")); +var_dump(unlink(".././bad/bad.txt")); +var_dump(unlink("../bad/../bad/bad.txt")); +var_dump(unlink("./.././bad/bad.txt")); +var_dump(unlink($directory."/test/bad/bad.txt")); + +test_open_basedir_after("unlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [unlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [unlink] *** + diff --git a/ext/standard/tests/file/parse_ini_file_error.phpt b/ext/standard/tests/file/parse_ini_file_error.phpt new file mode 100644 index 000000000..65a6ac1d8 --- /dev/null +++ b/ext/standard/tests/file/parse_ini_file_error.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test parse_ini_file() function : error conditions +--FILE-- +<?php +/* Prototype : proto array parse_ini_file(string filename [, bool process_sections]) + * Description: Parse configuration file + * Source code: ext/standard/basic_functions.c + * Alias to functions: + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing parse_ini_file() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing parse_ini_file() function with Zero arguments --\n"; +var_dump( parse_ini_file() ); + +//Test parse_ini_file with one more than the expected number of arguments +echo "\n-- Testing parse_ini_file() function with more than expected no. of arguments --\n"; +$filename = 'string_val'; +$process_sections = true; +$extra_arg = 10; +var_dump( parse_ini_file($filename, $process_sections, $extra_arg) ); + +echo "\n-- Testing parse_ini_file() function with a non-existent file --\n"; +$filename = __FILE__ . 'invalidfilename'; +var_dump( parse_ini_file($filename, $process_sections) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_ini_file() : error conditions *** + +-- Testing parse_ini_file() function with Zero arguments -- + +Warning: Wrong parameter count for parse_ini_file() in %s on line %d +NULL + +-- Testing parse_ini_file() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for parse_ini_file() in %s on line %d +NULL + +-- Testing parse_ini_file() function with a non-existent file -- + +Warning: parse_ini_file(%s): failed to open stream: No such file or directory in %s on line %d +array(0) { +} +Done diff --git a/ext/standard/tests/file/realpath_basic2.phpt b/ext/standard/tests/file/realpath_basic2.phpt new file mode 100644 index 000000000..b71feb98b --- /dev/null +++ b/ext/standard/tests/file/realpath_basic2.phpt @@ -0,0 +1,13 @@ +--TEST-- +realpath() with relative directory +--FILE-- +<?php + +var_dump(realpath('.') == getcwd()); +chdir('..'); +var_dump(realpath('.') == getcwd()); + +?> +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/standard/tests/file/realpath_basic3.phpt b/ext/standard/tests/file/realpath_basic3.phpt new file mode 100644 index 000000000..ce9385591 --- /dev/null +++ b/ext/standard/tests/file/realpath_basic3.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test realpath() with relative paths +--FILE-- +<?php +/* Prototype: string realpath ( string $path ); + Description: Returns canonicalized absolute pathname +*/ + +echo "\n*** Testing basic functions of realpath() with files ***\n"; + +/* creating directories and files */ +$file_path = dirname(__FILE__); +mkdir("$file_path/realpath_basic/home/test/", 0777, true); + +$file_handle1 = fopen("$file_path/realpath_basic/home/test/realpath_basic.tmp", "w"); +$file_handle2 = fopen("$file_path/realpath_basic/home/realpath_basic.tmp", "w"); +$file_handle3 = fopen("$file_path/realpath_basic/realpath_basic.tmp", "w"); +fclose($file_handle1); +fclose($file_handle2); +fclose($file_handle3); + +echo "\n*** Testing realpath() on filenames ***\n"; +$filenames = array ( + /* filenames resulting in valid paths */ + "./realpath_basic/home/realpath_basic.tmp", + "./realpath_basic/realpath_basic.tmp", + "./realpath_basic//home/test//../test/./realpath_basic.tmp", + "./realpath_basic/home//../././realpath_basic.tmp", + + /* filenames with invalid path */ + // checking for binary safe + "./realpath_basicx000/home/realpath_basic.tmp", + + ".///realpath_basic/home//..//././test//realpath_basic.tmp", + "./realpath_basic/home/../home/../test/..realpath_basic.tmp" +); + +chdir("$file_path/.."); +chdir($file_path); + +$counter = 1; +/* loop through $files to read the filepath of $file in the above array */ +foreach($filenames as $file) { + echo "\n-- Iteration $counter --\n"; + var_dump( realpath($file) ); + $counter++; +} + +echo "Done\n"; +?> +--CLEAN-- +<?php +$name_prefix = dirname(__FILE__)."/realpath_basic"; +unlink("$name_prefix/home/test/realpath_basic.tmp"); +unlink("$name_prefix/home/realpath_basic.tmp"); +unlink("$name_prefix/realpath_basic.tmp"); +rmdir("$name_prefix/home/test/"); +rmdir("$name_prefix/home/"); +rmdir("$name_prefix/"); +?> +--EXPECTF-- +*** Testing basic functions of realpath() with files *** + +*** Testing realpath() on filenames *** + +-- Iteration 1 -- +string(%d) "%srealpath_basic%shome%srealpath_basic.tmp" + +-- Iteration 2 -- +string(%d) "%srealpath_basic%srealpath_basic.tmp" + +-- Iteration 3 -- +string(%d) "%srealpath_basic%shome%stest%srealpath_basic.tmp" + +-- Iteration 4 -- +string(%d) "%srealpath_basic%srealpath_basic.tmp" + +-- Iteration 5 -- +bool(false) + +-- Iteration 6 -- +bool(false) + +-- Iteration 7 -- +bool(false) +Done diff --git a/ext/standard/tests/file/rename_basic.phpt b/ext/standard/tests/file/rename_basic.phpt index 8a255ca6e..28d3b1988 100755 --- a/ext/standard/tests/file/rename_basic.phpt +++ b/ext/standard/tests/file/rename_basic.phpt @@ -6,7 +6,7 @@ Test rename() function: basic functionality Description: Renames a file or directory */ -echo "*** Testing rename() for basic functions on existing file ***\n"; +echo "*** Testing rename() on non-existing file ***\n"; $file_path = dirname(__FILE__); $src_name = "$file_path/rename_basic.tmp"; $dest_name = "$file_path/rename_basic_new.tmp"; @@ -16,103 +16,30 @@ $fp = fopen($src_name, "w"); $s1 = stat($src_name); fclose($fp); -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false +var_dump( rename($src_name, $dest_name) ); // expecting true +var_dump( file_exists($src_name) ); // expecting false var_dump( file_exists($dest_name) ); // expecting true $s2 = stat("$file_path/rename_basic_new.tmp"); -// checking statistics of old and renamed file -// both should be same + +// checking statistics of old and renamed file - both should be same for ($i = 0; $i <= 12; $i++) { if ($s1[$i] != $s2[$i]) { echo "rename_basic.tmp and rename_basic_new.tmp stat differ at element $i\n"; } } -echo "\n*** Testing rename() on non-existing file ***\n"; -// try renaming a non existing file -$src_name = $file_path."/non_existent_file.tmp"; -$dest_name = $file_path."/rename_basic_new1.tmp"; -var_dump( rename($src_name, $dest_name) ); -// ensure that $dest_name didn't get created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting false - -// rename a existing dir to new name -echo "\n*** Testing rename() on existing directory ***\n"; -$dir_name = $file_path."/rename_basic_dir"; -mkdir($dir_name); -$new_dir_name = $file_path."/rename_basic_dir1"; -var_dump( rename($dir_name, $new_dir_name) ); -//ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting false -var_dump( file_exists($new_dir_name) ); // expecting true - -// try to rename an non_existing dir -echo "\n*** Testing rename() on non-existing directory ***\n"; -$non_existent_dir_name = $file_path."/non_existent_dir"; -$new_dir_name = "$file_path/rename_basic_dir2"; -var_dump( rename($non_existent_dir_name, $new_dir_name) ); -// ensure that $new_dir_name didn't get created -var_dump( file_exists($non_existent_dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting false - -echo "\n*** Testing rename() by giving stream context as third argument ***\n"; -$context = stream_context_create(); -// on directory -$dir_name = "$file_path/rename_basic_dir1"; -$new_dir_name = "$file_path/rename_basic_dir3"; -var_dump( rename($dir_name, $new_dir_name, $context) ); -// ensure that $new_dir_name got created -var_dump( file_exists($dir_name) ); // expecting flase -var_dump( file_exists($new_dir_name) ); // expecting true - -//on file -$src_name = "$file_path/rename_basic_new.tmp"; -$dest_name = "$file_path/rename_basic_new2.tmp"; -var_dump( rename($src_name, $dest_name, $context) ); -// ensure that $dest_name got created -var_dump( file_exists($src_name) ); // expecting false -var_dump( file_exists($dest_name) ); // expecting true - echo "Done\n"; ?> --CLEAN-- <?php -unlink(dirname(__FILE__)."/rename_basic_new2.tmp"); -rmdir(dirname(__FILE__)."/rename_basic_dir3"); +unlink(dirname(__FILE__)."/rename_basic.tmp"); +unlink(dirname(__FILE__)."/rename_basic_new.tmp"); ?> --EXPECTF-- -*** Testing rename() for basic functions on existing file *** -bool(true) -bool(false) -bool(true) - *** Testing rename() on non-existing file *** - -Warning: rename(%s/non_existent_file.tmp,%s/rename_basic_new1.tmp): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() on existing directory *** -bool(true) -bool(false) -bool(true) - -*** Testing rename() on non-existing directory *** - -Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d -bool(false) -bool(false) -bool(false) - -*** Testing rename() by giving stream context as third argument *** -bool(true) -bool(false) -bool(true) bool(true) bool(false) bool(true) Done + diff --git a/ext/standard/tests/file/rename_variation-win32.phpt b/ext/standard/tests/file/rename_variation-win32.phpt index 3cac5ccad..ae9555760 100644 --- a/ext/standard/tests/file/rename_variation-win32.phpt +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -14,7 +14,7 @@ if (substr(PHP_OS, 0, 3) != 'WIN') { require dirname(__FILE__).'/file.inc'; -/* creating directory */ +/* create directory */ $file_path = dirname(__FILE__); mkdir("$file_path/rename_variation"); @@ -30,7 +30,9 @@ $src_filenames = array( "$file_path/rename_variation//rename_variation.tmp", "$file_path//rename_variation//rename_variation.tmp", ); + $counter = 1; + /* loop through each $file and rename it to rename_variation2.tmp */ foreach($src_filenames as $src_filename) { echo "-- Iteration $counter --\n"; @@ -38,6 +40,7 @@ foreach($src_filenames as $src_filename) { fclose($fp); $dest_filename = "$file_path/rename_variation2.tmp"; var_dump( rename($src_filename, $dest_filename) ); + // ensure that file got renamed to new name var_dump( file_exists($src_filename) ); // expecting false var_dump( file_exists($dest_filename) ); // expecting true @@ -47,90 +50,8 @@ foreach($src_filenames as $src_filename) { unlink($dest_filename); } -// clean the temp dir and file rmdir("$file_path/rename_variation"); -// rename dirs across directories -echo "\n*** Testing rename() : renaming directory across directories ***\n"; -$src_dirs = array ( - /* Testing simple directory tree */ - "$file_path/rename_variation/", - - /* Testing a dir with trailing slash */ - "$file_path/rename_variation/", - - /* Testing dir with double trailing slashes */ - "$file_path//rename_variation//", -); - -$dest_dir = "$file_path/rename_variation_dir"; -// create the $dest_dir -mkdir($dest_dir); - -$counter = 1; -/* loop through each $src_dirs and rename it to $dest_dir */ -foreach($src_dirs as $src_dir) { - echo "-- Iteration $counter --\n"; - - // create the src dir - mkdir("$file_path/rename_variation/"); - // rename the src dir to a new dir in dest dir - var_dump( rename($src_dir, $dest_dir."/new_dir") ); - // ensure that dir was renamed - var_dump( file_exists($src_dir) ); // expecting false - var_dump( file_exists($dest_dir."/new_dir") ); // expecting true - - // remove the new dir - rmdir($dest_dir."/new_dir"); - $counter++; -} - -/* Renaming a file and directory to numeric name */ -echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; -$fp = fopen($file_path."/rename_variation.tmp", "w"); -fclose($fp); -// renaming existing file to numeric name -var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); -// ensure that rename worked fine -var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false -var_dump( file_exists($file_path."/12345" ) ); // expecting true -// remove the file -unlink($file_path."/12345"); - -// renaming a directory to numeric name -var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); -// ensure that rename worked fine -var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false -var_dump( file_exists($file_path."/12345" ) ); // expecting true - -// delete the file and dir -rmdir($file_path."/12345"); - -/* test rename() by trying to rename an existing file/dir to the same name - and one another */ -// create a dir -$file_path = dirname(__FILE__); -$dirname = "$file_path/rename_variation_dir"; -mkdir($dirname); -//create a file -$filename = "$file_path/rename_variation.tmp"; -$fp = fopen($filename, "w"); -fclose($fp); - -echo "\n-- Renaming file to same file name --\n"; -var_dump( rename($filename, $filename) ); - -echo "\n-- Renaming directory to same directory name --\n"; -var_dump( rename($dirname, $dirname) ); - -echo "\n-- Renaming existing file to existing directory name --\n"; -var_dump( rename($filename, $dirname) ); - -echo "\n-- Renaming existing directory to existing file name --\n"; -$fp = fopen($filename, "w"); -fclose($fp); -var_dump( rename($dirname, $filename) ); - echo "Done\n"; ?> --CLEAN-- @@ -147,53 +68,20 @@ bool(true) bool(false) bool(true) -- Iteration 2 -- -bool(true) -bool(false) -bool(true) --- Iteration 3 -- -bool(true) -bool(false) -bool(true) --- Iteration 4 -- -bool(true) -bool(false) -bool(true) -*** Testing rename() : renaming directory across directories *** --- Iteration 1 -- -bool(true) +Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): Invalid argument in %s on line %d bool(false) bool(true) --- Iteration 2 -- -bool(true) bool(false) -bool(true) --- Iteration 3 -- -bool(true) -bool(false) -bool(true) -*** Testing rename() by renaming a file and directory to numeric name *** +Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d +-- Iteration 3 -- bool(true) bool(false) bool(true) +-- Iteration 4 -- bool(true) bool(false) bool(true) +Done --- Renaming file to same file name -- -bool(true) - --- Renaming directory to same directory name -- -bool(true) - --- Renaming existing file to existing directory name -- - -Warning: rename(%s,%s): File exists in %s on line %d -bool(false) - --- Renaming existing directory to existing file name -- - -Warning: rename(%s,%s): File exists in %s on line %d -bool(false) -Done
\ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation1-win32.phpt b/ext/standard/tests/file/rename_variation1-win32.phpt new file mode 100644 index 000000000..0955096d7 --- /dev/null +++ b/ext/standard/tests/file/rename_variation1-win32.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); + +// rename dirs across directories +echo "\n*** Testing rename() : renaming directory across directories ***\n"; +$src_dirs = array ( + /* Testing simple directory tree */ + "$file_path/rename_variation/", + + /* Testing a dir with trailing slash */ + "$file_path/rename_variation/", + + /* Testing dir with double trailing slashes */ + "$file_path//rename_variation//", +); + +$dest_dir = "$file_path/rename_variation_dir"; + +// create the $dest_dir +mkdir($dest_dir); + +$counter = 1; + +/* loop through each $src_dirs and rename it to $dest_dir */ +foreach($src_dirs as $src_dir) { + echo "-- Iteration $counter --\n"; + + // create the src dir + mkdir("$file_path/rename_variation/"); + // rename the src dir to a new dir in dest dir + var_dump( rename($src_dir, $dest_dir."/new_dir") ); + // ensure that dir was renamed + var_dump( file_exists($src_dir) ); // expecting false + var_dump( file_exists($dest_dir."/new_dir") ); // expecting true + + // remove the new dir + rmdir($dest_dir."/new_dir"); + $counter++; +} + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/file/rename_variation2-win32.phpt b/ext/standard/tests/file/rename_variation2-win32.phpt new file mode 100644 index 000000000..87f4e7ddb --- /dev/null +++ b/ext/standard/tests/file/rename_variation2-win32.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +$file_path = dirname(__FILE__); +mkdir("$file_path/rename_variation_dir"); + +/* Renaming a file and directory to numeric name */ +echo "\n*** Testing rename() by renaming a file and directory to numeric name ***\n"; +$fp = fopen($file_path."/rename_variation.tmp", "w"); +fclose($fp); + +// renaming existing file to numeric name +var_dump( rename($file_path."/rename_variation.tmp", $file_path."/12345") ); + +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation.tmp" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +unlink($file_path."/12345"); + +// renaming a directory to numeric name +var_dump( rename($file_path."/rename_variation_dir/", $file_path."/12345") ); + +// ensure that rename worked fine +var_dump( file_exists($file_path."/rename_variation_dir" ) ); // expecting false +var_dump( file_exists($file_path."/12345" ) ); // expecting true + +rmdir($file_path."/12345"); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +*** Testing rename() by renaming a file and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/file/rename_variation3-win32.phpt b/ext/standard/tests/file/rename_variation3-win32.phpt new file mode 100644 index 000000000..7ad17093d --- /dev/null +++ b/ext/standard/tests/file/rename_variation3-win32.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +require dirname(__FILE__).'/file.inc'; + +/* creating directory */ +$file_path = dirname(__FILE__); +$dirname = "$file_path/rename_variation_dir"; +mkdir($dirname); + +/* test rename() by trying to rename an existing file/dir to the same name + and one another */ + +$filename = "$file_path/rename_variation.tmp"; +$fp = fopen($filename, "w"); +fclose($fp); + +echo "\n-- Renaming file to same file name --\n"; +var_dump( rename($filename, $filename) ); + +echo "\n-- Renaming directory to same directory name --\n"; +var_dump( rename($dirname, $dirname) ); + +echo "\n-- Renaming existing file to existing directory name --\n"; +var_dump( rename($filename, $dirname) ); + +echo "\n-- Renaming existing directory to existing file name --\n"; +$fp = fopen($filename, "w"); +fclose($fp); +var_dump( rename($dirname, $filename) ); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$file_path = dirname(__FILE__); +unlink($file_path."/rename_variation_link.tmp"); +unlink($file_path."/rename_variation.tmp"); +rmdir($file_path."/rename_variation_dir"); +?> +--EXPECTF-- +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s/rename_variation.tmp,%s/rename_variation_dir): File exists in %s on line %d +bool(false) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s/rename_variation_dir,%s/rename_variation.tmp): File exists in %s on line %d +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation8.phpt b/ext/standard/tests/file/rename_variation8.phpt new file mode 100644 index 000000000..650b6c990 --- /dev/null +++ b/ext/standard/tests/file/rename_variation8.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test rename() function: variation +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +echo "\n*** Testing rename() on non-existing file ***\n"; +$file_path = dirname(__FILE__); + +// try renaming a non existing file +$src_name = $file_path."/non_existent_file.tmp"; +$dest_name = $file_path."/rename_variation8_new.tmp"; +var_dump( rename($src_name, $dest_name) ); + +// ensure that $dest_name didn't get created +var_dump( file_exists($src_name) ); // expecting false +var_dump( file_exists($dest_name) ); // expecting false + +// rename a existing dir to new name +echo "\n*** Testing rename() on existing directory ***\n"; +$dir_name = $file_path."/rename_basic_dir"; +mkdir($dir_name); +$new_dir_name = $file_path."/rename_basic_dir1"; +var_dump( rename($dir_name, $new_dir_name) ); +//ensure that $new_dir_name got created +var_dump( file_exists($dir_name) ); // expecting false +var_dump( file_exists($new_dir_name) ); // expecting true + +// try to rename an non_existing dir +echo "\n*** Testing rename() on non-existing directory ***\n"; +$non_existent_dir_name = $file_path."/non_existent_dir"; +$new_dir_name = "$file_path/rename_basic_dir2"; +var_dump( rename($non_existent_dir_name, $new_dir_name) ); +// ensure that $new_dir_name didn't get created +var_dump( file_exists($non_existent_dir_name) ); // expecting flase +var_dump( file_exists($new_dir_name) ); // expecting false + +echo "Done\n"; +?> +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/rename_basic_new2.tmp"); +rmdir(dirname(__FILE__)."/rename_basic_dir1"); +?> +--EXPECTF-- +*** Testing rename() on non-existing file *** + +Warning: rename(%s/non_existent_file.tmp,%s/rename_variation8_new.tmp): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) + +*** Testing rename() on existing directory *** +bool(true) +bool(false) +bool(true) + +*** Testing rename() on non-existing directory *** + +Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d +bool(false) +bool(false) +bool(false) +Done + diff --git a/ext/standard/tests/file/rename_variation9.phpt b/ext/standard/tests/file/rename_variation9.phpt new file mode 100644 index 000000000..d923e4a3d --- /dev/null +++ b/ext/standard/tests/file/rename_variation9.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test rename() function: basic functionality +--FILE-- +<?php +/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] ); + Description: Renames a file or directory +*/ + +echo "\n*** Testing rename() by giving stream context as third argument ***\n"; +$file_path = dirname(__FILE__); + +$context = stream_context_create(); + +// on directory +$dir_name = "$file_path/rename_variation_dir9"; +$new_dir_name = "$file_path/rename_variation_dir9_new"; + +mkdir($dir_name); + +var_dump( rename($dir_name, $new_dir_name, $context) ); +var_dump( file_exists($dir_name) ); // expecting flase +var_dump( file_exists($new_dir_name) ); // expecting true + +//on file +$src_name = "$file_path/rename_variation9.tmp"; +$dest_name = "$file_path/rename_variation9_new.tmp"; + +// create the file +$fp = fopen($src_name, "w"); +$s1 = stat($src_name); +fclose($fp); + +var_dump( rename($src_name, $dest_name, $context) ); +var_dump( file_exists($src_name) ); // expecting false +var_dump( file_exists($dest_name) ); // expecting true + +echo "Done\n"; +?> +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/rename_variation9_new.tmp"); +rmdir(dirname(__FILE__)."/rename_variation_dir9_new"); +?> +--EXPECTF-- +*** Testing rename() by giving stream context as third argument *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) +Done + diff --git a/ext/standard/tests/general_functions/bug42272.phpt b/ext/standard/tests/general_functions/bug42272.phpt new file mode 100644 index 000000000..5a455d725 --- /dev/null +++ b/ext/standard/tests/general_functions/bug42272.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #42272: var_export() incorrectly escapes char(0). +--FILE-- +<?php +$foo = var_export("\0", true ); +echo $foo, "\n"; +var_export("a\0b"); +?> +--EXPECT-- +'' . "\0" . '' +'a' . "\0" . 'b' diff --git a/ext/standard/tests/general_functions/bug43293_1.phpt b/ext/standard/tests/general_functions/bug43293_1.phpt new file mode 100644 index 000000000..b4be25233 --- /dev/null +++ b/ext/standard/tests/general_functions/bug43293_1.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug#43293 (Multiple segfaults in getopt()) +--INI-- +register_argc_argv=Off +--FILE-- +<?php +$argv = array(1, 2, 3); +var_dump(getopt("abcd")); +var_dump($argv); +$argv = null; +var_dump(getopt("abcd")); +?> +--EXPECT-- +array(0) { +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +bool(false) + diff --git a/ext/standard/tests/general_functions/bug43293_2.phpt b/ext/standard/tests/general_functions/bug43293_2.phpt new file mode 100644 index 000000000..a91beebac --- /dev/null +++ b/ext/standard/tests/general_functions/bug43293_2.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug#43293 (Multiple segfaults in getopt()) +--INI-- +register_argc_argv=Off +--FILE-- +<?php +$argv = array(true, false); +var_dump(getopt("abcd")); +?> +--EXPECT-- +array(0) { +} + diff --git a/ext/standard/tests/general_functions/bug43293_3.phpt b/ext/standard/tests/general_functions/bug43293_3.phpt new file mode 100644 index 000000000..6c846610b --- /dev/null +++ b/ext/standard/tests/general_functions/bug43293_3.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug#43293 (Multiple segfaults in getopt()) +--SKIPIF-- +<?php +@getopt(null, array()); +if(error_get_last() !== null) { + echo "skip: longopts not enabled"; +} +?> +--ARGS-- +-f --f +--INI-- +register_argc_argv=On +--FILE-- +<?php +$args = array(true, false, "f"); +var_dump(getopt("f", $args), $args); +?> +--EXPECT-- +array(1) { + ["f"]=> + array(2) { + [0]=> + bool(false) + [1]=> + bool(false) + } +} +array(3) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + string(1) "f" +} + diff --git a/ext/standard/tests/general_functions/bug44394.phpt b/ext/standard/tests/general_functions/bug44394.phpt new file mode 100644 index 000000000..3a619283c --- /dev/null +++ b/ext/standard/tests/general_functions/bug44394.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #44394 Last two bytes missing from output +--FILE-- +<?php + +$string = "<a href='a?q=1'>asd</a>"; + +output_add_rewrite_var('a', 'b'); + +echo $string; + +ob_flush(); + +ob_end_clean(); + +?> +--EXPECT-- +<a href='a?q=1&a=b'>asd</a> diff --git a/ext/standard/tests/general_functions/bug44394_2.phpt b/ext/standard/tests/general_functions/bug44394_2.phpt new file mode 100644 index 000000000..68fae55d6 --- /dev/null +++ b/ext/standard/tests/general_functions/bug44394_2.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #44394 (Last two bytes missing from output) with session.use_trans_id +--SKIPIF-- +<?php if (!extension_loaded("session")) print "skip"; ?> +--FILE-- +<?php + +ini_set('session.use_trans_sid', 1); + +session_start(); + +ob_start(); + +$string = "<a href='a?q=1'>asd</a>"; + +output_add_rewrite_var('a', 'b'); + +echo $string; + +ob_flush(); + +ob_end_clean(); + +?> +--EXPECTF-- +<a href='a?q=1&PHPSESSID=%s&a=b'>asd</a> diff --git a/ext/standard/tests/general_functions/bug44487.phpt b/ext/standard/tests/general_functions/bug44487.phpt new file mode 100644 index 000000000..10c52c6b3 --- /dev/null +++ b/ext/standard/tests/general_functions/bug44487.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #44487 (call_user_method_array issues a warning when throwing an exception) +--INI-- +error_reporting = E_ALL & ~E_DEPRECATED +--FILE-- +<?php + +class Foo +{ + public function test() + { + print 'test'; + throw new Exception(); + } +} + +try { + $bar = new Foo(); + call_user_method_array('test', $bar, array()) ; +} catch (Exception $e) { +} +?> +--EXPECT-- +test diff --git a/ext/standard/tests/general_functions/bug44667.phpt b/ext/standard/tests/general_functions/bug44667.phpt new file mode 100644 index 000000000..49183cc58 --- /dev/null +++ b/ext/standard/tests/general_functions/bug44667.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #44667 (proc_open() does not handle pipes with the mode 'wb' correctly) +--SKIPIF-- +<?php if (!is_executable('/bin/cat')) echo 'skip cat not found'; ?> +--FILE-- +<?php + +$pipes = array(); + +$descriptor_spec = array( + 0 => array('pipe', 'rb'), + 1 => array('pipe', 'wb'), +); + +$proc = proc_open('cat', $descriptor_spec, $pipes); + +fwrite($pipes[0], 'Hello', 5); +fflush($pipes[0]); +fclose($pipes[0]); + +$result = fread($pipes[1], 5); +fclose($pipes[1]); + +proc_close($proc); + +echo "Result is: ", $result, "\n"; + +echo "Done\n"; + +?> +--EXPECTF-- +Result is: Hello +Done diff --git a/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt b/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt index f8cb94fb5..b90d22636 100755 --- a/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt +++ b/ext/standard/tests/general_functions/dl-cve-2007-4887.phpt @@ -1,5 +1,7 @@ --TEST-- dl() filename length checks (CVE-2007-4887) +--INI-- +enable_dl=On --FILE-- <?php var_dump(dl(str_repeat("a", 8376757))); diff --git a/ext/standard/tests/general_functions/getopt_002.phpt b/ext/standard/tests/general_functions/getopt_002.phpt new file mode 100644 index 000000000..3912ec87c --- /dev/null +++ b/ext/standard/tests/general_functions/getopt_002.phpt @@ -0,0 +1,42 @@ +--TEST-- +getopt#002 +--ARGS-- +-vvv -a value -1111 -2 -v +--INI-- +register_argc_argv=On +variables_order=GPS +--FILE-- +<?php + var_dump(getopt("2a:vcd1")); +?> +--EXPECT-- +array(4) { + ["v"]=> + array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(false) + [3]=> + bool(false) + } + ["a"]=> + string(5) "value" + [1]=> + array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(false) + [3]=> + bool(false) + } + [2]=> + bool(false) +} + + diff --git a/ext/standard/tests/general_functions/import_request.phpt b/ext/standard/tests/general_functions/import_request.phpt index c48a8f3ed..d9f43e93b 100644 --- a/ext/standard/tests/general_functions/import_request.phpt +++ b/ext/standard/tests/general_functions/import_request.phpt @@ -4,6 +4,8 @@ import_request_variables() tests a=1&b=heh&c=3&d[]=5&GLOBALS=test&1=hm --POST-- ap=25&bp=test&cp=blah3&dp[]=ar +--INI-- +register_globals=off --FILE-- <?php diff --git a/ext/standard/tests/general_functions/phpinfo.phpt b/ext/standard/tests/general_functions/phpinfo.phpt index 32125bfce..5b787ab55 100644 --- a/ext/standard/tests/general_functions/phpinfo.phpt +++ b/ext/standard/tests/general_functions/phpinfo.phpt @@ -24,7 +24,7 @@ Configure Command => %s Server API => Command Line Interface Virtual Directory Support => %s Configuration File (php.ini) Path => %s -Loaded Configuration File => %s +Loaded Configuration File => %a PHP API => %d PHP Extension => %d Zend Extension => %d diff --git a/ext/standard/tests/general_functions/var_export-locale.phpt b/ext/standard/tests/general_functions/var_export-locale.phpt index 6d2df8542..81896550b 100644 --- a/ext/standard/tests/general_functions/var_export-locale.phpt +++ b/ext/standard/tests/general_functions/var_export-locale.phpt @@ -572,9 +572,9 @@ string(3) "''" Iteration 12 -'\000' -'\000' -string(6) "'\000'" +'' . "\0" . '' +'' . "\0" . '' +string(14) "'' . "\0" . ''" Iteration 13 diff --git a/ext/standard/tests/general_functions/var_export.phpt b/ext/standard/tests/general_functions/var_export.phpt index 2a99c5bd8..b5cc886e4 100644 --- a/ext/standard/tests/general_functions/var_export.phpt +++ b/ext/standard/tests/general_functions/var_export.phpt @@ -565,9 +565,9 @@ string(3) "''" Iteration 12 -'\000' -'\000' -string(6) "'\000'" +'' . "\0" . '' +'' . "\0" . '' +string(14) "'' . "\0" . ''" Iteration 13 diff --git a/ext/standard/tests/math/acos_error.phpt b/ext/standard/tests/math/acos_error.phpt index 6e3f2ecfd..dd42fbb58 100644 --- a/ext/standard/tests/math/acos_error.phpt +++ b/ext/standard/tests/math/acos_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for acos() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/acosh_error.phpt b/ext/standard/tests/math/acosh_error.phpt index 8a4b9730e..fd2f92118 100644 --- a/ext/standard/tests/math/acosh_error.phpt +++ b/ext/standard/tests/math/acosh_error.phpt @@ -5,7 +5,6 @@ Test wrong number of arguments for acosh() if(substr(PHP_OS, 0, 3) == "WIN" ) die ("skip - function not supported on Windows"); ?> ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/asin_error.phpt b/ext/standard/tests/math/asin_error.phpt index 21c824b55..ef2a322e0 100644 --- a/ext/standard/tests/math/asin_error.phpt +++ b/ext/standard/tests/math/asin_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for asin() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/asinh_error.phpt b/ext/standard/tests/math/asinh_error.phpt index e6439d1bd..96f7ba061 100644 --- a/ext/standard/tests/math/asinh_error.phpt +++ b/ext/standard/tests/math/asinh_error.phpt @@ -5,7 +5,6 @@ Test wrong number of arguments for asinh() if(substr(PHP_OS, 0, 3) == "WIN" ) die ("skip - function not supported on Windows"); ?> ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/atan2_basic.phpt b/ext/standard/tests/math/atan2_basic.phpt new file mode 100644 index 000000000..65a0622c6 --- /dev/null +++ b/ext/standard/tests/math/atan2_basic.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test atan2() - basic function test of atan2() +--INI-- +precision=14 +--FILE-- +<?php +$valuesy = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + null, + true, + false); + +$valuesx = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + null, + true, + false); + +for ($i = 0; $i < count($valuesy); $i++) { + for ($j = 0; $j < count($valuesx); $j++) { + $res = atan2($valuesy[$i], $valuesx[$j]); + echo "Y:$valuesy[$i] X:$valuesx[$j] "; + var_dump($res); + } +} +?> +--EXPECTF-- +Y:23 X:23 float(0.78539816339745) +Y:23 X:-23 float(2.3561944901923) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:-23.45 float(2.3658820235113) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:2.345e1 float(0.77571063007847) +Y:23 X: float(1.5707963267949) +Y:23 X:1 float(1.5273454314034) +Y:23 X: float(1.5707963267949) +Y:-23 X:23 float(-0.78539816339745) +Y:-23 X:-23 float(-2.3561944901923) +Y:-23 X:23.45 float(-0.77571063007847) +Y:-23 X:-23.45 float(-2.3658820235113) +Y:-23 X:23 float(-0.78539816339745) +Y:-23 X:23 float(-0.78539816339745) +Y:-23 X:23 float(-0.78539816339745) +Y:-23 X:23.45 float(-0.77571063007847) +Y:-23 X:2.345e1 float(-0.77571063007847) +Y:-23 X: float(-1.5707963267949) +Y:-23 X:1 float(-1.5273454314034) +Y:-23 X: float(-1.5707963267949) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:-23 float(2.3465069568734) +Y:23.45 X:23.45 float(0.78539816339745) +Y:23.45 X:-23.45 float(2.3561944901923) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23.45 float(0.78539816339745) +Y:23.45 X:2.345e1 float(0.78539816339745) +Y:23.45 X: float(1.5707963267949) +Y:23.45 X:1 float(1.5281782247706) +Y:23.45 X: float(1.5707963267949) +Y:-23.45 X:23 float(-0.79508569671643) +Y:-23.45 X:-23 float(-2.3465069568734) +Y:-23.45 X:23.45 float(-0.78539816339745) +Y:-23.45 X:-23.45 float(-2.3561944901923) +Y:-23.45 X:23 float(-0.79508569671643) +Y:-23.45 X:23 float(-0.79508569671643) +Y:-23.45 X:23 float(-0.79508569671643) +Y:-23.45 X:23.45 float(-0.78539816339745) +Y:-23.45 X:2.345e1 float(-0.78539816339745) +Y:-23.45 X: float(-1.5707963267949) +Y:-23.45 X:1 float(-1.5281782247706) +Y:-23.45 X: float(-1.5707963267949) +Y:23 X:23 float(0.78539816339745) +Y:23 X:-23 float(2.3561944901923) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:-23.45 float(2.3658820235113) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:2.345e1 float(0.77571063007847) +Y:23 X: float(1.5707963267949) +Y:23 X:1 float(1.5273454314034) +Y:23 X: float(1.5707963267949) +Y:23 X:23 float(0.78539816339745) +Y:23 X:-23 float(2.3561944901923) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:-23.45 float(2.3658820235113) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:2.345e1 float(0.77571063007847) +Y:23 X: float(1.5707963267949) +Y:23 X:1 float(1.5273454314034) +Y:23 X: float(1.5707963267949) +Y:23 X:23 float(0.78539816339745) +Y:23 X:-23 float(2.3561944901923) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:-23.45 float(2.3658820235113) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23 float(0.78539816339745) +Y:23 X:23.45 float(0.77571063007847) +Y:23 X:2.345e1 float(0.77571063007847) +Y:23 X: float(1.5707963267949) +Y:23 X:1 float(1.5273454314034) +Y:23 X: float(1.5707963267949) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:-23 float(2.3465069568734) +Y:23.45 X:23.45 float(0.78539816339745) +Y:23.45 X:-23.45 float(2.3561944901923) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23 float(0.79508569671643) +Y:23.45 X:23.45 float(0.78539816339745) +Y:23.45 X:2.345e1 float(0.78539816339745) +Y:23.45 X: float(1.5707963267949) +Y:23.45 X:1 float(1.5281782247706) +Y:23.45 X: float(1.5707963267949) +Y:2.345e1 X:23 float(0.79508569671643) +Y:2.345e1 X:-23 float(2.3465069568734) +Y:2.345e1 X:23.45 float(0.78539816339745) +Y:2.345e1 X:-23.45 float(2.3561944901923) +Y:2.345e1 X:23 float(0.79508569671643) +Y:2.345e1 X:23 float(0.79508569671643) +Y:2.345e1 X:23 float(0.79508569671643) +Y:2.345e1 X:23.45 float(0.78539816339745) +Y:2.345e1 X:2.345e1 float(0.78539816339745) +Y:2.345e1 X: float(1.5707963267949) +Y:2.345e1 X:1 float(1.5281782247706) +Y:2.345e1 X: float(1.5707963267949) +Y: X:23 float(0) +Y: X:-23 float(3.1415926535898) +Y: X:23.45 float(0) +Y: X:-23.45 float(3.1415926535898) +Y: X:23 float(0) +Y: X:23 float(0) +Y: X:23 float(0) +Y: X:23.45 float(0) +Y: X:2.345e1 float(0) +Y: X: float(0) +Y: X:1 float(0) +Y: X: float(0) +Y:1 X:23 float(0.043450895391531) +Y:1 X:-23 float(3.0981417581983) +Y:1 X:23.45 float(0.042618102024328) +Y:1 X:-23.45 float(3.0989745515655) +Y:1 X:23 float(0.043450895391531) +Y:1 X:23 float(0.043450895391531) +Y:1 X:23 float(0.043450895391531) +Y:1 X:23.45 float(0.042618102024328) +Y:1 X:2.345e1 float(0.042618102024328) +Y:1 X: float(1.5707963267949) +Y:1 X:1 float(0.78539816339745) +Y:1 X: float(1.5707963267949) +Y: X:23 float(0) +Y: X:-23 float(3.1415926535898) +Y: X:23.45 float(0) +Y: X:-23.45 float(3.1415926535898) +Y: X:23 float(0) +Y: X:23 float(0) +Y: X:23 float(0) +Y: X:23.45 float(0) +Y: X:2.345e1 float(0) +Y: X: float(0) +Y: X:1 float(0) +Y: X: float(0) diff --git a/ext/standard/tests/math/atan2_error.phpt b/ext/standard/tests/math/atan2_error.phpt new file mode 100644 index 000000000..b56843e3a --- /dev/null +++ b/ext/standard/tests/math/atan2_error.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test atan2() - wrong params atan2() +--FILE-- +<?php +atan2(); +atan2(36); +atan2(36,25,0); +?> +--EXPECTF-- + +Warning: Wrong parameter count for atan2() in %s on line 2 + +Warning: Wrong parameter count for atan2() in %s on line 3 + +Warning: Wrong parameter count for atan2() in %s on line 4 diff --git a/ext/standard/tests/math/atan_error.phpt b/ext/standard/tests/math/atan_error.phpt index 07cc93aea..c1cbc7c3c 100644 --- a/ext/standard/tests/math/atan_error.phpt +++ b/ext/standard/tests/math/atan_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for atan() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/atanh_error.phpt b/ext/standard/tests/math/atanh_error.phpt index cb6fb6def..3201eef20 100644 --- a/ext/standard/tests/math/atanh_error.phpt +++ b/ext/standard/tests/math/atanh_error.phpt @@ -5,7 +5,6 @@ Test wrong number of arguments for atanh() if(substr(PHP_OS, 0, 3) == "WIN" ) die ("skip - function not supported on Windows"); ?> ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/base_convert_basic.phpt b/ext/standard/tests/math/base_convert_basic.phpt new file mode 100644 index 000000000..327f47c75 --- /dev/null +++ b/ext/standard/tests/math/base_convert_basic.phpt @@ -0,0 +1,316 @@ +--TEST-- +Test base_convert() - basic function tests base_convert() +--FILE-- +<?php +$frombase = array(2,8,10,16,36); +$tobase = array(2,8,10,16,36); + +$values = array(10, + 27, + 39, + 039, + 0x5F, + "10", + "27", + "39", + "5F", + "3XYZ" + ); + +for ($f= 0; $f < count($frombase); $f++) { + echo "\n...from base is ", $frombase[$f], "\n"; + for ($t= 0; $t < count($tobase); $t++) { + echo "......to base is ", $tobase[$t], "\n"; + for ($i =0; $i < count($values); $i++){ + $res = base_convert($values[$i],$frombase[$f],$tobase[$t]); + echo ".........value= ", $values[$i], " res = ", $res, "\n"; + } + } +} +?> + +--EXPECTF-- +...from base is 2 +......to base is 2 +.........value= 10 res = 10 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 3 res = 0 +.........value= 95 res = 0 +.........value= 10 res = 10 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 5F res = 0 +.........value= 3XYZ res = 0 +......to base is 8 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 3 res = 0 +.........value= 95 res = 0 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 5F res = 0 +.........value= 3XYZ res = 0 +......to base is 10 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 3 res = 0 +.........value= 95 res = 0 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 5F res = 0 +.........value= 3XYZ res = 0 +......to base is 16 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 3 res = 0 +.........value= 95 res = 0 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 5F res = 0 +.........value= 3XYZ res = 0 +......to base is 36 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 3 res = 0 +.........value= 95 res = 0 +.........value= 10 res = 2 +.........value= 27 res = 0 +.........value= 39 res = 0 +.........value= 5F res = 0 +.........value= 3XYZ res = 0 + +...from base is 8 +......to base is 2 +.........value= 10 res = 1000 +.........value= 27 res = 10111 +.........value= 39 res = 11 +.........value= 3 res = 11 +.........value= 95 res = 101 +.........value= 10 res = 1000 +.........value= 27 res = 10111 +.........value= 39 res = 11 +.........value= 5F res = 101 +.........value= 3XYZ res = 11 +......to base is 8 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 3 +.........value= 3 res = 3 +.........value= 95 res = 5 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 3 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 10 +.........value= 10 res = 8 +.........value= 27 res = 23 +.........value= 39 res = 3 +.........value= 3 res = 3 +.........value= 95 res = 5 +.........value= 10 res = 8 +.........value= 27 res = 23 +.........value= 39 res = 3 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 16 +.........value= 10 res = 8 +.........value= 27 res = 17 +.........value= 39 res = 3 +.........value= 3 res = 3 +.........value= 95 res = 5 +.........value= 10 res = 8 +.........value= 27 res = 17 +.........value= 39 res = 3 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 36 +.........value= 10 res = 8 +.........value= 27 res = n +.........value= 39 res = 3 +.........value= 3 res = 3 +.........value= 95 res = 5 +.........value= 10 res = 8 +.........value= 27 res = n +.........value= 39 res = 3 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 + +...from base is 10 +......to base is 2 +.........value= 10 res = 1010 +.........value= 27 res = 11011 +.........value= 39 res = 100111 +.........value= 3 res = 11 +.........value= 95 res = 1011111 +.........value= 10 res = 1010 +.........value= 27 res = 11011 +.........value= 39 res = 100111 +.........value= 5F res = 101 +.........value= 3XYZ res = 11 +......to base is 8 +.........value= 10 res = 12 +.........value= 27 res = 33 +.........value= 39 res = 47 +.........value= 3 res = 3 +.........value= 95 res = 137 +.........value= 10 res = 12 +.........value= 27 res = 33 +.........value= 39 res = 47 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 10 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 3 res = 3 +.........value= 95 res = 95 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 16 +.........value= 10 res = a +.........value= 27 res = 1b +.........value= 39 res = 27 +.........value= 3 res = 3 +.........value= 95 res = 5f +.........value= 10 res = a +.........value= 27 res = 1b +.........value= 39 res = 27 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 +......to base is 36 +.........value= 10 res = a +.........value= 27 res = r +.........value= 39 res = 13 +.........value= 3 res = 3 +.........value= 95 res = 2n +.........value= 10 res = a +.........value= 27 res = r +.........value= 39 res = 13 +.........value= 5F res = 5 +.........value= 3XYZ res = 3 + +...from base is 16 +......to base is 2 +.........value= 10 res = 10000 +.........value= 27 res = 100111 +.........value= 39 res = 111001 +.........value= 3 res = 11 +.........value= 95 res = 10010101 +.........value= 10 res = 10000 +.........value= 27 res = 100111 +.........value= 39 res = 111001 +.........value= 5F res = 1011111 +.........value= 3XYZ res = 11 +......to base is 8 +.........value= 10 res = 20 +.........value= 27 res = 47 +.........value= 39 res = 71 +.........value= 3 res = 3 +.........value= 95 res = 225 +.........value= 10 res = 20 +.........value= 27 res = 47 +.........value= 39 res = 71 +.........value= 5F res = 137 +.........value= 3XYZ res = 3 +......to base is 10 +.........value= 10 res = 16 +.........value= 27 res = 39 +.........value= 39 res = 57 +.........value= 3 res = 3 +.........value= 95 res = 149 +.........value= 10 res = 16 +.........value= 27 res = 39 +.........value= 39 res = 57 +.........value= 5F res = 95 +.........value= 3XYZ res = 3 +......to base is 16 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 3 res = 3 +.........value= 95 res = 95 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 5F res = 5f +.........value= 3XYZ res = 3 +......to base is 36 +.........value= 10 res = g +.........value= 27 res = 13 +.........value= 39 res = 1l +.........value= 3 res = 3 +.........value= 95 res = 45 +.........value= 10 res = g +.........value= 27 res = 13 +.........value= 39 res = 1l +.........value= 5F res = 2n +.........value= 3XYZ res = 3 + +...from base is 36 +......to base is 2 +.........value= 10 res = 100100 +.........value= 27 res = 1001111 +.........value= 39 res = 1110101 +.........value= 3 res = 11 +.........value= 95 res = 101001001 +.........value= 10 res = 100100 +.........value= 27 res = 1001111 +.........value= 39 res = 1110101 +.........value= 5F res = 11000011 +.........value= 3XYZ res = 101100111010111011 +......to base is 8 +.........value= 10 res = 44 +.........value= 27 res = 117 +.........value= 39 res = 165 +.........value= 3 res = 3 +.........value= 95 res = 511 +.........value= 10 res = 44 +.........value= 27 res = 117 +.........value= 39 res = 165 +.........value= 5F res = 303 +.........value= 3XYZ res = 547273 +......to base is 10 +.........value= 10 res = 36 +.........value= 27 res = 79 +.........value= 39 res = 117 +.........value= 3 res = 3 +.........value= 95 res = 329 +.........value= 10 res = 36 +.........value= 27 res = 79 +.........value= 39 res = 117 +.........value= 5F res = 195 +.........value= 3XYZ res = 183995 +......to base is 16 +.........value= 10 res = 24 +.........value= 27 res = 4f +.........value= 39 res = 75 +.........value= 3 res = 3 +.........value= 95 res = 149 +.........value= 10 res = 24 +.........value= 27 res = 4f +.........value= 39 res = 75 +.........value= 5F res = c3 +.........value= 3XYZ res = 2cebb +......to base is 36 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 3 res = 3 +.........value= 95 res = 95 +.........value= 10 res = 10 +.........value= 27 res = 27 +.........value= 39 res = 39 +.........value= 5F res = 5f +.........value= 3XYZ res = 3xyz
\ No newline at end of file diff --git a/ext/standard/tests/math/base_convert_error.phpt b/ext/standard/tests/math/base_convert_error.phpt new file mode 100644 index 000000000..7806c5648 --- /dev/null +++ b/ext/standard/tests/math/base_convert_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test base_convert() - wrong params base_convert() +--FILE-- +<?php +base_convert(); +base_convert(35); +base_convert(35,2); +base_convert(1234, 1, 10); +base_convert(1234, 10, 37); +?> +--EXPECTF-- + +Warning: Wrong parameter count for base_convert() in %s on line 2 + +Warning: Wrong parameter count for base_convert() in %s on line 3 + +Warning: Wrong parameter count for base_convert() in %s on line 4 + +Warning: base_convert(): Invalid `from base' (1) in %s on line 5 + +Warning: base_convert(): Invalid `to base' (37) in %s on line 6 diff --git a/ext/standard/tests/math/bindec_basic.phpt b/ext/standard/tests/math/bindec_basic.phpt new file mode 100644 index 000000000..e50dc8d48 --- /dev/null +++ b/ext/standard/tests/math/bindec_basic.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test bindec() - basic function test bindec() +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +$values = array(111000111, + 011100000, + 1111111111111111111111111111111, + 10000000000000000000000000000000, + 100002001, + '111000111', + '011100000', + '1111111111111111111111111111111', + '10000000000000000000000000000000', + '100002001', + 'abcdefg', + 311015, + 31101.3, + 31.1013e5, + 0x111ABC, + 011237, + true, + false, + null); + +for ($i = 0; $i < count($values); $i++) { + $res = bindec($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +int(455) +int(0) +int(32766) +int(5) +int(129) +int(455) +int(224) +int(2147483647) +float(2147483648) +int(129) +int(0) +int(13) +int(13) +int(26) +int(6) +int(0) +int(1) +int(0) +int(0) diff --git a/ext/standard/tests/math/bindec_basic_64bit.phpt b/ext/standard/tests/math/bindec_basic_64bit.phpt new file mode 100644 index 000000000..006983717 --- /dev/null +++ b/ext/standard/tests/math/bindec_basic_64bit.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test bindec() - basic function test bindec() +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php +$values = array(111000111, + 011100000, + 1111111111111111111111111111111, + 10000000000000000000000000000000, + 100002001, + '111000111', + '011100000', + '1111111111111111111111111111111', + '10000000000000000000000000000000', + '100002001', + 'abcdefg', + 311015, + 31101.3, + 31.1013e5, + 0x111ABC, + 011237, + true, + false, + null); + +for ($i = 0; $i < count($values); $i++) { + $res = bindec($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +int(455) +int(0) +int(32766) +int(5) +int(129) +int(455) +int(224) +int(2147483647) +int(2147483648) +int(129) +int(0) +int(13) +int(13) +int(26) +int(6) +int(0) +int(1) +int(0) +int(0) diff --git a/ext/standard/tests/math/bindec_error.phpt b/ext/standard/tests/math/bindec_error.phpt new file mode 100644 index 000000000..36193b63e --- /dev/null +++ b/ext/standard/tests/math/bindec_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test bindec() - basic function test bindec() +--FILE-- +<?php +bindec(); +bindec('01010101111',true); +?> +--EXPECTF-- + +Warning: Wrong parameter count for bindec() in %s on line 2 + +Warning: Wrong parameter count for bindec() in %s on line 3 diff --git a/ext/standard/tests/math/constants_basic.phpt b/ext/standard/tests/math/constants_basic.phpt new file mode 100644 index 000000000..0220d9335 --- /dev/null +++ b/ext/standard/tests/math/constants_basic.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test for pre-defined math constants +--INI-- +precision=14 +--FILE-- +<?php +echo "M_E= "; +var_dump(M_E); +echo "M_LOG2E= "; +var_dump(M_LOG2E); +echo "M_LOG10E= "; +var_dump(M_LOG10E); +echo "M_LN2= "; +var_dump(M_LN2); +echo "M_LN10= "; +var_dump(M_LN10); +echo "M_PI= "; +var_dump(M_PI); +echo "M_PI_2= "; +var_dump(M_PI_2); +echo "M_PI_4= "; +var_dump(M_PI_4); +echo "M_1_PI= "; +var_dump(M_1_PI); +echo "M_2_PI= "; +var_dump(M_2_PI); +echo "M_SQRTPI= "; +var_dump(M_SQRTPI); +echo "M_2_SQRTPI= "; +var_dump(M_2_SQRTPI); +echo "M_LNPI= "; +var_dump(M_LNPI); +echo "M_EULER= "; +var_dump(M_EULER); +echo "M_SQRT2= "; +var_dump(M_SQRT2); +echo "M_SQRT1_2= "; +var_dump(M_SQRT1_2); +echo "M_SQRT3= "; +var_dump(M_SQRT3); +echo "INF= "; +var_dump(INF); +echo "NAN= "; +var_dump(NAN); +?> +--EXPECT-- +M_E= float(2.718281828459) +M_LOG2E= float(1.442695040889) +M_LOG10E= float(0.43429448190325) +M_LN2= float(0.69314718055995) +M_LN10= float(2.302585092994) +M_PI= float(3.1415926535898) +M_PI_2= float(1.5707963267949) +M_PI_4= float(0.78539816339745) +M_1_PI= float(0.31830988618379) +M_2_PI= float(0.63661977236758) +M_SQRTPI= float(1.7724538509055) +M_2_SQRTPI= float(1.1283791670955) +M_LNPI= float(1.1447298858494) +M_EULER= float(0.57721566490153) +M_SQRT2= float(1.4142135623731) +M_SQRT1_2= float(0.70710678118655) +M_SQRT3= float(1.7320508075689) +INF= float(INF) +NAN= float(NAN) diff --git a/ext/standard/tests/math/cos_error.phpt b/ext/standard/tests/math/cos_error.phpt index 1a9a26ce6..3198b9e82 100644 --- a/ext/standard/tests/math/cos_error.phpt +++ b/ext/standard/tests/math/cos_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for cos() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/cosh_error.phpt b/ext/standard/tests/math/cosh_error.phpt index f91cb256a..f4552e61c 100644 --- a/ext/standard/tests/math/cosh_error.phpt +++ b/ext/standard/tests/math/cosh_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for cosh() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/decbin_basic.phpt b/ext/standard/tests/math/decbin_basic.phpt new file mode 100644 index 000000000..e6fc5dc30 --- /dev/null +++ b/ext/standard/tests/math/decbin_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test decbin() - basic function test +--FILE-- +<?php +$values = array(10, + 3950.5, + 3.9505e3, + 039, + 0x5F, + "10", + "3950.5", + "3.9505e3", + "039", + "0x5F", + true, + false, + null, + ); + +for ($i = 0; $i < count($values); $i++) { + $res = decbin($values[$i]); + var_dump($res); +} +?> + +--EXPECTF-- +string(4) "1010" +string(12) "111101101110" +string(12) "111101101110" +string(2) "11" +string(7) "1011111" +string(4) "1010" +string(12) "111101101110" +string(2) "11" +string(6) "100111" +string(1) "0" +string(1) "1" +string(1) "0" +string(1) "0"
\ No newline at end of file diff --git a/ext/standard/tests/math/decbin_error.phpt b/ext/standard/tests/math/decbin_error.phpt new file mode 100644 index 000000000..a350cee7f --- /dev/null +++ b/ext/standard/tests/math/decbin_error.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test decbin() - wrong params +--FILE-- +<?php +decbin(); +decbin(23,2,true); +?> +--EXPECTF-- + +Warning: Wrong parameter count for decbin() in %s on line 2 + +Warning: Wrong parameter count for decbin() in %s on line 3 + diff --git a/ext/standard/tests/math/dechex_basic.phpt b/ext/standard/tests/math/dechex_basic.phpt new file mode 100644 index 000000000..cba4aa632 --- /dev/null +++ b/ext/standard/tests/math/dechex_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test dechex() - basic function dechex() +--FILE-- +<?php +$values = array(10, + 3950.5, + 3.9505e3, + 039, + 0x5F, + "10", + "3950.5", + "3.9505e3", + "039", + "0x5F", + true, + false, + null, + ); + +for ($i = 0; $i < count($values); $i++) { + $res = dechex($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +string(1) "a" +string(3) "f6e" +string(3) "f6e" +string(1) "3" +string(2) "5f" +string(1) "a" +string(3) "f6e" +string(1) "3" +string(2) "27" +string(1) "0" +string(1) "1" +string(1) "0" +string(1) "0"
\ No newline at end of file diff --git a/ext/standard/tests/math/dechex_error.phpt b/ext/standard/tests/math/dechex_error.phpt new file mode 100644 index 000000000..f83afb346 --- /dev/null +++ b/ext/standard/tests/math/dechex_error.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test dechex() - wrong params dechex() +--FILE-- +<?php +dechex(); +dechex(23,2,true); +?> + +--EXPECTF-- + +Warning: Wrong parameter count for dechex() in %s on line 2 + +Warning: Wrong parameter count for dechex() in %s on line 3 diff --git a/ext/standard/tests/math/decoct_basic.phpt b/ext/standard/tests/math/decoct_basic.phpt new file mode 100644 index 000000000..3021e6be1 --- /dev/null +++ b/ext/standard/tests/math/decoct_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test decoct() - basic function test decoct() +--FILE-- +<?php +$values = array(10, + 3950.5, + 3.9505e3, + 039, + 0x5F, + "10", + "3950.5", + "3.9505e3", + "039", + "0x5F", + true, + false, + null, + ); + +for ($i = 0; $i < count($values); $i++) { + $res = decoct($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +string(2) "12" +string(4) "7556" +string(4) "7556" +string(1) "3" +string(3) "137" +string(2) "12" +string(4) "7556" +string(1) "3" +string(2) "47" +string(1) "0" +string(1) "1" +string(1) "0" +string(1) "0" diff --git a/ext/standard/tests/math/decoct_error.phpt b/ext/standard/tests/math/decoct_error.phpt new file mode 100644 index 000000000..48c30644f --- /dev/null +++ b/ext/standard/tests/math/decoct_error.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test decoct() - wrong params decoct() +--FILE-- +<?php +decoct(); +decoct(23,2,true); +?> +--EXPECTF-- + +Warning: Wrong parameter count for decoct() in %s on line 2 + +Warning: Wrong parameter count for decoct() in %s on line 3 + diff --git a/ext/standard/tests/math/deg2rad_basic.phpt b/ext/standard/tests/math/deg2rad_basic.phpt new file mode 100644 index 000000000..64771b998 --- /dev/null +++ b/ext/standard/tests/math/deg2rad_basic.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test return type and value for expected input deg2rad() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float deg2rad(float number) + * Function is implemented in ext/standard/math.c +*/ + +$file_path = dirname(__FILE__); +require($file_path."/allowed_rounding_error.inc"); + +$arg_0 = 0.0; +$arg_1 = 90.0; +$arg_2 = 180.0; +$arg_3 = 360.0; + + +echo "deg2rad $arg_0 = "; +$r0 = deg2rad($arg_0); +var_dump($r0); +if (allowed_rounding_error($r0 ,0 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} + +echo "deg2rad $arg_1 = "; +$r1 = deg2rad($arg_1); +var_dump($r1); +if (allowed_rounding_error($r1 ,1.5707963267949 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +echo "deg2rad $arg_2 = "; +$r2 = deg2rad($arg_2); +var_dump($r2); +if (allowed_rounding_error($r2 ,3.1415926535898 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +echo "deg2rad $arg_3 = "; +$r3 = deg2rad($arg_3); +var_dump($r3); +if (allowed_rounding_error($r3 ,6.2831853071796 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +?> +--EXPECTF-- +deg2rad 0 = float(%f) +Pass +deg2rad 90 = float(%f) +Pass +deg2rad 180 = float(%f) +Pass +deg2rad 360 = float(%f) +Pass diff --git a/ext/standard/tests/math/deg2rad_error.phpt b/ext/standard/tests/math/deg2rad_error.phpt new file mode 100644 index 000000000..3cfdfc304 --- /dev/null +++ b/ext/standard/tests/math/deg2rad_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test wrong number of arguments for deg2rad() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float deg2rad(float number) + * Function is implemented in ext/standard/math.c +*/ + +$arg_0 = 1.0; +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(deg2rad($arg_0, $extra_arg)); + +echo "\nToo few arguments\n"; +var_dump(deg2rad()); + +?> +--EXPECTF-- +Too many arguments + +Warning: Wrong parameter count for deg2rad() in %s on line 11 +NULL + +Too few arguments + +Warning: Wrong parameter count for deg2rad() in %s on line 14 +NULL diff --git a/ext/standard/tests/math/deg2rad_variation.phpt b/ext/standard/tests/math/deg2rad_variation.phpt new file mode 100644 index 000000000..4ce8900a9 --- /dev/null +++ b/ext/standard/tests/math/deg2rad_variation.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test variations in usage of deg2rad() +--INI-- +precision = 10 +--FILE-- +<?php +/* + * proto float deg2rad(float number) + * Function is implemented in ext/standard/math.c +*/ + + +//Test deg2rad with a different input values + +$values = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + "nonsense", + "1000", + "1000ABC", + null, + true, + false); + +for ($i = 0; $i < count($values); $i++) { + $res = deg2rad($values[$i]); + var_dump($res); +} + +?> +--EXPECT-- +float(0.401425728) +float(-0.401425728) +float(0.4092797096) +float(-0.4092797096) +float(0.401425728) +float(0.401425728) +float(0.401425728) +float(0.4092797096) +float(0.4092797096) +float(0) +float(17.45329252) +float(17.45329252) +float(0) +float(0.01745329252) +float(0) diff --git a/ext/standard/tests/math/exp_error.phpt b/ext/standard/tests/math/exp_error.phpt new file mode 100644 index 000000000..21949f4a7 --- /dev/null +++ b/ext/standard/tests/math/exp_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test exp() - wrong params for exp() +--INI-- +precision=14 +--FILE-- +<?php +exp(); +exp(23,true); +?> +--EXPECTF-- + +Warning: exp() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: exp() expects exactly 1 parameter, 2 given in %s on line %d diff --git a/ext/standard/tests/math/fmod_basic.phpt b/ext/standard/tests/math/fmod_basic.phpt new file mode 100644 index 000000000..c29abca9d --- /dev/null +++ b/ext/standard/tests/math/fmod_basic.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test fmod() - basic function test fmod() +--INI-- +precision=14 +--FILE-- +<?php +$values1 = array(234, + -234, + 23.45e1, + -23.45e1, + 0xEA, + 0352, + "234", + "234.5", + "23.45e1", + null, + true, + false); + +$values2 = array(2, + -2, + 2.3e1, + -2.3e1, + 0x2, + 02, + "2", + "2.3", + "2.3e1", + null, + true, + false); +for ($i = 0; $i < count($values1); $i++) { + echo "\niteration ", $i, "\n"; + + for ($j = 0; $j < count($values2); $j++) { + $res = fmod($values1[$i], $values2[$j]); + var_dump($res); + } +} +?> +--EXPECTF-- + +iteration 0 +float(0) +float(0) +float(4) +float(4) +float(0) +float(0) +float(0) +float(1.7) +float(4) +float(NAN) +float(0) +float(NAN) + +iteration 1 +float(-0) +float(-0) +float(-4) +float(-4) +float(-0) +float(-0) +float(-0) +float(-1.7) +float(-4) +float(NAN) +float(-0) +float(NAN) + +iteration 2 +float(0.5) +float(0.5) +float(4.5) +float(4.5) +float(0.5) +float(0.5) +float(0.5) +float(2.2) +float(4.5) +float(NAN) +float(0.5) +float(NAN) + +iteration 3 +float(-0.5) +float(-0.5) +float(-4.5) +float(-4.5) +float(-0.5) +float(-0.5) +float(-0.5) +float(-2.2) +float(-4.5) +float(NAN) +float(-0.5) +float(NAN) + +iteration 4 +float(0) +float(0) +float(4) +float(4) +float(0) +float(0) +float(0) +float(1.7) +float(4) +float(NAN) +float(0) +float(NAN) + +iteration 5 +float(0) +float(0) +float(4) +float(4) +float(0) +float(0) +float(0) +float(1.7) +float(4) +float(NAN) +float(0) +float(NAN) + +iteration 6 +float(0) +float(0) +float(4) +float(4) +float(0) +float(0) +float(0) +float(1.7) +float(4) +float(NAN) +float(0) +float(NAN) + +iteration 7 +float(0.5) +float(0.5) +float(4.5) +float(4.5) +float(0.5) +float(0.5) +float(0.5) +float(2.2) +float(4.5) +float(NAN) +float(0.5) +float(NAN) + +iteration 8 +float(0.5) +float(0.5) +float(4.5) +float(4.5) +float(0.5) +float(0.5) +float(0.5) +float(2.2) +float(4.5) +float(NAN) +float(0.5) +float(NAN) + +iteration 9 +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(NAN) +float(0) +float(NAN) + +iteration 10 +float(1) +float(1) +float(1) +float(1) +float(1) +float(1) +float(1) +float(1) +float(1) +float(NAN) +float(0) +float(NAN) + +iteration 11 +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(0) +float(NAN) +float(0) +float(NAN) diff --git a/ext/standard/tests/math/fmod_error.phpt b/ext/standard/tests/math/fmod_error.phpt new file mode 100644 index 000000000..42a6ad1a0 --- /dev/null +++ b/ext/standard/tests/math/fmod_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test fmod() - wrong params test fmod() +--INI-- +precision=14 +--FILE-- +<?php +fmod(); +fmod(23); +fmod(23,2,true); +?> +--EXPECTF-- + +Warning: fmod() expects exactly 2 parameters, 0 given in %s on line 2 + +Warning: fmod() expects exactly 2 parameters, 1 given in %s on line 3 + +Warning: fmod() expects exactly 2 parameters, 3 given in %s on line 4 diff --git a/ext/standard/tests/math/getrandmax_basic.phpt b/ext/standard/tests/math/getrandmax_basic.phpt new file mode 100644 index 000000000..4e52c192d --- /dev/null +++ b/ext/standard/tests/math/getrandmax_basic.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test getrandmax() - basic function test getrandmax() +--FILE-- +<?php +$biggest_int = getrandmax(); +var_dump($biggest_int); +?> +--EXPECTF-- +int(%d)
\ No newline at end of file diff --git a/ext/standard/tests/math/getrandmax_error.phpt b/ext/standard/tests/math/getrandmax_error.phpt new file mode 100644 index 000000000..9f244a2a6 --- /dev/null +++ b/ext/standard/tests/math/getrandmax_error.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test getrandmax() - wrong params test getrandmax() +--FILE-- +<?php +var_dump($biggest_int = getrandmax(true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for getrandmax() in %s on line 2 +NULL diff --git a/ext/standard/tests/math/hexdec_basic.phpt b/ext/standard/tests/math/hexdec_basic.phpt new file mode 100644 index 000000000..1c42ae7e4 --- /dev/null +++ b/ext/standard/tests/math/hexdec_basic.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test hexdec() - basic function test hexdec() +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +$values = array(0x123abc, + 0x789DEF, + 0x7FFFFFFF, + 0x80000000, + '0x123abc', + '0x789DEF', + '0x7FFFFFFF', + '0x80000000', + '0x123XYZABC', + 311015, + '311015', + 31101.3, + 31.1013e5, + 011237, + '011237', + true, + false, + null); +for ($i = 0; $i < count($values); $i++) { + $res = hexdec($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +int(18433668) +int(126895953) +float(142929835591) +float(142929835592) +int(1194684) +int(7904751) +int(2147483647) +float(2147483648) +int(1194684) +int(3215381) +int(3215381) +int(3215379) +int(51446064) +int(18279) +int(70199) +int(1) +int(0) +int(0) diff --git a/ext/standard/tests/math/hexdec_error.phpt b/ext/standard/tests/math/hexdec_error.phpt new file mode 100644 index 000000000..06ce3fb20 --- /dev/null +++ b/ext/standard/tests/math/hexdec_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test hexdec() - wrong params test hexdec() +--FILE-- +<?php +hexdec(); +hexdec('0x123abc',true); +?> +--EXPECTF-- + +Warning: Wrong parameter count for hexdec() in %s on line 2 + +Warning: Wrong parameter count for hexdec() in %s on line 3 diff --git a/ext/standard/tests/math/hypot_error.phpt b/ext/standard/tests/math/hypot_error.phpt new file mode 100644 index 000000000..19a9ee085 --- /dev/null +++ b/ext/standard/tests/math/hypot_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test hypot() - wrong params test hypot() +--INI-- +precision=14 +--FILE-- +<?php +hypot(); +hypot(36); +hypot(36,25,0); +?> +--EXPECTF-- + + +Warning: Wrong parameter count for hypot() in %s on line 2 + +Warning: Wrong parameter count for hypot() in %s on line 3 + +Warning: Wrong parameter count for hypot() in %s on line 4 diff --git a/ext/standard/tests/math/is_finite_basic.phpt b/ext/standard/tests/math/is_finite_basic.phpt new file mode 100644 index 000000000..85d268527 --- /dev/null +++ b/ext/standard/tests/math/is_finite_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test is_finite() - basic function test is_finite() +--FILE-- +<?php +$values = array(234, + -234, + 23.45e1, + -23.45e1, + 0xEA, + 0352, + "234", + "234.5", + "23.45e1", + null, + true, + false, + pow(0, -2), + acos(1.01)); +; +for ($i = 0; $i < count($values); $i++) { + $res = is_finite($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) + + diff --git a/ext/standard/tests/math/is_finite_error.phpt b/ext/standard/tests/math/is_finite_error.phpt new file mode 100644 index 000000000..e26563079 --- /dev/null +++ b/ext/standard/tests/math/is_finite_error.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test is_finite() - wrong params test is_finite() +--FILE-- +<?php +is_finite(); +is_finite(23,2,true); +?> +--EXPECTF-- + +Warning: is_finite() expects exactly 1 parameter, 0 given in %s on line 2 + +Warning: is_finite() expects exactly 1 parameter, 3 given in %s on line 3 + diff --git a/ext/standard/tests/math/is_infinite_basic.phpt b/ext/standard/tests/math/is_infinite_basic.phpt new file mode 100644 index 000000000..ca7992228 --- /dev/null +++ b/ext/standard/tests/math/is_infinite_basic.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test is_infinite() - basic function test is_infinite() +--FILE-- +<?php +$values = array(234, + -234, + 23.45e1, + -23.45e1, + 0xEA, + 0352, + "234", + "234.5", + "23.45e1", + null, + true, + false, + pow(0, -2), + acos(1.01)); +; +for ($i = 0; $i < count($values); $i++) { + $res = is_infinite($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) + + + diff --git a/ext/standard/tests/math/is_infinite_error.phpt b/ext/standard/tests/math/is_infinite_error.phpt new file mode 100644 index 000000000..5d6ad9d42 --- /dev/null +++ b/ext/standard/tests/math/is_infinite_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test is_infinite() - wrong params test is_infinite() +--FILE-- +<?php +is_infinite(); +is_infinite(23,2,true); +?> +--EXPECTF-- + +Warning: is_infinite() expects exactly 1 parameter, 0 given in %s on line 2 + +Warning: is_infinite() expects exactly 1 parameter, 3 given in %s on line 3 diff --git a/ext/standard/tests/math/is_nan_basic.phpt b/ext/standard/tests/math/is_nan_basic.phpt new file mode 100644 index 000000000..fb10737ce --- /dev/null +++ b/ext/standard/tests/math/is_nan_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test is_nan() - basic function test is_nan() +--FILE-- +<?php +$values = array(234, + -234, + 23.45e1, + -23.45e1, + 0xEA, + 0352, + "234", + "234.5", + "23.45e1", + null, + true, + false, + pow(0, -2), + acos(1.01)); + + +for ($i = 0; $i < count($values); $i++) { + $res = is_nan($values[$i]); + var_dump($res); +} + +?> + +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) + + + diff --git a/ext/standard/tests/math/is_nan_error.phpt b/ext/standard/tests/math/is_nan_error.phpt new file mode 100644 index 000000000..7749e4e40 --- /dev/null +++ b/ext/standard/tests/math/is_nan_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test is_nan() - wrong params test is_nan() +--FILE-- +<?php +is_nan(); +is_nan(23,2,true); +?> +--EXPECTF-- + +Warning: is_nan() expects exactly 1 parameter, 0 given in %s on line 2 + +Warning: is_nan() expects exactly 1 parameter, 3 given in %s on line 3 + + + + diff --git a/ext/standard/tests/math/lcg_value_basic.phpt b/ext/standard/tests/math/lcg_value_basic.phpt new file mode 100644 index 000000000..6d624d84a --- /dev/null +++ b/ext/standard/tests/math/lcg_value_basic.phpt @@ -0,0 +1,56 @@ +--TEST-- +Maths test for xapic versions of lcg_value() +--FILE-- +<?php + +echo "MATHS test script started\n"; + + +echo "\n lcg_value tests...\n"; +for ($i = 0; $i < 100; $i++) { + $res = lcg_value(); + + if (!is_float($res) || $res < 0 || $res > 1) { + break; + } +} + +if ($i != 100) { + echo "FAILED\n"; +} else { + echo "PASSED\n"; +} + +echo "\n lcg_value error cases..spurious args get ignored\n"; +$res = lcg_value(23); + +if (!is_float($res) || $res < 0 || $res > 1) { + echo "FAILED\n"; +} else { + echo "PASSED\n"; +} + +$res = lcg_value(10,false); +if (!is_float($res) || $res < 0 || $res > 1) { + echo "FAILED\n"; +} else { + echo "PASSED\n"; +} + +echo "MATHS test script completed\n"; + +?> + +--EXPECT-- +MATHS test script started + + lcg_value tests... +PASSED + + lcg_value error cases..spurious args get ignored +PASSED +PASSED +MATHS test script completed + + + diff --git a/ext/standard/tests/math/log10_basic.phpt b/ext/standard/tests/math/log10_basic.phpt new file mode 100644 index 000000000..0877df23d --- /dev/null +++ b/ext/standard/tests/math/log10_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test return type and value for expected input log10() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float log10(float number) + * Function is implemented in ext/standard/math.c +*/ + +$file_path = dirname(__FILE__); +require($file_path."/allowed_rounding_error.inc"); + +$arg_0 = 1.0; +$arg_1 = 10.0; +$arg_2 = 100.0; + +echo "log10 $arg_0 = "; +$r0 = log10($arg_0); +var_dump($r0); +if (allowed_rounding_error($r0 ,0.0 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} + +echo "log10 $arg_1 = "; +$r1 = log10($arg_1); +var_dump($r1); +if (allowed_rounding_error($r1 ,1.0 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} + +echo "log10 $arg_2 = "; +$r2 = log10($arg_2); +var_dump($r2); +if (allowed_rounding_error($r2 ,2.0 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +?> +--EXPECTF-- +log10 1 = float(%f) +Pass +log10 10 = float(%f) +Pass +log10 100 = float(%f) +Pass diff --git a/ext/standard/tests/math/log10_error.phpt b/ext/standard/tests/math/log10_error.phpt new file mode 100644 index 000000000..083494a84 --- /dev/null +++ b/ext/standard/tests/math/log10_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test wrong number of arguments for log10() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float log10(float number) + * Function is implemented in ext/standard/math.c +*/ + +$arg_0 = 1.0; +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(log10($arg_0, $extra_arg)); + +echo "\nToo few arguments\n"; +var_dump(log10()); + +?> +--EXPECTF-- +Too many arguments + +Warning: Wrong parameter count for log10() in %s on line 11 +NULL + +Too few arguments + +Warning: Wrong parameter count for log10() in %s on line 14 +NULL diff --git a/ext/standard/tests/math/log10_variation.phpt b/ext/standard/tests/math/log10_variation.phpt new file mode 100644 index 000000000..746412a44 --- /dev/null +++ b/ext/standard/tests/math/log10_variation.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test variations in usage of log10() +--INI-- +precision = 10 +--FILE-- +<?php +/* + * proto float log10(float number) + * Function is implemented in ext/standard/math.c +*/ + + +//Test log10 with a different input values + +$values = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + "nonsense", + "1000", + "1000ABC", + null, + true, + false); + +for ($i = 0; $i < count($values); $i++) { + $res = log10($values[$i]); + var_dump($res); +} + +?> +--EXPECT-- +float(1.361727836) +float(NAN) +float(1.370142847) +float(NAN) +float(1.361727836) +float(1.361727836) +float(1.361727836) +float(1.370142847) +float(1.370142847) +float(-INF) +float(3) +float(3) +float(-INF) +float(0) +float(-INF) diff --git a/ext/standard/tests/math/log_basic.phpt b/ext/standard/tests/math/log_basic.phpt new file mode 100644 index 000000000..e2f9c9fe7 --- /dev/null +++ b/ext/standard/tests/math/log_basic.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test log() - basic function test log() +--INI-- +precision=14 +--FILE-- +<?php +$values = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + null, + true, + false); + +echo "\n LOG tests...no base\n"; +for ($i = 0; $i < count($values); $i++) { + $res = log($values[$i]); + var_dump($res); +} + +echo "\n LOG tests...base\n"; +for ($i = 0; $i < count($values); $i++) { + $res = log($values[$i], 4); + var_dump($res); +} +?> + +--EXPECTF-- + LOG tests...no base +float(3.1354942159291) +float(NAN) +float(3.1548704948923) +float(NAN) +float(3.1354942159291) +float(3.1354942159291) +float(3.1354942159291) +float(3.1548704948923) +float(3.1548704948923) +float(-INF) +float(0) +float(-INF) + + LOG tests...base +float(2.2617809780285) +float(NAN) +float(2.275758008814) +float(NAN) +float(2.2617809780285) +float(2.2617809780285) +float(2.2617809780285) +float(2.275758008814) +float(2.275758008814) +float(-INF) +float(0) +float(-INF) diff --git a/ext/standard/tests/math/log_error.phpt b/ext/standard/tests/math/log_error.phpt new file mode 100644 index 000000000..77084a4ec --- /dev/null +++ b/ext/standard/tests/math/log_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test log() - wrong params test log() +--INI-- +precision=14 +--FILE-- +<?php +log(); +log(36,4,true); +log(36, -4); +?> +--EXPECTF-- + +Warning: Wrong parameter count for log() in %s on line 2 + +Warning: Wrong parameter count for log() in %s on line 3 + +Warning: log(): base must be greater than 0 in %s on line 4 diff --git a/ext/standard/tests/math/mt_getrandmax_basic.phpt b/ext/standard/tests/math/mt_getrandmax_basic.phpt new file mode 100644 index 000000000..29a30d088 --- /dev/null +++ b/ext/standard/tests/math/mt_getrandmax_basic.phpt @@ -0,0 +1,8 @@ +--TEST-- +Test mt_getrandmax() - basic function test mt_getrandmax() +--FILE-- +<?php +var_dump(mt_getrandmax()); +?> +--EXPECTF-- +int(%d)
\ No newline at end of file diff --git a/ext/standard/tests/math/mt_getrandmax_error.phpt b/ext/standard/tests/math/mt_getrandmax_error.phpt new file mode 100644 index 000000000..b30da3a91 --- /dev/null +++ b/ext/standard/tests/math/mt_getrandmax_error.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test mt_getrandmax() - wrong paramas mt_getrandmax() +--FILE-- +<?php +var_dump(mt_getrandmax(true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for mt_getrandmax() in %s on line 2 +NULL
\ No newline at end of file diff --git a/ext/standard/tests/math/mt_rand_basic.phpt b/ext/standard/tests/math/mt_rand_basic.phpt new file mode 100644 index 000000000..8b6b3cb2c --- /dev/null +++ b/ext/standard/tests/math/mt_rand_basic.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test mt_rand() - basic function test mt_rand() +--FILE-- +<?php +$default_max = mt_getrandmax(); + +echo "\nmt_rand() tests with default min and max value (i.e 0 thru ", $default_max, ")\n"; +for ($i = 0; $i < 100; $i++) { + $res = mt_rand(); + +// By default RAND_MAX is 32768 although no constant is defined for it for user space apps + if (!is_int($res) || $res < 0 || $res > $default_max) { + break; + } +} + +if ($i != 100) { + echo "FAILED: res = ", $res, " min = 0 max = ", $default_max, "\n"; +} else { + echo "PASSED: range min = 0 max = ", $default_max, "\n"; +} + +echo "\nmt_rand() tests with defined min and max value\n"; + +$min = array(10, + 100, + 10.5, + 10.5e3, + 0x10, + 0400); + +$max = array(100, + 1000, + 19.5, + 10.5e5, + 0x10000, + 0700); + +for ($x = 0; $x < count($min); $x++) { + for ($i = 0; $i < 100; $i++) { + $res = mt_rand($min[$x], $max[$x]); + + if (!is_int($res) || $res < intval($min[$x]) || $res > intval($max[$x])) { + echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + break; + } + } + + if ($i == 100) { + echo "PASSED: range min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + } +} + +echo "\nNon-numeric cases\n"; +$min = array(true, + false, + null, + "10", + "0x10", + "10.5"); + +// Eexepcted numerical equivalent of above non-numerics +$minval = array(1, + 0, + 0, + 10, + 0, + 10); +for ($x = 0; $x < count($min); $x++) { + for ($i = 0; $i < 100; $i++) { + $res = mt_rand($min[$x], 100); + + if (!is_int($res) || $res < intval($minval[$x]) || $res > 100) { + echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + break; + } + } + + if ($i == 100) { + echo "PASSED range min = ", intval($min[$x]), " max = 100\n"; + } +} +?> +--EXPECTF-- +mt_rand() tests with default min and max value (i.e 0 thru 2147483647) +PASSED: range min = 0 max = 2147483647 + +mt_rand() tests with defined min and max value +PASSED: range min = 10 max = 100 +PASSED: range min = 100 max = 1000 +PASSED: range min = 10 max = 19 +PASSED: range min = 10500 max = 1050000 +PASSED: range min = 16 max = 65536 +PASSED: range min = 256 max = 448 + +Non-numeric cases +PASSED range min = 1 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 10 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 10 max = 100 diff --git a/ext/standard/tests/math/mt_rand_error.phpt b/ext/standard/tests/math/mt_rand_error.phpt new file mode 100644 index 000000000..e0a80586e --- /dev/null +++ b/ext/standard/tests/math/mt_rand_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test mt_rand() - wrong params test mt_rand() +--FILE-- +<?php +mt_rand(25); +mt_rand(10,100,false); +mt_rand("one", 100); +mt_rand(1, "hundered"); +?> + +--EXPECTF-- + +Warning: mt_rand() expects exactly 2 parameters, 1 given in %s on line 2 + +Warning: mt_rand() expects exactly 2 parameters, 3 given in %s on line 3 + +Warning: mt_rand() expects parameter 1 to be long, string given in %s on line 4 + +Warning: mt_rand() expects parameter 2 to be long, string given in %s on line 5 diff --git a/ext/standard/tests/math/mt_srand_basic.phpt b/ext/standard/tests/math/mt_srand_basic.phpt new file mode 100644 index 000000000..e28b1b9ea --- /dev/null +++ b/ext/standard/tests/math/mt_srand_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test mt_srand() - basic function (return values) mt_srand() +--FILE-- +<?php +// Should return NULL if given anything that it can convert to long +// This doesn't actually test what it does with the input :-\ +var_dump(mt_srand()); +var_dump(mt_srand(500)); +var_dump(mt_srand(500.1)); +var_dump(mt_srand("500")); +var_dump(mt_srand("500E3")); +var_dump(mt_srand(true)); +var_dump(mt_srand(false)); +var_dump(mt_srand(NULL)); +?> +--EXPECTF-- +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL
\ No newline at end of file diff --git a/ext/standard/tests/math/mt_srand_error.phpt b/ext/standard/tests/math/mt_srand_error.phpt new file mode 100644 index 000000000..5543d7841 --- /dev/null +++ b/ext/standard/tests/math/mt_srand_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test mt_srand() - wrong params test mt_srand() +--FILE-- +<?php +var_dump(mt_srand(500, true)); +var_dump(mt_srand("fivehundred")); +var_dump(mt_srand("500ABC")); +?> +--EXPECTF-- +Warning: mt_srand() expects at most 1 parameter, 2 given in %s on line 2 +NULL + +Warning: mt_srand() expects parameter 1 to be long, string given in %s on line 3 +NULL + +Notice: A non well formed numeric value encountered in %s on line 4 +NULL + + + diff --git a/ext/standard/tests/math/number_format_error.phpt b/ext/standard/tests/math/number_format_error.phpt new file mode 100644 index 000000000..5ebe12931 --- /dev/null +++ b/ext/standard/tests/math/number_format_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test number_format() - wrong params test number_format() +--FILE-- +<?php +number_format(); +number_format(23,2,true); +number_format(23,2,true,false,36); +?> +--EXPECTF-- + +Warning: Wrong parameter count for number_format() in %s on line 2 + +Warning: Wrong parameter count for number_format() in %s on line 3 + +Warning: Wrong parameter count for number_format() in %s on line 4 + diff --git a/ext/standard/tests/math/octdec_basic.phpt b/ext/standard/tests/math/octdec_basic.phpt new file mode 100644 index 000000000..8fd57ecfe --- /dev/null +++ b/ext/standard/tests/math/octdec_basic.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test octdec() - basic function test octdec() +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +$values = array(01234567, + 0567, + 017777777777, + 020000000000, + 0x1234ABC, + 12345, + '01234567', + '0567', + '017777777777', + '020000000000', + '0x1234ABC', + '12345', + 31101.3, + 31.1013e5, + true, + false, + null); + +for ($i = 0; $i < count($values); $i++) { + $res = octdec($values[$i]); + var_dump($res); +} +?> +--EXPECTF-- +int(14489) +int(253) +int(36947879) +int(4618484) +int(4104) +int(5349) +int(342391) +int(375) +int(2147483647) +float(2147483648) +int(668) +int(5349) +int(102923) +int(823384) +int(1) +int(0) +int(0)
\ No newline at end of file diff --git a/ext/standard/tests/math/octdec_error.phpt b/ext/standard/tests/math/octdec_error.phpt new file mode 100644 index 000000000..8a3d1759a --- /dev/null +++ b/ext/standard/tests/math/octdec_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test octdec() - wrong params test octdec() +--FILE-- +<?php +octdec(); +octdec('0123567',true); +?> +--EXPECTF-- + +Warning: Wrong parameter count for octdec() in %s on line 2 + +Warning: Wrong parameter count for octdec() in %s on line 3 diff --git a/ext/standard/tests/math/pi_basic.phpt b/ext/standard/tests/math/pi_basic.phpt new file mode 100644 index 000000000..fec569137 --- /dev/null +++ b/ext/standard/tests/math/pi_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test pi() - basic function test pi() +--INI-- +precision=14 +--FILE-- +<?php +echo pi(), "\n"; +echo M_PI, "\n"; +// N.B pi() ignores all specified arguments no error +// messages are produced if arguments are spcified. +?> +--EXPECTF-- +3.1415926535898 +3.1415926535898 diff --git a/ext/standard/tests/math/pow_basic.phpt b/ext/standard/tests/math/pow_basic.phpt new file mode 100644 index 000000000..96864e0ab --- /dev/null +++ b/ext/standard/tests/math/pow_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test pow() - basic function test pow() +--INI-- +precision=14 +--FILE-- +<?php +$values = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + null, + true, + false); + +for ($i = 0; $i < count($values); $i++) { + $res = pow($values[$i], 4); + var_dump($res); +} +?> +--EXPECTF-- +int(279841) +int(279841) +float(302392.75950625) +float(302392.75950625) +int(279841) +int(279841) +int(279841) +float(302392.75950625) +float(302392.75950625) +int(0) +int(1) +int(0)
\ No newline at end of file diff --git a/ext/standard/tests/math/pow_error.phpt b/ext/standard/tests/math/pow_error.phpt new file mode 100644 index 000000000..d00173eb4 --- /dev/null +++ b/ext/standard/tests/math/pow_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test pow() - wrong params test pow() +--INI-- +precision=14 +--FILE-- +<?php +pow(); +pow(36); +pow(36,4,true); +?> +--EXPECTF-- + +Warning: pow() expects exactly 2 parameters, 0 given in %s line 2 + +Warning: pow() expects exactly 2 parameters, 1 given in %s line 3 + +Warning: pow() expects exactly 2 parameters, 3 given in %s line 4 + + diff --git a/ext/standard/tests/math/rad2deg_basic.phpt b/ext/standard/tests/math/rad2deg_basic.phpt new file mode 100644 index 000000000..0256ffbd9 --- /dev/null +++ b/ext/standard/tests/math/rad2deg_basic.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test return type and value for expected input rad2deg() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float rad2deg(float number) + * Function is implemented in ext/standard/math.c +*/ + +$file_path = dirname(__FILE__); +require($file_path."/allowed_rounding_error.inc"); + +$arg_0 = 0.0; +$arg_1 = 1.570796327; +$arg_2 = 3.141592654; +$arg_3 = 6.283185307; + +echo "rad2deg $arg_0= "; +$r0 = rad2deg($arg_0); +var_dump($r0); +if (allowed_rounding_error($r0 ,0 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +echo "rad2deg $arg_1 = "; +$r1 = rad2deg($arg_1); +var_dump($r1); +if (allowed_rounding_error($r1 ,90.000000011752)) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +echo "rad2deg $arg_2 = "; +$r2 = rad2deg($arg_2); +var_dump($r2); +if (allowed_rounding_error($r2 ,180.0000000235 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +echo "rad2deg $arg_3 = "; +$r3 = rad2deg($arg_3); +var_dump($r3); +if (allowed_rounding_error($r3 ,359.99999998971 )) { + echo "Pass\n"; +} +else { + echo "Fail\n"; +} +?> +--EXPECTF-- +rad2deg 0= float(%f) +Pass +rad2deg 1.570796327 = float(%f) +Pass +rad2deg 3.141592654 = float(%f) +Pass +rad2deg 6.283185307 = float(%f) +Pass diff --git a/ext/standard/tests/math/rad2deg_error.phpt b/ext/standard/tests/math/rad2deg_error.phpt new file mode 100644 index 000000000..989232106 --- /dev/null +++ b/ext/standard/tests/math/rad2deg_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test wrong number of arguments for rad2deg() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float rad2deg(float number) + * Function is implemented in ext/standard/math.c +*/ + +$arg_0 = 1.0; +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(rad2deg($arg_0, $extra_arg)); + +echo "\nToo few arguments\n"; +var_dump(rad2deg()); + +?> +--EXPECTF-- +Too many arguments + +Warning: Wrong parameter count for rad2deg() in %s on line 11 +NULL + +Too few arguments + +Warning: Wrong parameter count for rad2deg() in %s on line 14 +NULL diff --git a/ext/standard/tests/math/rad2deg_variation.phpt b/ext/standard/tests/math/rad2deg_variation.phpt new file mode 100644 index 000000000..3fd6ec8cf --- /dev/null +++ b/ext/standard/tests/math/rad2deg_variation.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test variations in usage of rad2deg() +--INI-- +precision = 10 +--FILE-- +<?php +/* + * proto float rad2deg(float number) + * Function is implemented in ext/standard/math.c +*/ + + +//Test rad2deg with a different input values + +$values = array(23, + -23, + 2.345e1, + -2.345e1, + 0x17, + 027, + "23", + "23.45", + "2.345e1", + "nonsense", + "1000", + "1000ABC", + null, + true, + false); + +for ($i = 0; $i < count($values); $i++) { + $res = rad2deg($values[$i]); + var_dump($res); +} + +?> +--EXPECT-- +float(1317.802929) +float(-1317.802929) +float(1343.58603) +float(-1343.58603) +float(1317.802929) +float(1317.802929) +float(1317.802929) +float(1343.58603) +float(1343.58603) +float(0) +float(57295.77951) +float(57295.77951) +float(0) +float(57.29577951) +float(0) diff --git a/ext/standard/tests/math/rand_basic.phpt b/ext/standard/tests/math/rand_basic.phpt new file mode 100644 index 000000000..525956017 --- /dev/null +++ b/ext/standard/tests/math/rand_basic.phpt @@ -0,0 +1,103 @@ +--TEST-- +Test rand() - basic function test rand() +--FILE-- +<?php +$default_max = getrandmax(); + +echo "\nrand() tests with default min and max value (i.e 0 thru ", $default_max, ")\n"; +for ($i = 0; $i < 100; $i++) { + $res = rand(); + +// By default RAND_MAX is 32768 although no constant is defined for it for user space apps + if (!is_int($res) || $res < 0 || $res > $default_max) { + break; + } +} + +if ($i != 100) { + echo "FAILED: res = ", $res, " min = 0 max = ", $default_max, "\n"; +} else { + echo "PASSED: range min = 0 max = ", $default_max, "\n"; +} + +echo "\nrand() tests with defined min and max value\n"; + +$min = array(10, + 100, + 10.5, + 10.5e3, + 0x10, + 0400); + +$max = array(100, + 1000, + 19.5, + 10.5e5, + 0x10000, + 0700); + +for ($x = 0; $x < count($min); $x++) { + for ($i = 0; $i < 100; $i++) { + $res = rand($min[$x], $max[$x]); + + if (!is_int($res) || $res < intval($min[$x]) || $res > intval($max[$x])) { + echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + break; + } + } + + if ($i == 100) { + echo "PASSED: range min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + } +} + +echo "\nNon-numeric cases\n"; +$min = array(true, + false, + null, + "10", + "0x10", + "10.5"); + +// Eexepcted numerical equivalent of above non-numerics +$minval = array(1, + 0, + 0, + 10, + 0, + 10); +for ($x = 0; $x < count($min); $x++) { + for ($i = 0; $i < 100; $i++) { + $res = rand($min[$x], 100); + + if (!is_int($res) || $res < intval($minval[$x]) || $res > 100) { + echo "FAILED: res = ", $res, " min = ", intval($min[$x]), " max = ", intval($max[$x]), "\n"; + break; + } + } + + if ($i == 100) { + echo "PASSED range min = ", intval($min[$x]), " max = 100\n"; + } +} +?> +--EXPECTF-- + +rand() tests with default min and max value (i.e 0 thru %i) +PASSED: range min = 0 max = %i + +rand() tests with defined min and max value +PASSED: range min = 10 max = 100 +PASSED: range min = 100 max = 1000 +PASSED: range min = 10 max = 19 +PASSED: range min = 10500 max = 1050000 +PASSED: range min = 16 max = 65536 +PASSED: range min = 256 max = 448 + +Non-numeric cases +PASSED range min = 1 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 10 max = 100 +PASSED range min = 0 max = 100 +PASSED range min = 10 max = 100 diff --git a/ext/standard/tests/math/rand_error.phpt b/ext/standard/tests/math/rand_error.phpt new file mode 100644 index 000000000..79aa0112d --- /dev/null +++ b/ext/standard/tests/math/rand_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test rand() - wrong params test rand() +--FILE-- +<?php +rand(25); +rand(10,100,false); +rand("one", 100); +rand(1, "hundered"); +?> +--EXPECTF-- + +Warning: rand() expects exactly 2 parameters, 1 given in %s on line 2 + +Warning: rand() expects exactly 2 parameters, 3 given in %s on line 3 + +Warning: rand() expects parameter 1 to be long, string given in %s on line 4 + +Warning: rand() expects parameter 2 to be long, string given in %s on line 5 diff --git a/ext/standard/tests/math/sin_error.phpt b/ext/standard/tests/math/sin_error.phpt index e2693ea8f..3fdb10af1 100644 --- a/ext/standard/tests/math/sin_error.phpt +++ b/ext/standard/tests/math/sin_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for sin() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/sinh_error.phpt b/ext/standard/tests/math/sinh_error.phpt index 415d6b09b..8a3584dfc 100644 --- a/ext/standard/tests/math/sinh_error.phpt +++ b/ext/standard/tests/math/sinh_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for sinh() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/sqrt_basic.phpt b/ext/standard/tests/math/sqrt_basic.phpt new file mode 100644 index 000000000..076a11301 --- /dev/null +++ b/ext/standard/tests/math/sqrt_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test return type and value for expected input sqrt() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float sqrt(float number) + * Function is implemented in ext/standard/math.c +*/ + +$arg_0 = 9.0; + +var_dump(sqrt($arg_0)); + +?> +--EXPECT-- +float(3) diff --git a/ext/standard/tests/math/sqrt_error.phpt b/ext/standard/tests/math/sqrt_error.phpt new file mode 100644 index 000000000..318a18a35 --- /dev/null +++ b/ext/standard/tests/math/sqrt_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test wrong number of arguments for sqrt() +--INI-- +precision = 14 +--FILE-- +<?php +/* + * proto float sqrt(float number) + * Function is implemented in ext/standard/math.c +*/ + +$arg_0 = 1.0; +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(sqrt($arg_0, $extra_arg)); + +echo "\nToo few arguments\n"; +var_dump(sqrt()); + +?> +--EXPECTF-- +Too many arguments + +Warning: Wrong parameter count for sqrt() in %s on line 11 +NULL + +Too few arguments + +Warning: Wrong parameter count for sqrt() in %s on line 14 +NULL diff --git a/ext/standard/tests/math/srand_basic.phpt b/ext/standard/tests/math/srand_basic.phpt new file mode 100644 index 000000000..16aa2dd69 --- /dev/null +++ b/ext/standard/tests/math/srand_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +Maths test for xapic versions of srand() +--FILE-- +<?php +// Should return NULL if given anything that it can convert to long +// This doesn't actually test what it does with the input :-\ +var_dump(srand()); +var_dump(srand(500)); +var_dump(srand(500.1)); +var_dump(srand("500")); +var_dump(srand("500E3")); +var_dump(srand(true)); +var_dump(srand(false)); +var_dump(srand(NULL)); +?> +--EXPECTF-- +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL
\ No newline at end of file diff --git a/ext/standard/tests/math/srand_error.phpt b/ext/standard/tests/math/srand_error.phpt new file mode 100644 index 000000000..852867222 --- /dev/null +++ b/ext/standard/tests/math/srand_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test srand() - wrong params test srand() +--FILE-- +<?php +var_dump(mt_srand(500, true)); +var_dump(mt_srand("fivehundred")); +var_dump(mt_srand("500ABC")); +?> +--EXPECTF-- +Warning: mt_srand() expects at most 1 parameter, 2 given in %s on line 2 +NULL + +Warning: mt_srand() expects parameter 1 to be long, string given in %s on line 3 +NULL + +Notice: A non well formed numeric value encountered in %s on line 4 +NULL diff --git a/ext/standard/tests/math/tan_error.phpt b/ext/standard/tests/math/tan_error.phpt index 58dcc2a43..3508f0e78 100644 --- a/ext/standard/tests/math/tan_error.phpt +++ b/ext/standard/tests/math/tan_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for tan() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/math/tanh_error.phpt b/ext/standard/tests/math/tanh_error.phpt index 8ce3e9131..f90de5eb5 100644 --- a/ext/standard/tests/math/tanh_error.phpt +++ b/ext/standard/tests/math/tanh_error.phpt @@ -1,6 +1,5 @@ --TEST-- Test wrong number of arguments for tanh() ---INI-- --FILE-- <?php /* diff --git a/ext/standard/tests/network/gethostbyaddr_error.phpt b/ext/standard/tests/network/gethostbyaddr_error.phpt new file mode 100644 index 000000000..2c54ae994 --- /dev/null +++ b/ext/standard/tests/network/gethostbyaddr_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test gethostbyaddr() function : error conditions +--FILE-- +<?php +/* Prototype : proto string gethostbyaddr(string ip_address) + * Description: Get the Internet host name corresponding to a given IP address + * Source code: ext/standard/dns.c + * Alias to functions: + */ + + +echo "Testing gethostbyaddr : error conditions\n"; + +// Zero arguments +echo "\n-- Testing gethostbyaddr function with Zero arguments --\n"; +var_dump( gethostbyaddr() ); + +//Test gethostbyaddr with one more than the expected number of arguments +echo "\n-- Testing gethostbyaddr function with more than expected no. of arguments --\n"; +$ip_address = 'string_val'; +$extra_arg = 10; +var_dump( gethostbyaddr($ip_address, $extra_arg) ); + +echo "\n-- Testing gethostbyaddr function with invalid addresses --\n"; + +$ip_address = 'invalid'; +var_dump( gethostbyaddr($ip_address) ); + +$ip_address = '300.1.2.3'; +var_dump( gethostbyaddr($ip_address) ); + +$ip_address = '256.1.2.3'; +var_dump( gethostbyaddr($ip_address) ); + +echo "Done"; +?> +--EXPECTREGEX-- +Testing gethostbyaddr : error conditions + +-- Testing gethostbyaddr function with Zero arguments -- + +Warning: Wrong parameter count for gethostbyaddr\(\) in .* on line \d+ +NULL + +-- Testing gethostbyaddr function with more than expected no. of arguments -- + +Warning: Wrong parameter count for gethostbyaddr\(\) in .* on line \d+ +NULL + +-- Testing gethostbyaddr function with invalid addresses -- + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) + +Warning: gethostbyaddr\(\): Address is not (in a.b.c.d form|a valid IPv4 or IPv6 address) in .* on line \d+ +bool\(false\) +Done diff --git a/ext/standard/tests/network/gethostbynamel_error.phpt b/ext/standard/tests/network/gethostbynamel_error.phpt new file mode 100644 index 000000000..7e58d5ad5 --- /dev/null +++ b/ext/standard/tests/network/gethostbynamel_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test gethostbynamel() function : error conditions +--FILE-- +<?php +/* Prototype : proto array gethostbynamel(string hostname) + * Description: Return a list of IP addresses that a given hostname resolves to. + * Source code: ext/standard/dns.c + * Alias to functions: + */ + +echo "*** Testing gethostbynamel() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing gethostbynamel() function with Zero arguments --\n"; +var_dump( gethostbynamel() ); + +//Test gethostbynamel with one more than the expected number of arguments +echo "\n-- Testing gethostbynamel() function with more than expected no. of arguments --\n"; +$hostname = 'string_val'; +$extra_arg = 10; +var_dump( gethostbynamel($hostname, $extra_arg) ); + +echo "\n-- Testing gethostbynamel() with an unknown host --\n"; +$hostname = 'unknownhost_zzz_xxx_yyy'; +var_dump( gethostbynamel($hostname) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing gethostbynamel() : error conditions *** + +-- Testing gethostbynamel() function with Zero arguments -- + +Warning: Wrong parameter count for gethostbynamel() in %s on line %d +NULL + +-- Testing gethostbynamel() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for gethostbynamel() in %s on line %d +NULL + +-- Testing gethostbynamel() with an unknown host -- +bool(false) +Done diff --git a/ext/standard/tests/reg/ereg_basic_001.phpt b/ext/standard/tests/reg/ereg_basic_001.phpt new file mode 100644 index 000000000..485b2d26e --- /dev/null +++ b/ext/standard/tests/reg/ereg_basic_001.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test ereg() function : basic functionality (with $regs) +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with ereg, specifying $regs + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "--> Pattern: '$pattern'; string: '$string'\n"; + var_dump(ereg($pattern, $string, $regs)); + var_dump($regs); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; string: '--- ab ---' +int(6) +array(3) { + [0]=> + string(6) "- ab -" + [1]=> + string(1) "a" + [2]=> + string(1) "b" +} +--> Pattern: '()'; string: '' +int(1) +array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +--> Pattern: '()'; string: 'abcdef' +int(1) +array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +--> Pattern: '[x]|[^x]'; string: 'abcdef' +int(1) +array(1) { + [0]=> + string(1) "a" +} +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; string: '--- aaa bbb ccc ddd ---' +int(15) +array(6) { + [0]=> + string(15) "aaa bbb ccc ddd" + [1]=> + string(1) "a" + [2]=> + string(2) "aa" + [3]=> + string(3) "bbb" + [4]=> + string(3) "ccc" + [5]=> + string(3) "ddd" +} +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; string: '\`^.[$()|*+?{'' +int(14) +array(1) { + [0]=> + string(14) "\`^.[$()|*+?{'" +} +--> Pattern: '\a'; string: 'a' +int(1) +array(1) { + [0]=> + string(1) "a" +} +--> Pattern: '[0-9][^0-9]'; string: '2a' +int(2) +array(1) { + [0]=> + string(2) "2a" +} +--> Pattern: '^[[:alnum:]]{62,62}$'; string: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +int(62) +array(1) { + [0]=> + string(62) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} +--> Pattern: '^[[:digit:]]{5}'; string: '0123456789' +int(5) +array(1) { + [0]=> + string(5) "01234" +} +--> Pattern: '[[:digit:]]{5}$'; string: '0123456789' +int(5) +array(1) { + [0]=> + string(5) "56789" +} +--> Pattern: '[[:blank:]]{1,10}'; string: ' + ' +int(2) +array(1) { + [0]=> + string(2) " " +} +--> Pattern: '[[:print:]]{3}'; string: ' a ' +int(3) +array(1) { + [0]=> + string(3) " a " +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_basic_002.phpt b/ext/standard/tests/reg/ereg_basic_002.phpt new file mode 100644 index 000000000..672632fc7 --- /dev/null +++ b/ext/standard/tests/reg/ereg_basic_002.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test ereg() function : basic functionality (without $regs) +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with ereg, without specifying $regs + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "--> Pattern: '$pattern'; string: '$string'\n"; + var_dump(ereg($pattern, $string)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; string: '--- ab ---' +int(1) +--> Pattern: '()'; string: '' +int(1) +--> Pattern: '()'; string: 'abcdef' +int(1) +--> Pattern: '[x]|[^x]'; string: 'abcdef' +int(1) +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; string: '--- aaa bbb ccc ddd ---' +int(1) +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; string: '\`^.[$()|*+?{'' +int(1) +--> Pattern: '\a'; string: 'a' +int(1) +--> Pattern: '[0-9][^0-9]'; string: '2a' +int(1) +--> Pattern: '^[[:alnum:]]{62,62}$'; string: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +int(1) +--> Pattern: '^[[:digit:]]{5}'; string: '0123456789' +int(1) +--> Pattern: '[[:digit:]]{5}$'; string: '0123456789' +int(1) +--> Pattern: '[[:blank:]]{1,10}'; string: ' + ' +int(1) +--> Pattern: '[[:print:]]{3}'; string: ' a ' +int(1) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_basic_003.phpt b/ext/standard/tests/reg/ereg_basic_003.phpt new file mode 100644 index 000000000..8c1473883 --- /dev/null +++ b/ext/standard/tests/reg/ereg_basic_003.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test ereg() function : basic functionality - long RE +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a long RE with lots of matches + */ + +var_dump(ereg(str_repeat('(.)', 2048), str_repeat('x', 2048))); +var_dump(ereg(str_repeat('(.)', 2048), str_repeat('x', 2048), $regs)); +var_dump(count($regs)); + +echo "Done"; +?> +--EXPECTF-- +int(1) +int(2048) +int(2049) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_basic_004.phpt b/ext/standard/tests/reg/ereg_basic_004.phpt new file mode 100644 index 000000000..1356eaf63 --- /dev/null +++ b/ext/standard/tests/reg/ereg_basic_004.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test ereg() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$regs = 'original'; + +var_dump(ereg('A', 'a', $regs)); +var_dump(ereg('[A-Z]', '0', $regs)); +var_dump(ereg('(a){4}', 'aaa', $regs)); +var_dump(ereg('^a', 'ba', $regs)); +var_dump(ereg('b$', 'ba', $regs)); +var_dump(ereg('[:alpha:]', 'x', $regs)); + +// Ensure $regs is unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_error_001.phpt b/ext/standard/tests/reg/ereg_error_001.phpt new file mode 100644 index 000000000..44bb1f965 --- /dev/null +++ b/ext/standard/tests/reg/ereg_error_001.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test ereg() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test wrong number of args + */ + +echo "*** Testing ereg() : error conditions ***\n"; + + +//Test ereg with one more than the expected number of arguments +echo "\n-- Testing ereg() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$string = 'string_val'; +$registers = array(1, 2); +$extra_arg = 10; +var_dump( ereg($pattern, $string, $registers, $extra_arg) ); + +// Testing ereg with one less than the expected number of arguments +echo "\n-- Testing ereg() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +var_dump( ereg($pattern) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : error conditions *** + +-- Testing ereg() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for ereg() in %s on line 21 +NULL + +-- Testing ereg() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for ereg() in %s on line 26 +NULL +Done diff --git a/ext/standard/tests/reg/ereg_error_002.phpt b/ext/standard/tests/reg/ereg_error_002.phpt new file mode 100644 index 000000000..61166ee97 --- /dev/null +++ b/ext/standard/tests/reg/ereg_error_002.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test ereg() function : error conditions - test bad regular expressions +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test bad regular expressions + */ + +echo "*** Testing ereg() : error conditions ***\n"; + +$regs = 'original'; + +var_dump(ereg("", "hello")); +var_dump(ereg("c(d", "hello")); +var_dump(ereg("a[b", "hello")); +var_dump(ereg("c(d", "hello")); +var_dump(ereg("*", "hello")); +var_dump(ereg("+", "hello")); +var_dump(ereg("?", "hello")); +var_dump(ereg("(+?*)", "hello", $regs)); +var_dump(ereg("h{256}", "hello")); +var_dump(ereg("h|", "hello")); +var_dump(ereg("h{0}", "hello")); +var_dump(ereg("h{2,1}", "hello")); +var_dump(ereg('[a-c-e]', 'd')); +var_dump(ereg('\\', 'x')); +var_dump(ereg('([9-0])', '1', $regs)); + +//ensure $regs unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : error conditions *** + +Warning: ereg(): REG_EMPTY in %s on line 16 +bool(false) + +Warning: ereg(): REG_EPAREN in %s on line 17 +bool(false) + +Warning: ereg(): REG_EBRACK in %s on line 18 +bool(false) + +Warning: ereg(): REG_EPAREN in %s on line 19 +bool(false) + +Warning: ereg(): REG_BADRPT in %s on line 20 +bool(false) + +Warning: ereg(): REG_BADRPT in %s on line 21 +bool(false) + +Warning: ereg(): REG_BADRPT in %s on line 22 +bool(false) + +Warning: ereg(): REG_BADRPT in %s on line 23 +bool(false) + +Warning: ereg(): REG_BADBR in %s on line 24 +bool(false) + +Warning: ereg(): REG_EMPTY in %s on line 25 +bool(false) + +Warning: ereg(): REG_EMPTY in %s on line 26 +bool(false) + +Warning: ereg(): REG_BADBR in %s on line 27 +bool(false) + +Warning: ereg(): REG_ERANGE in %s on line 28 +bool(false) + +Warning: ereg(): REG_EESCAPE in %s on line 29 +bool(false) + +Warning: ereg(): REG_ERANGE in %s on line 30 +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_basic_001.phpt b/ext/standard/tests/reg/ereg_replace_basic_001.phpt new file mode 100644 index 000000000..e0a5dfb7b --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_basic_001.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test ereg_replace() function : basic functionality +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with ereg_replace + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +$replacement = '[this is a replacement]'; + +foreach ($expressions as $re) { + list($pattern, $match) = $re; + echo "--> Pattern: '$pattern'; match: '$match'\n"; + var_dump(ereg_replace($pattern, $replacement, $match . ' this contains some matches ' . $match)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +string(82) "--[this is a replacement]-- this contains some matches --[this is a replacement]--" +--> Pattern: '()'; match: '' +string(695) "[this is a replacement] [this is a replacement]t[this is a replacement]h[this is a replacement]i[this is a replacement]s[this is a replacement] [this is a replacement]c[this is a replacement]o[this is a replacement]n[this is a replacement]t[this is a replacement]a[this is a replacement]i[this is a replacement]n[this is a replacement]s[this is a replacement] [this is a replacement]s[this is a replacement]o[this is a replacement]m[this is a replacement]e[this is a replacement] [this is a replacement]m[this is a replacement]a[this is a replacement]t[this is a replacement]c[this is a replacement]h[this is a replacement]e[this is a replacement]s[this is a replacement] [this is a replacement]" +--> Pattern: '()'; match: 'abcdef' +string(983) "[this is a replacement]a[this is a replacement]b[this is a replacement]c[this is a replacement]d[this is a replacement]e[this is a replacement]f[this is a replacement] [this is a replacement]t[this is a replacement]h[this is a replacement]i[this is a replacement]s[this is a replacement] [this is a replacement]c[this is a replacement]o[this is a replacement]n[this is a replacement]t[this is a replacement]a[this is a replacement]i[this is a replacement]n[this is a replacement]s[this is a replacement] [this is a replacement]s[this is a replacement]o[this is a replacement]m[this is a replacement]e[this is a replacement] [this is a replacement]m[this is a replacement]a[this is a replacement]t[this is a replacement]c[this is a replacement]h[this is a replacement]e[this is a replacement]s[this is a replacement] [this is a replacement]a[this is a replacement]b[this is a replacement]c[this is a replacement]d[this is a replacement]e[this is a replacement]f[this is a replacement]" +--> Pattern: '[x]|[^x]'; match: 'abcdef' +string(920) "[this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement]" +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +string(90) "--- [this is a replacement] --- this contains some matches --- [this is a replacement] ---" +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +string(74) "[this is a replacement] this contains some matches [this is a replacement]" +--> Pattern: '\a'; match: 'a' +string(118) "[this is a replacement] this cont[this is a replacement]ins some m[this is a replacement]tches [this is a replacement]" +--> Pattern: '[0-9][^0-9]'; match: '2a' +string(74) "[this is a replacement] this contains some matches [this is a replacement]" +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +string(152) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ this contains some matches 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +string(66) "[this is a replacement]56789 this contains some matches 0123456789" +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +string(66) "0123456789 this contains some matches 01234[this is a replacement]" +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +string(163) " +[this is a replacement]this[this is a replacement]contains[this is a replacement]some[this is a replacement]matches[this is a replacement] +[this is a replacement]" +--> Pattern: '[[:print:]]{3}'; match: ' a ' +string(254) "[this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement] " +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_basic_002.phpt b/ext/standard/tests/reg/ereg_replace_basic_002.phpt new file mode 100644 index 000000000..4ef9c4109 --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_basic_002.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test ereg_replace() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$replacement = 'r'; + +var_dump(ereg_replace('A', $replacement, 'a')); +var_dump(ereg_replace('[A-Z]', $replacement, '0')); +var_dump(ereg_replace('(a){4}', $replacement, 'aaa')); +var_dump(ereg_replace('^a', $replacement, 'ba')); +var_dump(ereg_replace('b$', $replacement, 'ba')); +var_dump(ereg_replace('[:alpha:]', $replacement, 'x')); + + +echo "Done"; +?> +--EXPECTF-- +string(1) "a" +string(1) "0" +string(3) "aaa" +string(2) "ba" +string(2) "ba" +string(1) "x" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_error_001.phpt b/ext/standard/tests/reg/ereg_replace_error_001.phpt new file mode 100644 index 000000000..e6aedf47e --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test ereg_replace() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing ereg_replace() : error conditions ***\n"; + + +//Test ereg_replace with one more than the expected number of arguments +echo "\n-- Testing ereg_replace() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$replacement = 'string_val'; +$string = 'string_val'; +$extra_arg = 10; +var_dump( ereg_replace($pattern, $replacement, $string, $extra_arg) ); + +// Testing ereg_replace with one less than the expected number of arguments +echo "\n-- Testing ereg_replace() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +$replacement = 'string_val'; +var_dump( ereg_replace($pattern, $replacement) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg_replace() : error conditions *** + +-- Testing ereg_replace() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for ereg_replace() in %s on line 17 +NULL + +-- Testing ereg_replace() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for ereg_replace() in %s on line 23 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_error_002.phpt b/ext/standard/tests/reg/ereg_replace_error_002.phpt new file mode 100644 index 000000000..6e7183c42 --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_error_002.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test ereg_replace() function : error conditions - bad regular expressions +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing ereg_replace() : bad REs ***\n"; +var_dump(ereg_replace("", "hello", "some string")); +var_dump(ereg_replace("c(d", "hello", "some string")); +var_dump(ereg_replace("a[b", "hello", "some string")); +var_dump(ereg_replace("c(d", "hello", "some string"));; +var_dump(ereg_replace("*", "hello", "some string")); +var_dump(ereg_replace("+", "hello", "some string")); +var_dump(ereg_replace("?", "hello", "some string")); +var_dump(ereg_replace("(+?*)", "hello", "some string")); +var_dump(ereg_replace("h{256}", "hello", "some string")); +var_dump(ereg_replace("h|", "hello", "some string")); +var_dump(ereg_replace("h{0}", "hello", "some string")); +var_dump(ereg_replace("h{2,1}", "hello", "some string")); +var_dump(ereg_replace('[a-c-e]', 'd', "some string")); +var_dump(ereg_replace('\\', 'x', "some string")); +var_dump(ereg_replace('([9-0])', '1', "some string")); +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg_replace() : bad REs *** + +Warning: ereg_replace(): REG_EMPTY in %s on line 9 +bool(false) + +Warning: ereg_replace(): REG_EPAREN in %s on line 10 +bool(false) + +Warning: ereg_replace(): REG_EBRACK in %s on line 11 +bool(false) + +Warning: ereg_replace(): REG_EPAREN in %s on line 12 +bool(false) + +Warning: ereg_replace(): REG_BADRPT in %s on line 13 +bool(false) + +Warning: ereg_replace(): REG_BADRPT in %s on line 14 +bool(false) + +Warning: ereg_replace(): REG_BADRPT in %s on line 15 +bool(false) + +Warning: ereg_replace(): REG_BADRPT in %s on line 16 +bool(false) + +Warning: ereg_replace(): REG_BADBR in %s on line 17 +bool(false) + +Warning: ereg_replace(): REG_EMPTY in %s on line 18 +bool(false) + +Warning: ereg_replace(): REG_EMPTY in %s on line 19 +bool(false) + +Warning: ereg_replace(): REG_BADBR in %s on line 20 +bool(false) + +Warning: ereg_replace(): REG_ERANGE in %s on line 21 +bool(false) + +Warning: ereg_replace(): REG_EESCAPE in %s on line 22 +bool(false) + +Warning: ereg_replace(): REG_ERANGE in %s on line 23 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_variation_001.phpt b/ext/standard/tests/reg/ereg_replace_variation_001.phpt new file mode 100644 index 000000000..446ac86e0 --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_variation_001.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test ereg_replace() function : usage variations - unexpected type arg 1 +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing ereg_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$replacement = 'new'; +$string = 'original'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( ereg_replace($value, $replacement, $string) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value 12345 +string(8) "original" + +Arg value -2345 +string(8) "original" + +Arg value 10.5 +string(8) "original" + +Arg value -10.5 +string(8) "original" + +Arg value 101234567000 +string(8) "original" + +Arg value 1.07654321E-9 +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 0.5 +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value Array +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(74) +string(8) "original" + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - ereg_replace(): REG_EMPTY, %s(74) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_variation_002.phpt b/ext/standard/tests/reg/ereg_replace_variation_002.phpt new file mode 100644 index 000000000..bd55dbcde --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_variation_002.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test ereg_replace() function : usage variations - unexpected type arg 2 +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing ereg_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'ell'; +$string = 'hello!'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for replacement + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump(urlencode(ereg_replace($pattern, $value, $string))); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value 12345 +string(6) "h9o%21" + +Arg value -2345 +string(8) "h%D7o%21" + +Arg value 10.5 +string(8) "h%0Ao%21" + +Arg value -10.5 +string(8) "h%F6o%21" + +Arg value 101234567000 +string(%d) "h%so%21" + +Arg value 1.07654321E-9 +string(5) "ho%21" + +Arg value 0.5 +string(5) "ho%21" + +Arg value Array +string(5) "ho%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(74) +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_replace_variation_003.phpt b/ext/standard/tests/reg/ereg_replace_variation_003.phpt new file mode 100644 index 000000000..1d8353599 --- /dev/null +++ b/ext/standard/tests/reg/ereg_replace_variation_003.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test ereg_replace() function : usage variations - unexpected type arg 3 +--FILE-- +<?php +/* Prototype : proto string ereg_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing ereg_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '1'; +$replacement = 'new value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( ereg_replace($pattern, $replacement, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(9) "new value" + +Arg value 12345 +string(13) "new value2345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(12) "new value0.5" + +Arg value -10.5 +string(13) "-new value0.5" + +Arg value 101234567000 +string(28) "new value0new value234567000" + +Arg value 1.07654321E-9 +string(29) "new value.0765432new valueE-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(9) "new value" + +Arg value +string(0) "" + +Arg value 1 +string(9) "new value" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +string(6) "Object" + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_variation_001.phpt b/ext/standard/tests/reg/ereg_variation_001.phpt new file mode 100644 index 000000000..977404d05 --- /dev/null +++ b/ext/standard/tests/reg/ereg_variation_001.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test ereg() function : usage variations - unexpected type arg 1 +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing ereg() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$string = '1'; +$registers = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( ereg($value, $string, $registers) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(65) +Error: 8 - Undefined variable: unset_var, %s(68) + +Arg value 0 +bool(false) + +Arg value 1 +int(1) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value 1 +int(1) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value 1 +int(1) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(75) +Error: 8 - Object of class stdClass to string conversion, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - ereg(): REG_EMPTY, %s(75) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_variation_002.phpt b/ext/standard/tests/reg/ereg_variation_002.phpt new file mode 100644 index 000000000..c5f4e8e01 --- /dev/null +++ b/ext/standard/tests/reg/ereg_variation_002.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test ereg() function : usage variations - unexpected type arg 2 +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing ereg() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '1'; +$registers = array(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( ereg($pattern, $value, $registers) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +bool(false) + +Arg value 1 +int(1) + +Arg value 12345 +int(1) + +Arg value -2345 +bool(false) + +Arg value 10.5 +int(1) + +Arg value -10.5 +int(1) + +Arg value 101234567000 +int(1) + +Arg value 1.07654321E-9 +int(1) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +int(1) + +Arg value +bool(false) + +Arg value 1 +int(1) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_variation_003.phpt b/ext/standard/tests/reg/ereg_variation_003.phpt new file mode 100644 index 000000000..42c1ae1bb --- /dev/null +++ b/ext/standard/tests/reg/ereg_variation_003.phpt @@ -0,0 +1,283 @@ +--TEST-- +Test ereg() function : usage variations - unexpected type for arg 3 +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing ereg() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'h(.*)lo!'; +$string = 'hello!'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for registers + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( ereg($pattern, $string, $value) ); + var_dump($value); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(61) +Error: 8 - Undefined variable: unset_var, %s(64) + +Arg value 0 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 12345 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value -2345 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 10.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value -10.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 101234567000 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1.07654321E-9 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 0.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value string +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value string +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(70) + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/ereg_variation_004.phpt b/ext/standard/tests/reg/ereg_variation_004.phpt new file mode 100644 index 000000000..cbbb3c15e --- /dev/null +++ b/ext/standard/tests/reg/ereg_variation_004.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ereg() function : usage variations - pass non-variable as arg 3, which is pass-by-ref. +--FILE-- +<?php +/* Prototype : proto int ereg(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +var_dump(ereg('l{2}', 'hello', str_repeat('x',1))); +echo "Done"; +?> +--EXPECTF-- + +Strict Standards: Only variables should be passed by reference in %s on line 8 +int(2) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_basic.phpt b/ext/standard/tests/reg/eregi_basic.phpt new file mode 100644 index 000000000..de1db0ed4 --- /dev/null +++ b/ext/standard/tests/reg/eregi_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test eregi() function : basic functionality - confirm case insensitivity +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Case-insensitive regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test basic funtionality of eregi() + */ + +echo "*** Testing eregi() : basic functionality ***\n"; +$string = <<<END +UPPERCASE WORDS +lowercase words +MIxED CaSe woRdS +END; + +var_dump(eregi('words', $string, $match1)); +var_dump($match1); + +var_dump(eregi('[[:lower:]]+[[:space:]]case', $string, $match2)); //character class lower should just match [a-z] but in case insensitive search matches [a-zA-Z] +var_dump($match2); +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : basic functionality *** +int(5) +array(1) { + [0]=> + string(5) "WORDS" +} +int(10) +array(1) { + [0]=> + string(10) "MIxED CaSe" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_basic_001.phpt b/ext/standard/tests/reg/eregi_basic_001.phpt new file mode 100644 index 000000000..8557b8111 --- /dev/null +++ b/ext/standard/tests/reg/eregi_basic_001.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test eregi() function : basic functionality (with $regs) +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with eregi, specifying $regs + */ + +echo "*** Testing eregi() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "--> Pattern: '$pattern'; string: '$string'\n"; + var_dump(eregi($pattern, $string, $regs)); + var_dump($regs); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; string: '--- ab ---' +int(6) +array(3) { + [0]=> + string(6) "- ab -" + [1]=> + string(1) "a" + [2]=> + string(1) "b" +} +--> Pattern: '()'; string: '' +int(1) +array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +--> Pattern: '()'; string: 'abcdef' +int(1) +array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +--> Pattern: '[x]|[^x]'; string: 'abcdef' +int(1) +array(1) { + [0]=> + string(1) "a" +} +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; string: '--- aaa bbb ccc ddd ---' +int(15) +array(6) { + [0]=> + string(15) "aaa bbb ccc ddd" + [1]=> + string(1) "a" + [2]=> + string(2) "aa" + [3]=> + string(3) "bbb" + [4]=> + string(3) "ccc" + [5]=> + string(3) "ddd" +} +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; string: '\`^.[$()|*+?{'' +int(14) +array(1) { + [0]=> + string(14) "\`^.[$()|*+?{'" +} +--> Pattern: '\a'; string: 'a' +int(1) +array(1) { + [0]=> + string(1) "a" +} +--> Pattern: '[0-9][^0-9]'; string: '2a' +int(2) +array(1) { + [0]=> + string(2) "2a" +} +--> Pattern: '^[[:alnum:]]{62,62}$'; string: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +int(62) +array(1) { + [0]=> + string(62) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} +--> Pattern: '^[[:digit:]]{5}'; string: '0123456789' +int(5) +array(1) { + [0]=> + string(5) "01234" +} +--> Pattern: '[[:digit:]]{5}$'; string: '0123456789' +int(5) +array(1) { + [0]=> + string(5) "56789" +} +--> Pattern: '[[:blank:]]{1,10}'; string: ' + ' +int(2) +array(1) { + [0]=> + string(2) " " +} +--> Pattern: '[[:print:]]{3}'; string: ' a ' +int(3) +array(1) { + [0]=> + string(3) " a " +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_basic_002.phpt b/ext/standard/tests/reg/eregi_basic_002.phpt new file mode 100644 index 000000000..8c5d0e471 --- /dev/null +++ b/ext/standard/tests/reg/eregi_basic_002.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test eregi() function : basic functionality (without $regs) +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with eregi, without specifying $regs + */ + +echo "*** Testing eregi() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "--> Pattern: '$pattern'; string: '$string'\n"; + var_dump(eregi($pattern, $string)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; string: '--- ab ---' +int(1) +--> Pattern: '()'; string: '' +int(1) +--> Pattern: '()'; string: 'abcdef' +int(1) +--> Pattern: '[x]|[^x]'; string: 'abcdef' +int(1) +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; string: '--- aaa bbb ccc ddd ---' +int(1) +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; string: '\`^.[$()|*+?{'' +int(1) +--> Pattern: '\a'; string: 'a' +int(1) +--> Pattern: '[0-9][^0-9]'; string: '2a' +int(1) +--> Pattern: '^[[:alnum:]]{62,62}$'; string: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +int(1) +--> Pattern: '^[[:digit:]]{5}'; string: '0123456789' +int(1) +--> Pattern: '[[:digit:]]{5}$'; string: '0123456789' +int(1) +--> Pattern: '[[:blank:]]{1,10}'; string: ' + ' +int(1) +--> Pattern: '[[:print:]]{3}'; string: ' a ' +int(1) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_basic_003.phpt b/ext/standard/tests/reg/eregi_basic_003.phpt new file mode 100644 index 000000000..a4861caa8 --- /dev/null +++ b/ext/standard/tests/reg/eregi_basic_003.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test eregi() function : basic functionality - long RE +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a long RE with lots of matches + */ + +var_dump(eregi(str_repeat('(.)', 2048), str_repeat('x', 2048))); +var_dump(eregi(str_repeat('(.)', 2048), str_repeat('x', 2048), $regs)); +var_dump(count($regs)); + +echo "Done"; +?> +--EXPECTF-- +int(1) +int(2048) +int(2049) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_basic_004.phpt b/ext/standard/tests/reg/eregi_basic_004.phpt new file mode 100644 index 000000000..ad411e21f --- /dev/null +++ b/ext/standard/tests/reg/eregi_basic_004.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test eregi() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$regs = 'original'; + +var_dump(eregi('[A-Z]', '0', $regs)); +var_dump(eregi('(a){4}', 'aaa', $regs)); +var_dump(eregi('^a', 'ba', $regs)); +var_dump(eregi('b$', 'ba', $regs)); +var_dump(eregi('[:alpha:]', 'x', $regs)); + +// Ensure $regs is unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_error_001.phpt b/ext/standard/tests/reg/eregi_error_001.phpt new file mode 100644 index 000000000..a767e24b5 --- /dev/null +++ b/ext/standard/tests/reg/eregi_error_001.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test eregi() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test wrong number of args + */ + +echo "*** Testing eregi() : error conditions ***\n"; + + +//Test eregi with one more than the expected number of arguments +echo "\n-- Testing eregi() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$string = 'string_val'; +$registers = array(1, 2); +$extra_arg = 10; +var_dump( eregi($pattern, $string, $registers, $extra_arg) ); + +// Testing eregi with one less than the expected number of arguments +echo "\n-- Testing eregi() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +var_dump( eregi($pattern) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : error conditions *** + +-- Testing eregi() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for eregi() in %s on line 21 +NULL + +-- Testing eregi() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for eregi() in %s on line 26 +NULL +Done diff --git a/ext/standard/tests/reg/eregi_error_002.phpt b/ext/standard/tests/reg/eregi_error_002.phpt new file mode 100644 index 000000000..3c3bd7c99 --- /dev/null +++ b/ext/standard/tests/reg/eregi_error_002.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test eregi() function : error conditions - test bad regular expressions +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test bad regular expressions + */ + +echo "*** Testing eregi() : error conditions ***\n"; + +$regs = 'original'; + +var_dump(eregi("", "hello")); +var_dump(eregi("c(d", "hello")); +var_dump(eregi("a[b", "hello")); +var_dump(eregi("c(d", "hello")); +var_dump(eregi("*", "hello")); +var_dump(eregi("+", "hello")); +var_dump(eregi("?", "hello")); +var_dump(eregi("(+?*)", "hello", $regs)); +var_dump(eregi("h{256}", "hello")); +var_dump(eregi("h|", "hello")); +var_dump(eregi("h{0}", "hello")); +var_dump(eregi("h{2,1}", "hello")); +var_dump(eregi('[a-c-e]', 'd')); +var_dump(eregi('\\', 'x')); +var_dump(eregi('([9-0])', '1', $regs)); + +//ensure $regs unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : error conditions *** + +Warning: eregi(): REG_EMPTY in %s on line 16 +bool(false) + +Warning: eregi(): REG_EPAREN in %s on line 17 +bool(false) + +Warning: eregi(): REG_EBRACK in %s on line 18 +bool(false) + +Warning: eregi(): REG_EPAREN in %s on line 19 +bool(false) + +Warning: eregi(): REG_BADRPT in %s on line 20 +bool(false) + +Warning: eregi(): REG_BADRPT in %s on line 21 +bool(false) + +Warning: eregi(): REG_BADRPT in %s on line 22 +bool(false) + +Warning: eregi(): REG_BADRPT in %s on line 23 +bool(false) + +Warning: eregi(): REG_BADBR in %s on line 24 +bool(false) + +Warning: eregi(): REG_EMPTY in %s on line 25 +bool(false) + +Warning: eregi(): REG_EMPTY in %s on line 26 +bool(false) + +Warning: eregi(): REG_BADBR in %s on line 27 +bool(false) + +Warning: eregi(): REG_ERANGE in %s on line 28 +bool(false) + +Warning: eregi(): REG_EESCAPE in %s on line 29 +bool(false) + +Warning: eregi(): REG_ERANGE in %s on line 30 +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_basic.phpt b/ext/standard/tests/reg/eregi_replace_basic.phpt new file mode 100644 index 000000000..f9f025fe9 --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test eregi_replace() function : basic functionality - confirm case insensitivity +--FILE-- + +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Case insensitive replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test basic functionality of eregi_replace() + */ + +echo "*** Testing eregi_replace() : basic functionality ***\n"; + +$string = 'UPPERCASE WORDS, lowercase words, MIxED CaSe woRdS'; + +echo "String Before...\n"; +var_dump($string); +echo "\nString after...\n"; + +var_dump(eregi_replace('([[:lower:]]+) word', '\\1_character', $string)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing eregi_replace() : basic functionality *** +String Before... +string(50) "UPPERCASE WORDS, lowercase words, MIxED CaSe woRdS" + +String after... +string(65) "UPPERCASE_characterS, lowercase_characters, MIxED CaSe_characterS" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_basic_001.phpt b/ext/standard/tests/reg/eregi_replace_basic_001.phpt new file mode 100644 index 000000000..bffcd0637 --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_basic_001.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test ereg() function : basic functionality +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple, valid matches with eregi_replace + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +$replacement = '[this is a replacement]'; + +foreach ($expressions as $re) { + list($pattern, $match) = $re; + echo "--> Pattern: '$pattern'; match: '$match'\n"; + var_dump(eregi_replace($pattern, $replacement, $match . ' this contains some matches ' . $match)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +string(82) "--[this is a replacement]-- this contains some matches --[this is a replacement]--" +--> Pattern: '()'; match: '' +string(695) "[this is a replacement] [this is a replacement]t[this is a replacement]h[this is a replacement]i[this is a replacement]s[this is a replacement] [this is a replacement]c[this is a replacement]o[this is a replacement]n[this is a replacement]t[this is a replacement]a[this is a replacement]i[this is a replacement]n[this is a replacement]s[this is a replacement] [this is a replacement]s[this is a replacement]o[this is a replacement]m[this is a replacement]e[this is a replacement] [this is a replacement]m[this is a replacement]a[this is a replacement]t[this is a replacement]c[this is a replacement]h[this is a replacement]e[this is a replacement]s[this is a replacement] [this is a replacement]" +--> Pattern: '()'; match: 'abcdef' +string(983) "[this is a replacement]a[this is a replacement]b[this is a replacement]c[this is a replacement]d[this is a replacement]e[this is a replacement]f[this is a replacement] [this is a replacement]t[this is a replacement]h[this is a replacement]i[this is a replacement]s[this is a replacement] [this is a replacement]c[this is a replacement]o[this is a replacement]n[this is a replacement]t[this is a replacement]a[this is a replacement]i[this is a replacement]n[this is a replacement]s[this is a replacement] [this is a replacement]s[this is a replacement]o[this is a replacement]m[this is a replacement]e[this is a replacement] [this is a replacement]m[this is a replacement]a[this is a replacement]t[this is a replacement]c[this is a replacement]h[this is a replacement]e[this is a replacement]s[this is a replacement] [this is a replacement]a[this is a replacement]b[this is a replacement]c[this is a replacement]d[this is a replacement]e[this is a replacement]f[this is a replacement]" +--> Pattern: '[x]|[^x]'; match: 'abcdef' +string(920) "[this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement]" +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +string(90) "--- [this is a replacement] --- this contains some matches --- [this is a replacement] ---" +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +string(74) "[this is a replacement] this contains some matches [this is a replacement]" +--> Pattern: '\a'; match: 'a' +string(118) "[this is a replacement] this cont[this is a replacement]ins some m[this is a replacement]tches [this is a replacement]" +--> Pattern: '[0-9][^0-9]'; match: '2a' +string(74) "[this is a replacement] this contains some matches [this is a replacement]" +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +string(152) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ this contains some matches 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +string(66) "[this is a replacement]56789 this contains some matches 0123456789" +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +string(66) "0123456789 this contains some matches 01234[this is a replacement]" +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +string(163) " +[this is a replacement]this[this is a replacement]contains[this is a replacement]some[this is a replacement]matches[this is a replacement] +[this is a replacement]" +--> Pattern: '[[:print:]]{3}'; match: ' a ' +string(254) "[this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement][this is a replacement] " +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_basic_002.phpt b/ext/standard/tests/reg/eregi_replace_basic_002.phpt new file mode 100644 index 000000000..7a4bd3d84 --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_basic_002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test eregi_replace() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$replacement = 'r'; + +var_dump(eregi_replace('[A-Z]', $replacement, '0')); +var_dump(eregi_replace('(a){4}', $replacement, 'aaa')); +var_dump(eregi_replace('^a', $replacement, 'ba')); +var_dump(eregi_replace('b$', $replacement, 'ba')); +var_dump(eregi_replace('[:alpha:]', $replacement, 'x')); + + +echo "Done"; +?> +--EXPECTF-- +string(1) "0" +string(3) "aaa" +string(2) "ba" +string(2) "ba" +string(1) "x" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_error_001.phpt b/ext/standard/tests/reg/eregi_replace_error_001.phpt new file mode 100644 index 000000000..8b7f90d9a --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test eregi_replace() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing eregi_replace() : error conditions ***\n"; + + +//Test eregi_replace with one more than the expected number of arguments +echo "\n-- Testing eregi_replace() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$replacement = 'string_val'; +$string = 'string_val'; +$extra_arg = 10; +var_dump( eregi_replace($pattern, $replacement, $string, $extra_arg) ); + +// Testing eregi_replace with one less than the expected number of arguments +echo "\n-- Testing eregi_replace() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +$replacement = 'string_val'; +var_dump( eregi_replace($pattern, $replacement) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi_replace() : error conditions *** + +-- Testing eregi_replace() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for eregi_replace() in %s on line 17 +NULL + +-- Testing eregi_replace() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for eregi_replace() in %s on line 23 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_error_002.phpt b/ext/standard/tests/reg/eregi_replace_error_002.phpt new file mode 100644 index 000000000..35684b8bd --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_error_002.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test eregi_replace() function : error conditions - bad regular expressions +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing eregi_replace() : bad REs ***\n"; +var_dump(eregi_replace("", "hello", "some string")); +var_dump(eregi_replace("c(d", "hello", "some string")); +var_dump(eregi_replace("a[b", "hello", "some string")); +var_dump(eregi_replace("c(d", "hello", "some string"));; +var_dump(eregi_replace("*", "hello", "some string")); +var_dump(eregi_replace("+", "hello", "some string")); +var_dump(eregi_replace("?", "hello", "some string")); +var_dump(eregi_replace("(+?*)", "hello", "some string")); +var_dump(eregi_replace("h{256}", "hello", "some string")); +var_dump(eregi_replace("h|", "hello", "some string")); +var_dump(eregi_replace("h{0}", "hello", "some string")); +var_dump(eregi_replace("h{2,1}", "hello", "some string")); +var_dump(eregi_replace('[a-c-e]', 'd', "some string")); +var_dump(eregi_replace('\\', 'x', "some string")); +var_dump(eregi_replace('([9-0])', '1', "some string")); +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi_replace() : bad REs *** + +Warning: eregi_replace(): REG_EMPTY in %s on line 9 +bool(false) + +Warning: eregi_replace(): REG_EPAREN in %s on line 10 +bool(false) + +Warning: eregi_replace(): REG_EBRACK in %s on line 11 +bool(false) + +Warning: eregi_replace(): REG_EPAREN in %s on line 12 +bool(false) + +Warning: eregi_replace(): REG_BADRPT in %s on line 13 +bool(false) + +Warning: eregi_replace(): REG_BADRPT in %s on line 14 +bool(false) + +Warning: eregi_replace(): REG_BADRPT in %s on line 15 +bool(false) + +Warning: eregi_replace(): REG_BADRPT in %s on line 16 +bool(false) + +Warning: eregi_replace(): REG_BADBR in %s on line 17 +bool(false) + +Warning: eregi_replace(): REG_EMPTY in %s on line 18 +bool(false) + +Warning: eregi_replace(): REG_EMPTY in %s on line 19 +bool(false) + +Warning: eregi_replace(): REG_BADBR in %s on line 20 +bool(false) + +Warning: eregi_replace(): REG_ERANGE in %s on line 21 +bool(false) + +Warning: eregi_replace(): REG_EESCAPE in %s on line 22 +bool(false) + +Warning: eregi_replace(): REG_ERANGE in %s on line 23 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_variation_001.phpt b/ext/standard/tests/reg/eregi_replace_variation_001.phpt new file mode 100644 index 000000000..87f9aa277 --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_variation_001.phpt @@ -0,0 +1,175 @@ +--TEST-- +Test eregi_replace() function : usage variations - unexpected type arg 1 +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing eregi_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$replacement = 'new'; +$string = 'original'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( eregi_replace($value, $replacement, $string) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value 12345 +string(8) "original" + +Arg value -2345 +string(8) "original" + +Arg value 10.5 +string(8) "original" + +Arg value -10.5 +string(8) "original" + +Arg value 101234567000 +string(8) "original" + +Arg value 1.07654321E-9 +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 0.5 +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value Array +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value Array +string(8) "original" + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +string(8) "original" + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(74) +string(8) "original" + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - eregi_replace(): REG_EMPTY, %s(74) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_variation_002.phpt b/ext/standard/tests/reg/eregi_replace_variation_002.phpt new file mode 100644 index 000000000..786de9978 --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_variation_002.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test eregi_replace() function : usage variations - unexpected type arg 2 +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing eregi_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'ell'; +$string = 'hello!'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for replacement + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump(urlencode(eregi_replace($pattern, $value, $string))); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value 12345 +string(6) "h9o%21" + +Arg value -2345 +string(8) "h%D7o%21" + +Arg value 10.5 +string(8) "h%0Ao%21" + +Arg value -10.5 +string(8) "h%F6o%21" + +Arg value 101234567000 +string(%d) "h%so%21" + +Arg value 1.07654321E-9 +string(5) "ho%21" + +Arg value 0.5 +string(5) "ho%21" + +Arg value Array +string(5) "ho%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value Array +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value 1 +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(74) +string(8) "h%01o%21" + +Arg value +string(5) "ho%21" + +Arg value +string(5) "ho%21" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_replace_variation_003.phpt b/ext/standard/tests/reg/eregi_replace_variation_003.phpt new file mode 100644 index 000000000..f4426fd3c --- /dev/null +++ b/ext/standard/tests/reg/eregi_replace_variation_003.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test eregi_replace() function : usage variations - unexpected type arg 3 +--FILE-- +<?php +/* Prototype : proto string eregi_replace(string pattern, string replacement, string string) + * Description: Replace regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing eregi_replace() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '1'; +$replacement = 'new value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( eregi_replace($pattern, $replacement, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi_replace() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(9) "new value" + +Arg value 12345 +string(13) "new value2345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(12) "new value0.5" + +Arg value -10.5 +string(13) "-new value0.5" + +Arg value 101234567000 +string(28) "new value0new value234567000" + +Arg value 1.07654321E-9 +string(29) "new value.0765432new valueE-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +string(5) "Array" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(9) "new value" + +Arg value +string(0) "" + +Arg value 1 +string(9) "new value" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +string(6) "Object" + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_variation_001.phpt b/ext/standard/tests/reg/eregi_variation_001.phpt new file mode 100644 index 000000000..ea8b8440d --- /dev/null +++ b/ext/standard/tests/reg/eregi_variation_001.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test eregi() function : usage variations - unexpected type arg 1 +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + + +echo "*** Testing eregi() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$string = '1'; +$registers = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( eregi($value, $string, $registers) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(65) +Error: 8 - Undefined variable: unset_var, %s(68) + +Arg value 0 +bool(false) + +Arg value 1 +int(1) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value 1 +int(1) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value 1 +int(1) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(75) +Error: 8 - Object of class stdClass to string conversion, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) + +Arg value +Error: 2 - eregi(): REG_EMPTY, %s(75) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_variation_002.phpt b/ext/standard/tests/reg/eregi_variation_002.phpt new file mode 100644 index 000000000..766a48abd --- /dev/null +++ b/ext/standard/tests/reg/eregi_variation_002.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test eregi() function : usage variations - unexpected type arg 2 +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing eregi() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '1'; +$registers = array(); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( eregi($pattern, $value, $registers) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +bool(false) + +Arg value 1 +int(1) + +Arg value 12345 +int(1) + +Arg value -2345 +bool(false) + +Arg value 10.5 +int(1) + +Arg value -10.5 +int(1) + +Arg value 101234567000 +int(1) + +Arg value 1.07654321E-9 +int(1) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value 1 +int(1) + +Arg value +bool(false) + +Arg value 1 +int(1) + +Arg value +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +bool(false) + +Arg value +bool(false) + +Arg value +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_variation_003.phpt b/ext/standard/tests/reg/eregi_variation_003.phpt new file mode 100644 index 000000000..43785871a --- /dev/null +++ b/ext/standard/tests/reg/eregi_variation_003.phpt @@ -0,0 +1,283 @@ +--TEST-- +Test eregi() function : usage variations - unexpected type for arg 3 +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing eregi() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'h(.*)lo!'; +$string = 'hello!'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for registers + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( eregi($pattern, $string, $value) ); + var_dump($value); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing eregi() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(61) +Error: 8 - Undefined variable: unset_var, %s(64) + +Arg value 0 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 12345 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value -2345 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 10.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value -10.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 101234567000 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1.07654321E-9 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 0.5 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value 1 +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value string +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value string +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(70) + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} + +Arg value +int(6) +array(2) { + [0]=> + string(6) "hello!" + [1]=> + string(2) "el" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/eregi_variation_004.phpt b/ext/standard/tests/reg/eregi_variation_004.phpt new file mode 100644 index 000000000..bf4f03695 --- /dev/null +++ b/ext/standard/tests/reg/eregi_variation_004.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test eregi() function : usage variations - pass non-variable as arg 3, which is pass-by-ref. +--FILE-- +<?php +/* Prototype : proto int eregi(string pattern, string string [, array registers]) + * Description: Regular expression match + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +var_dump(eregi('l{2}', 'hello', str_repeat('x',1))); +echo "Done"; +?> +--EXPECTF-- + +Strict Standards: Only variables should be passed by reference in %s on line 8 +int(2) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/regular_expressions.inc b/ext/standard/tests/reg/regular_expressions.inc new file mode 100644 index 000000000..98fae4b11 --- /dev/null +++ b/ext/standard/tests/reg/regular_expressions.inc @@ -0,0 +1,24 @@ +<?php + +/** + * POSIX regular expressions each coupled with a string that they match, + * based on documentation on http://www.tin.org/bin/man.cgi?section=7&topic=regex . + */ +$expressions = array( + //array(pattern, string to match) + array('..(a|b|c)(a|b|c)..', '--- ab ---'), + array('()', ''), + array('()', 'abcdef'), + array('[x]|[^x]', 'abcdef'), + array('(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)', '--- aaa bbb ccc ddd ---'), + array('\\\\\`\^\.\[\$\(\)\|\*\+\?\{\\\'', '\\`^.[$()|*+?{\''), + array('\\a', 'a'), + array('[0-9][^0-9]', '2a'), + array('^[[:alnum:]]{62,62}$', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), + array('^[[:digit:]]{5}', '0123456789'), + array('[[:digit:]]{5}$', '0123456789'), + array('[[:blank:]]{1,10}', "\n \t"), + array('[[:print:]]{3}', " a "), +); + +?>
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_basic_001.phpt b/ext/standard/tests/reg/split_basic_001.phpt new file mode 100644 index 000000000..e122e2c15 --- /dev/null +++ b/ext/standard/tests/reg/split_basic_001.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test split() function : basic functionality - test a number of simple split, specifying a limit +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple split, specifying a limit + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "\n--> Pattern: '$pattern'; match: '$string'\n"; + var_dump(split($pattern, $string . ' |1| ' . $string . ' |2| ' . $string, 2)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** + +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +array(2) { + [0]=> + string(2) "--" + [1]=> + string(32) "-- |1| --- ab --- |2| --- ab ---" +} + +--> Pattern: '()'; match: '' + +Warning: split(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '()'; match: 'abcdef' + +Warning: split(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '[x]|[^x]'; match: 'abcdef' +array(2) { + [0]=> + string(0) "" + [1]=> + string(27) "bcdef |1| abcdef |2| abcdef" +} + +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(60) " --- |1| --- aaa bbb ccc ddd --- |2| --- aaa bbb ccc ddd ---" +} + +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +array(2) { + [0]=> + string(0) "" + [1]=> + string(38) " |1| \`^.[$()|*+?{' |2| \`^.[$()|*+?{'" +} + +--> Pattern: '\a'; match: 'a' +array(2) { + [0]=> + string(0) "" + [1]=> + string(12) " |1| a |2| a" +} + +--> Pattern: '[0-9][^0-9]'; match: '2a' +array(2) { + [0]=> + string(0) "" + [1]=> + string(14) " |1| 2a |2| 2a" +} + +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +array(1) { + [0]=> + string(196) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |1| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |2| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +array(2) { + [0]=> + string(0) "" + [1]=> + string(35) "56789 |1| 0123456789 |2| 0123456789" +} + +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +array(2) { + [0]=> + string(35) "0123456789 |1| 0123456789 |2| 01234" + [1]=> + string(0) "" +} + +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +array(2) { + [0]=> + string(1) " +" + [1]=> + string(15) "|1| + |2| + " +} + +--> Pattern: '[[:print:]]{3}'; match: ' a ' +array(2) { + [0]=> + string(0) "" + [1]=> + string(16) " |1| a |2| a " +} +Done diff --git a/ext/standard/tests/reg/split_basic_002.phpt b/ext/standard/tests/reg/split_basic_002.phpt new file mode 100644 index 000000000..110007d3e --- /dev/null +++ b/ext/standard/tests/reg/split_basic_002.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test split() function : basic functionality - test a number of simple split, without specifying a limit +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple split, without specifying a limit + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "\n--> Pattern: '$pattern'; match: '$string'\n"; + var_dump(split($pattern, $string . ' |1| ' . $string . ' |2| ' . $string)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** + +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +array(4) { + [0]=> + string(2) "--" + [1]=> + string(9) "-- |1| --" + [2]=> + string(9) "-- |2| --" + [3]=> + string(2) "--" +} + +--> Pattern: '()'; match: '' + +Warning: split(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '()'; match: 'abcdef' + +Warning: split(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '[x]|[^x]'; match: 'abcdef' +array(29) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(0) "" + [8]=> + string(0) "" + [9]=> + string(0) "" + [10]=> + string(0) "" + [11]=> + string(0) "" + [12]=> + string(0) "" + [13]=> + string(0) "" + [14]=> + string(0) "" + [15]=> + string(0) "" + [16]=> + string(0) "" + [17]=> + string(0) "" + [18]=> + string(0) "" + [19]=> + string(0) "" + [20]=> + string(0) "" + [21]=> + string(0) "" + [22]=> + string(0) "" + [23]=> + string(0) "" + [24]=> + string(0) "" + [25]=> + string(0) "" + [26]=> + string(0) "" + [27]=> + string(0) "" + [28]=> + string(0) "" +} + +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +array(4) { + [0]=> + string(4) "--- " + [1]=> + string(13) " --- |1| --- " + [2]=> + string(13) " --- |2| --- " + [3]=> + string(4) " ---" +} + +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +array(4) { + [0]=> + string(0) "" + [1]=> + string(5) " |1| " + [2]=> + string(5) " |2| " + [3]=> + string(0) "" +} + +--> Pattern: '\a'; match: 'a' +array(4) { + [0]=> + string(0) "" + [1]=> + string(5) " |1| " + [2]=> + string(5) " |2| " + [3]=> + string(0) "" +} + +--> Pattern: '[0-9][^0-9]'; match: '2a' +array(6) { + [0]=> + string(0) "" + [1]=> + string(2) " |" + [2]=> + string(1) " " + [3]=> + string(2) " |" + [4]=> + string(1) " " + [5]=> + string(0) "" +} + +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +array(1) { + [0]=> + string(196) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |1| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |2| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +array(3) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(30) " |1| 0123456789 |2| 0123456789" +} + +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +array(2) { + [0]=> + string(35) "0123456789 |1| 0123456789 |2| 01234" + [1]=> + string(0) "" +} + +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +array(6) { + [0]=> + string(1) " +" + [1]=> + string(3) "|1|" + [2]=> + string(1) " +" + [3]=> + string(3) "|2|" + [4]=> + string(1) " +" + [5]=> + string(0) "" +} + +--> Pattern: '[[:print:]]{3}'; match: ' a ' +array(7) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(1) " " +} +Done diff --git a/ext/standard/tests/reg/split_basic_003.phpt b/ext/standard/tests/reg/split_basic_003.phpt new file mode 100644 index 000000000..4d36fcddb --- /dev/null +++ b/ext/standard/tests/reg/split_basic_003.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test split() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$replacement = 'r'; + +var_dump(split('A', '-- a --')); +var_dump(split('[A-Z]', '-- 0 --')); +var_dump(split('(a){4}', '--- aaa ---')); +var_dump(split('^a', '--- ba ---')); +var_dump(split('b$', '--- ba ---')); +var_dump(split('[:alpha:]', '--- x ---')); + + +echo "Done"; +?> +--EXPECTF-- +array(1) { + [0]=> + string(7) "-- a --" +} +array(1) { + [0]=> + string(7) "-- 0 --" +} +array(1) { + [0]=> + string(11) "--- aaa ---" +} +array(1) { + [0]=> + string(10) "--- ba ---" +} +array(1) { + [0]=> + string(10) "--- ba ---" +} +array(1) { + [0]=> + string(9) "--- x ---" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_error_001.phpt b/ext/standard/tests/reg/split_error_001.phpt new file mode 100644 index 000000000..ff8e6cbdd --- /dev/null +++ b/ext/standard/tests/reg/split_error_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test split() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing split() : error conditions - wrong number of args ***\n"; + + +//Test split with one more than the expected number of arguments +echo "\n-- Testing split() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$string = 'string_val'; +$limit = 10; +$extra_arg = 10; +var_dump( split($pattern, $string, $limit, $extra_arg) ); + +// Testing split with one less than the expected number of arguments +echo "\n-- Testing split() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +var_dump( split($pattern) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : error conditions - wrong number of args *** + +-- Testing split() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for split() in %s on line 17 +NULL + +-- Testing split() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for split() in %s on line 22 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_error_002.phpt b/ext/standard/tests/reg/split_error_002.phpt new file mode 100644 index 000000000..8c4ce345d --- /dev/null +++ b/ext/standard/tests/reg/split_error_002.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test split() function : error conditions - test bad regular expressions +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test bad regular expressions + */ + +echo "*** Testing split() : error conditions ***\n"; + +$regs = 'original'; + +var_dump(split("", "hello")); +var_dump(split("c(d", "hello")); +var_dump(split("a[b", "hello")); +var_dump(split("c(d", "hello")); +var_dump(split("*", "hello")); +var_dump(split("+", "hello")); +var_dump(split("?", "hello")); +var_dump(split("(+?*)", "hello", $regs)); +var_dump(split("h{256}", "hello")); +var_dump(split("h|", "hello")); +var_dump(split("h{0}", "hello")); +var_dump(split("h{2,1}", "hello")); +var_dump(split('[a-c-e]', 'd')); +var_dump(split('\\', 'x')); +var_dump(split('([9-0])', '1', $regs)); + +//ensure $regs unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : error conditions *** + +Warning: split(): REG_EMPTY in %s on line 16 +bool(false) + +Warning: split(): REG_EPAREN in %s on line 17 +bool(false) + +Warning: split(): REG_EBRACK in %s on line 18 +bool(false) + +Warning: split(): REG_EPAREN in %s on line 19 +bool(false) + +Warning: split(): REG_BADRPT in %s on line 20 +bool(false) + +Warning: split(): REG_BADRPT in %s on line 21 +bool(false) + +Warning: split(): REG_BADRPT in %s on line 22 +bool(false) + +Warning: split(): REG_BADRPT in %s on line 23 +bool(false) + +Warning: split(): REG_BADBR in %s on line 24 +bool(false) + +Warning: split(): REG_EMPTY in %s on line 25 +bool(false) + +Warning: split(): REG_EMPTY in %s on line 26 +bool(false) + +Warning: split(): REG_BADBR in %s on line 27 +bool(false) + +Warning: split(): REG_ERANGE in %s on line 28 +bool(false) + +Warning: split(): REG_EESCAPE in %s on line 29 +bool(false) + +Warning: split(): REG_ERANGE in %s on line 30 +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_variation_001.phpt b/ext/standard/tests/reg/split_variation_001.phpt new file mode 100644 index 000000000..625bf0625 --- /dev/null +++ b/ext/standard/tests/reg/split_variation_001.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test split() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing split() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$string = '1 a 1 Array 1 c '; +$limit = 5; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( split($value, $string, $limit) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value 12345 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value -2345 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 10.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value -10.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 101234567000 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 1.07654321E-9 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 0.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - split(): REG_EMPTY, %s(74) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_variation_002.phpt b/ext/standard/tests/reg/split_variation_002.phpt new file mode 100644 index 000000000..d7fa8445b --- /dev/null +++ b/ext/standard/tests/reg/split_variation_002.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test split() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing split() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'r|j|E'; +$limit = 5; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( split($pattern, $value, $limit) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +array(1) { + [0]=> + string(1) "0" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value 12345 +array(1) { + [0]=> + string(5) "12345" +} + +Arg value -2345 +array(1) { + [0]=> + string(5) "-2345" +} + +Arg value 10.5 +array(1) { + [0]=> + string(4) "10.5" +} + +Arg value -10.5 +array(1) { + [0]=> + string(5) "-10.5" +} + +Arg value 101234567000 +array(1) { + [0]=> + string(12) "101234567000" +} + +Arg value 1.07654321E-9 +array(2) { + [0]=> + string(10) "1.07654321" + [1]=> + string(2) "-9" +} + +Arg value 0.5 +array(1) { + [0]=> + string(3) "0.5" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +array(2) { + [0]=> + string(2) "Ob" + [1]=> + string(3) "ect" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} +Done diff --git a/ext/standard/tests/reg/split_variation_003.phpt b/ext/standard/tests/reg/split_variation_003.phpt new file mode 100644 index 000000000..7686c0886 --- /dev/null +++ b/ext/standard/tests/reg/split_variation_003.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test split() function : usage variations - unexpected type for arg 3 +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); +echo "*** Testing split() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '[[:space:]]'; +$string = '1 2 3 4 5'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, +); + +// loop through each element of the array for limit + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( split($pattern, $string, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : usage variations *** + +Arg value 10.5 +array(5) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "4" + [4]=> + string(1) "5" +} + +Arg value -10.5 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1.07654321E-9 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 0.5 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value string +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value string +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(72) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(73) +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/split_variation_004.phpt b/ext/standard/tests/reg/split_variation_004.phpt new file mode 100644 index 000000000..537070908 --- /dev/null +++ b/ext/standard/tests/reg/split_variation_004.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test split() function : usage variations - out-of-range values for limit +--FILE-- +<?php +/* Prototype : proto array split(string pattern, string string [, int limit]) + * Description: Split string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); +echo "*** Testing split() : usage variations ***\n"; + +$pattern = '[[:space:]]'; +$string = '1 2 3 4 5'; +var_dump(split($pattern, $string, 0)); +var_dump(split($pattern, $string, -10)); +var_dump(split($pattern, $string, 10E20)); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing split() : usage variations *** +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_basic_001.phpt b/ext/standard/tests/reg/spliti_basic_001.phpt new file mode 100644 index 000000000..04f138d4e --- /dev/null +++ b/ext/standard/tests/reg/spliti_basic_001.phpt @@ -0,0 +1,129 @@ +--TEST-- +Test spliti() function : basic functionality - test a number of simple spliti, specifying a limit +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple spliti, specifying a limit + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "\n--> Pattern: '$pattern'; match: '$string'\n"; + var_dump(spliti($pattern, $string . ' |1| ' . $string . ' |2| ' . $string, 2)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** + +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +array(2) { + [0]=> + string(2) "--" + [1]=> + string(32) "-- |1| --- ab --- |2| --- ab ---" +} + +--> Pattern: '()'; match: '' + +Warning: spliti(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '()'; match: 'abcdef' + +Warning: spliti(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '[x]|[^x]'; match: 'abcdef' +array(2) { + [0]=> + string(0) "" + [1]=> + string(27) "bcdef |1| abcdef |2| abcdef" +} + +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(60) " --- |1| --- aaa bbb ccc ddd --- |2| --- aaa bbb ccc ddd ---" +} + +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +array(2) { + [0]=> + string(0) "" + [1]=> + string(38) " |1| \`^.[$()|*+?{' |2| \`^.[$()|*+?{'" +} + +--> Pattern: '\a'; match: 'a' +array(2) { + [0]=> + string(0) "" + [1]=> + string(12) " |1| a |2| a" +} + +--> Pattern: '[0-9][^0-9]'; match: '2a' +array(2) { + [0]=> + string(0) "" + [1]=> + string(14) " |1| 2a |2| 2a" +} + +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +array(1) { + [0]=> + string(196) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |1| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |2| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +array(2) { + [0]=> + string(0) "" + [1]=> + string(35) "56789 |1| 0123456789 |2| 0123456789" +} + +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +array(2) { + [0]=> + string(35) "0123456789 |1| 0123456789 |2| 01234" + [1]=> + string(0) "" +} + +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +array(2) { + [0]=> + string(1) " +" + [1]=> + string(15) "|1| + |2| + " +} + +--> Pattern: '[[:print:]]{3}'; match: ' a ' +array(2) { + [0]=> + string(0) "" + [1]=> + string(16) " |1| a |2| a " +} +Done diff --git a/ext/standard/tests/reg/spliti_basic_002.phpt b/ext/standard/tests/reg/spliti_basic_002.phpt new file mode 100644 index 000000000..79784d324 --- /dev/null +++ b/ext/standard/tests/reg/spliti_basic_002.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test spliti() function : basic functionality - test a number of simple spliti, without specifying a limit +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test a number of simple spliti, without specifying a limit + */ + +echo "*** Testing ereg() : basic functionality ***\n"; + +include(dirname(__FILE__) . '/regular_expressions.inc'); + +foreach ($expressions as $re) { + list($pattern,$string) = $re; + echo "\n--> Pattern: '$pattern'; match: '$string'\n"; + var_dump(spliti($pattern, $string . ' |1| ' . $string . ' |2| ' . $string)); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ereg() : basic functionality *** + +--> Pattern: '..(a|b|c)(a|b|c)..'; match: '--- ab ---' +array(4) { + [0]=> + string(2) "--" + [1]=> + string(9) "-- |1| --" + [2]=> + string(9) "-- |2| --" + [3]=> + string(2) "--" +} + +--> Pattern: '()'; match: '' + +Warning: spliti(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '()'; match: 'abcdef' + +Warning: spliti(): Invalid Regular Expression in %s on line 19 +bool(false) + +--> Pattern: '[x]|[^x]'; match: 'abcdef' +array(29) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(0) "" + [7]=> + string(0) "" + [8]=> + string(0) "" + [9]=> + string(0) "" + [10]=> + string(0) "" + [11]=> + string(0) "" + [12]=> + string(0) "" + [13]=> + string(0) "" + [14]=> + string(0) "" + [15]=> + string(0) "" + [16]=> + string(0) "" + [17]=> + string(0) "" + [18]=> + string(0) "" + [19]=> + string(0) "" + [20]=> + string(0) "" + [21]=> + string(0) "" + [22]=> + string(0) "" + [23]=> + string(0) "" + [24]=> + string(0) "" + [25]=> + string(0) "" + [26]=> + string(0) "" + [27]=> + string(0) "" + [28]=> + string(0) "" +} + +--> Pattern: '(a{1})(a{1,}) (b{1,3}) (c+) (d?ddd|e)'; match: '--- aaa bbb ccc ddd ---' +array(4) { + [0]=> + string(4) "--- " + [1]=> + string(13) " --- |1| --- " + [2]=> + string(13) " --- |2| --- " + [3]=> + string(4) " ---" +} + +--> Pattern: '\\\`\^\.\[\$\(\)\|\*\+\?\{\''; match: '\`^.[$()|*+?{'' +array(4) { + [0]=> + string(0) "" + [1]=> + string(5) " |1| " + [2]=> + string(5) " |2| " + [3]=> + string(0) "" +} + +--> Pattern: '\a'; match: 'a' +array(4) { + [0]=> + string(0) "" + [1]=> + string(5) " |1| " + [2]=> + string(5) " |2| " + [3]=> + string(0) "" +} + +--> Pattern: '[0-9][^0-9]'; match: '2a' +array(6) { + [0]=> + string(0) "" + [1]=> + string(2) " |" + [2]=> + string(1) " " + [3]=> + string(2) " |" + [4]=> + string(1) " " + [5]=> + string(0) "" +} + +--> Pattern: '^[[:alnum:]]{62,62}$'; match: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +array(1) { + [0]=> + string(196) "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |1| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ |2| 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + +--> Pattern: '^[[:digit:]]{5}'; match: '0123456789' +array(3) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(30) " |1| 0123456789 |2| 0123456789" +} + +--> Pattern: '[[:digit:]]{5}$'; match: '0123456789' +array(2) { + [0]=> + string(35) "0123456789 |1| 0123456789 |2| 01234" + [1]=> + string(0) "" +} + +--> Pattern: '[[:blank:]]{1,10}'; match: ' + ' +array(6) { + [0]=> + string(1) " +" + [1]=> + string(3) "|1|" + [2]=> + string(1) " +" + [3]=> + string(3) "|2|" + [4]=> + string(1) " +" + [5]=> + string(0) "" +} + +--> Pattern: '[[:print:]]{3}'; match: ' a ' +array(7) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + string(0) "" + [6]=> + string(1) " " +} +Done diff --git a/ext/standard/tests/reg/spliti_basic_003.phpt b/ext/standard/tests/reg/spliti_basic_003.phpt new file mode 100644 index 000000000..143f1a196 --- /dev/null +++ b/ext/standard/tests/reg/spliti_basic_003.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test spliti() function : basic functionality - a few non-matches +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$replacement = 'r'; + +var_dump(spliti('[A-Z]', '-- 0 --')); +var_dump(spliti('(a){4}', '--- aaa ---')); +var_dump(spliti('^a', '--- ba ---')); +var_dump(spliti('b$', '--- ba ---')); +var_dump(spliti('[:alpha:]', '--- x ---')); + + +echo "Done"; +?> +--EXPECTF-- +array(1) { + [0]=> + string(7) "-- 0 --" +} +array(1) { + [0]=> + string(11) "--- aaa ---" +} +array(1) { + [0]=> + string(10) "--- ba ---" +} +array(1) { + [0]=> + string(10) "--- ba ---" +} +array(1) { + [0]=> + string(9) "--- x ---" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_basic_004.phpt b/ext/standard/tests/reg/spliti_basic_004.phpt new file mode 100644 index 000000000..95edc158d --- /dev/null +++ b/ext/standard/tests/reg/spliti_basic_004.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test spliti() function : basic functionality - confirm case insensitivity +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +$replacement = 'r'; + +var_dump(spliti('[a-z]', '--- A ---')); +var_dump(spliti('[A-Z]', '--- a ---')); +var_dump(spliti('[[:lower:]]', '--- A ---')); +var_dump(spliti('[[:upper:]]', '--- a ---')); + +echo "Done"; +?> +--EXPECTF-- +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(4) " ---" +} +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(4) " ---" +} +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(4) " ---" +} +array(2) { + [0]=> + string(4) "--- " + [1]=> + string(4) " ---" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_error_001.phpt b/ext/standard/tests/reg/spliti_error_001.phpt new file mode 100644 index 000000000..44d2be618 --- /dev/null +++ b/ext/standard/tests/reg/spliti_error_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test spliti() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +echo "*** Testing spliti() : error conditions - wrong number of args ***\n"; + + +//Test spliti with one more than the expected number of arguments +echo "\n-- Testing spliti() function with more than expected no. of arguments --\n"; +$pattern = 'string_val'; +$string = 'string_val'; +$limit = 10; +$extra_arg = 10; +var_dump( spliti($pattern, $string, $limit, $extra_arg) ); + +// Testing spliti with one less than the expected number of arguments +echo "\n-- Testing spliti() function with less than expected no. of arguments --\n"; +$pattern = 'string_val'; +var_dump( spliti($pattern) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : error conditions - wrong number of args *** + +-- Testing spliti() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for spliti() in %s on line 17 +NULL + +-- Testing spliti() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for spliti() in %s on line 22 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_error_002.phpt b/ext/standard/tests/reg/spliti_error_002.phpt new file mode 100644 index 000000000..030fb2b24 --- /dev/null +++ b/ext/standard/tests/reg/spliti_error_002.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test spliti() function : error conditions - test bad regular expressions +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +/* + * Test bad regular expressions + */ + +echo "*** Testing spliti() : error conditions ***\n"; + +$regs = 'original'; + +var_dump(spliti("", "hello")); +var_dump(spliti("c(d", "hello")); +var_dump(spliti("a[b", "hello")); +var_dump(spliti("c(d", "hello")); +var_dump(spliti("*", "hello")); +var_dump(spliti("+", "hello")); +var_dump(spliti("?", "hello")); +var_dump(spliti("(+?*)", "hello", $regs)); +var_dump(spliti("h{256}", "hello")); +var_dump(spliti("h|", "hello")); +var_dump(spliti("h{0}", "hello")); +var_dump(spliti("h{2,1}", "hello")); +var_dump(spliti('[a-c-e]', 'd')); +var_dump(spliti('\\', 'x')); +var_dump(spliti('([9-0])', '1', $regs)); + +//ensure $regs unchanged +var_dump($regs); + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : error conditions *** + +Warning: spliti(): REG_EMPTY in %s on line 16 +bool(false) + +Warning: spliti(): REG_EPAREN in %s on line 17 +bool(false) + +Warning: spliti(): REG_EBRACK in %s on line 18 +bool(false) + +Warning: spliti(): REG_EPAREN in %s on line 19 +bool(false) + +Warning: spliti(): REG_BADRPT in %s on line 20 +bool(false) + +Warning: spliti(): REG_BADRPT in %s on line 21 +bool(false) + +Warning: spliti(): REG_BADRPT in %s on line 22 +bool(false) + +Warning: spliti(): REG_BADRPT in %s on line 23 +bool(false) + +Warning: spliti(): REG_BADBR in %s on line 24 +bool(false) + +Warning: spliti(): REG_EMPTY in %s on line 25 +bool(false) + +Warning: spliti(): REG_EMPTY in %s on line 26 +bool(false) + +Warning: spliti(): REG_BADBR in %s on line 27 +bool(false) + +Warning: spliti(): REG_ERANGE in %s on line 28 +bool(false) + +Warning: spliti(): REG_EESCAPE in %s on line 29 +bool(false) + +Warning: spliti(): REG_ERANGE in %s on line 30 +bool(false) +string(8) "original" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_variation_001.phpt b/ext/standard/tests/reg/spliti_variation_001.phpt new file mode 100644 index 000000000..b9b15b589 --- /dev/null +++ b/ext/standard/tests/reg/spliti_variation_001.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test spliti() function : usage variations - unexpected type for arg 1 +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing spliti() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$string = '1 a 1 Array 1 c '; +$limit = 5; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for pattern + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( spliti($value, $string, $limit) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value 12345 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value -2345 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 10.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value -10.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 101234567000 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 1.07654321E-9 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value 0.5 +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(2) { + [0]=> + string(6) "1 a 1 " + [1]=> + string(5) " 1 c " +} + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value 1 +array(4) { + [0]=> + string(0) "" + [1]=> + string(3) " a " + [2]=> + string(7) " Array " + [3]=> + string(3) " c " +} + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +array(1) { + [0]=> + string(16) "1 a 1 Array 1 c " +} + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) + +Arg value +Error: 2 - spliti(): REG_EMPTY, %s(74) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_variation_002.phpt b/ext/standard/tests/reg/spliti_variation_002.phpt new file mode 100644 index 000000000..a1e51bdb6 --- /dev/null +++ b/ext/standard/tests/reg/spliti_variation_002.phpt @@ -0,0 +1,270 @@ +--TEST-- +Test spliti() function : usage variations - unexpected type for arg 2 +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing spliti() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = 'r|j|E'; +$limit = 5; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( spliti($pattern, $value, $limit) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +array(1) { + [0]=> + string(1) "0" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value 12345 +array(1) { + [0]=> + string(5) "12345" +} + +Arg value -2345 +array(1) { + [0]=> + string(5) "-2345" +} + +Arg value 10.5 +array(1) { + [0]=> + string(4) "10.5" +} + +Arg value -10.5 +array(1) { + [0]=> + string(5) "-10.5" +} + +Arg value 101234567000 +array(1) { + [0]=> + string(12) "101234567000" +} + +Arg value 1.07654321E-9 +array(2) { + [0]=> + string(10) "1.07654321" + [1]=> + string(2) "-9" +} + +Arg value 0.5 +array(1) { + [0]=> + string(3) "0.5" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value Array +Error: 8 - Array to string conversion, %s(74) +array(3) { + [0]=> + string(1) "A" + [1]=> + string(0) "" + [2]=> + string(2) "ay" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value 1 +array(1) { + [0]=> + string(1) "1" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(74) +Error: 8 - Object of class stdClass to string conversion, %s(74) +array(3) { + [0]=> + string(2) "Ob" + [1]=> + string(0) "" + [2]=> + string(2) "ct" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} + +Arg value +array(1) { + [0]=> + string(0) "" +} +Done diff --git a/ext/standard/tests/reg/spliti_variation_003.phpt b/ext/standard/tests/reg/spliti_variation_003.phpt new file mode 100644 index 000000000..e6c8f10b5 --- /dev/null +++ b/ext/standard/tests/reg/spliti_variation_003.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test spliti() function : usage variations - unexpected type for arg 3 +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); +echo "*** Testing spliti() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$pattern = '[[:space:]]'; +$string = '1 2 3 4 5'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, +); + +// loop through each element of the array for limit + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( spliti($pattern, $string, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : usage variations *** + +Arg value 10.5 +array(5) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "4" + [4]=> + string(1) "5" +} + +Arg value -10.5 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1.07654321E-9 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 0.5 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value Array +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value 1 +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value string +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value string +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(72) + +Arg value +Error: 8 - Object of class stdClass could not be converted to int, %s(73) +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} + +Arg value +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/spliti_variation_004.phpt b/ext/standard/tests/reg/spliti_variation_004.phpt new file mode 100644 index 000000000..e6c8e3c21 --- /dev/null +++ b/ext/standard/tests/reg/spliti_variation_004.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test spliti() function : usage variations - out-of-range values for limit +--FILE-- +<?php +/* Prototype : proto array spliti(string pattern, string string [, int limit]) + * Description: spliti string into array by regular expression + * Source code: ext/standard/reg.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); +echo "*** Testing spliti() : usage variations ***\n"; + +$pattern = '[[:space:]]'; +$string = '1 2 3 4 5'; +var_dump(spliti($pattern, $string, 0)); +var_dump(spliti($pattern, $string, -10)); +var_dump(spliti($pattern, $string, 10E20)); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing spliti() : usage variations *** +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +array(1) { + [0]=> + string(9) "1 2 3 4 5" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/sql_regcase_basic_001.phpt b/ext/standard/tests/reg/sql_regcase_basic_001.phpt new file mode 100644 index 000000000..7657fa28c --- /dev/null +++ b/ext/standard/tests/reg/sql_regcase_basic_001.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test sql_regcase() function : basic functionality +--FILE-- +<?php +/* Prototype : proto string sql_regcase(string string) + * Description: Make regular expression for case insensitive match + * Source code: ext/standard/reg.c + * Alias to functions: msql_regcase + */ + +echo "*** Testing sql_regcase() : basic functionality ***\n"; + + +// Initialise all required variables +$string = 'string_Val-0'; + +// Calling sql_regcase() with all possible arguments +var_dump( sql_regcase($string) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sql_regcase() : basic functionality *** +string(39) "[Ss][Tt][Rr][Ii][Nn][Gg]_[Vv][Aa][Ll]-0" +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/sql_regcase_error_001.phpt b/ext/standard/tests/reg/sql_regcase_error_001.phpt new file mode 100644 index 000000000..3ab9fd8db --- /dev/null +++ b/ext/standard/tests/reg/sql_regcase_error_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test sql_regcase() function : error conditions +--FILE-- +<?php +/* Prototype : proto string sql_regcase(string string) + * Description: Make regular expression for case insensitive match + * Source code: ext/standard/reg.c + * Alias to functions: msql_regcase + */ + +echo "*** Testing sql_regcase() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing sql_regcase() function with Zero arguments --\n"; +var_dump( sql_regcase() ); + +//Test sql_regcase with one more than the expected number of arguments +echo "\n-- Testing sql_regcase() function with more than expected no. of arguments --\n"; +$string = 'string_val'; +$extra_arg = 10; +var_dump( sql_regcase($string, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sql_regcase() : error conditions *** + +-- Testing sql_regcase() function with Zero arguments -- + +Warning: Wrong parameter count for sql_regcase() in %s on line 12 +NULL + +-- Testing sql_regcase() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for sql_regcase() in %s on line 18 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/reg/sql_regcase_variation_001.phpt b/ext/standard/tests/reg/sql_regcase_variation_001.phpt new file mode 100644 index 000000000..ed0bef06d --- /dev/null +++ b/ext/standard/tests/reg/sql_regcase_variation_001.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test sql_regcase() function : usage variations - unexpected arg type +--FILE-- +<?php +/* Prototype : proto string sql_regcase(string string) + * Description: Make regular expression for case insensitive match + * Source code: ext/standard/reg.c + * Alias to functions: msql_regcase + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing sql_regcase() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for string + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( sql_regcase($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing sql_regcase() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(62) +Error: 8 - Undefined variable: unset_var, %s(65) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(16) "1.07654321[Ee]-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 8 - Array to string conversion, %s(72) +string(20) "[Aa][Rr][Rr][Aa][Yy]" + +Arg value Array +Error: 8 - Array to string conversion, %s(72) +string(20) "[Aa][Rr][Rr][Aa][Yy]" + +Arg value Array +Error: 8 - Array to string conversion, %s(72) +string(20) "[Aa][Rr][Rr][Aa][Yy]" + +Arg value Array +Error: 8 - Array to string conversion, %s(72) +string(20) "[Aa][Rr][Rr][Aa][Yy]" + +Arg value Array +Error: 8 - Array to string conversion, %s(72) +string(20) "[Aa][Rr][Rr][Aa][Yy]" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(71) + +Arg value +Error: 4096 - Object of class stdClass could not be converted to string, %s(72) +Error: 8 - Object of class stdClass to string conversion, %s(72) +string(24) "[Oo][Bb][Jj][Ee][Cc][Tt]" + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/005.phpt b/ext/standard/tests/serialize/005.phpt index d67f6fbf7..e7b23db70 100755 --- a/ext/standard/tests/serialize/005.phpt +++ b/ext/standard/tests/serialize/005.phpt @@ -179,7 +179,7 @@ do_autoload(autoload_not_available) do_autoload(autoload_not_available) Warning: unserialize(): Function unserializer() hasn't defined the class it was called for in %s005.php on line %d -object(__PHP_Incomplete_Class)#1 (1) { +object(__PHP_Incomplete_Class)#%d (1) { ["__PHP_Incomplete_Class_Name"]=> string(22) "autoload_not_available" } diff --git a/ext/standard/tests/serialize/bug43614.phpt b/ext/standard/tests/serialize/bug43614.phpt new file mode 100644 index 000000000..127dfba58 --- /dev/null +++ b/ext/standard/tests/serialize/bug43614.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #43614 (incorrect processing of numerical string keys of array in arbitrary serialized data) +--FILE-- +<?php + +error_reporting(E_ALL); + +var_dump($a = unserialize('a:2:{s:2:"10";i:1;s:2:"01";i:2;}')); +var_dump($a['10']); +var_dump($a['01']); + +?> +--EXPECT-- +array(2) { + [10]=> + int(1) + ["01"]=> + int(2) +} +int(1) +int(2) diff --git a/ext/standard/tests/serialize/serialization_arrays_001.phpt b/ext/standard/tests/serialize/serialization_arrays_001.phpt new file mode 100644 index 000000000..e39954277 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_001.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test serialize() & unserialize() functions: arrays (circular references) +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +echo "\n--- Testing Circular reference of an array ---\n"; + +echo "-- Normal array --\n"; +$arr_circ = array(0, 1, -2, 3.333333, "a", array(), &$arr_circ); +$serialize_data = serialize($arr_circ); +$arr_circ[6] = null; +var_dump( $serialize_data ); +$arr_circ = unserialize($serialize_data); +var_dump( $arr_circ ); +$arr_circ[6] = null; + +echo "\n-- Associative array --\n"; +$arr_asso = array("a" => "test"); +$arr_asso[ "b" ] = &$arr_asso[ "a" ]; +var_dump($arr_asso); +$serialize_data = serialize($arr_asso); +var_dump($serialize_data); +$arr_asso = unserialize($serialize_data); +var_dump($arr_asso); + +echo "\nDone"; +?> +--EXPECTF-- + +--- Testing Circular reference of an array --- +-- Normal array -- +string(238) "a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;R:8;}}" +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-2) + [3]=> + float(3.333333) + [4]=> + string(1) "a" + [5]=> + array(0) { + } + [6]=> + &array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-2) + [3]=> + float(3.333333) + [4]=> + string(1) "a" + [5]=> + array(0) { + } + [6]=> + &array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-2) + [3]=> + float(3.333333) + [4]=> + string(1) "a" + [5]=> + array(0) { + } + [6]=> + *RECURSION* + } + } +} + +-- Associative array -- +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} +string(37) "a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}" +array(2) { + ["a"]=> + &string(4) "test" + ["b"]=> + &string(4) "test" +} + +Done diff --git a/ext/standard/tests/serialize/serialization_arrays_002.phpt b/ext/standard/tests/serialize/serialization_arrays_002.phpt new file mode 100644 index 000000000..f8cef7818 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_002.phpt @@ -0,0 +1,544 @@ +--TEST-- +serialization: arrays with references amonst elements +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- No references:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 0 refs 1:\n"; +$a = array(); +$a[0] = &$a[1]; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 0 refs 2:\n"; +$a = array(); +$a[0] = &$a[2]; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[0]; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs 2:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[2]; +$a[2] = 1; +check($a); + +echo "\n\n--- 2 refs 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$a[0]; +check($a); + +echo "\n\n--- 2 refs 1:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$a[1]; +check($a); + +echo "\n\n--- 0,1 ref 2:\n"; +$a = array(); +$a[0] = &$a[2]; +$a[1] = &$a[2]; +$a[2] = 1; +check($a); + +echo "\n\n--- 0,2 ref 1:\n"; +$a = array(); +$a[0] = &$a[1]; +$a[1] = 1; +$a[2] = &$a[1]; +check($a); + +echo "\n\n--- 1,2 ref 0:\n"; +$a = array(); +$a[0] = 1; +$a[1] = &$a[0]; +$a[2] = &$a[0]; +check($a); + +echo "Done"; +?> +--EXPECTF-- + + +--- No references: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 0 refs 1: +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:1;i:1;i:0;R:2;i:2;i:1;}" +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 0 refs 2: +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + int(1) +} +string(30) "a:3:{i:2;i:1;i:0;R:2;i:1;i:1;}" +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" +} +array(3) { + [2]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [1]=> + string(10) "b1.changed" +} + + +--- 1 refs 0: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1 refs 2: +array(3) { + [0]=> + int(1) + [2]=> + &int(1) + [1]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:2;i:1;i:1;R:3;}" +array(3) { + [0]=> + int(1) + [2]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + string(10) "b0.changed" + [2]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" +} + + +--- 2 refs 0: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 2 refs 1: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;R:3;}" +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 0,1 ref 2: +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + &int(1) +} +string(30) "a:3:{i:2;i:1;i:0;R:2;i:1;R:2;}" +array(3) { + [2]=> + &int(1) + [0]=> + &int(1) + [1]=> + &int(1) +} +array(3) { + [2]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" +} +array(3) { + [2]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" +} +array(3) { + [2]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" +} + + +--- 0,2 ref 1: +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:1;i:1;i:0;R:2;i:2;R:2;}" +array(3) { + [1]=> + &int(1) + [0]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [1]=> + &string(10) "b0.changed" + [0]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [1]=> + &string(10) "b1.changed" + [0]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [1]=> + &string(10) "b2.changed" + [0]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} + + +--- 1,2 ref 0: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_arrays_003.phpt b/ext/standard/tests/serialize/serialization_arrays_003.phpt new file mode 100644 index 000000000..8d664fccf --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_003.phpt @@ -0,0 +1,294 @@ +--TEST-- +serialization: arrays with references to an external variable +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- 0 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = 1; +$a[2] = 1; +check($a); + +echo "\n\n--- 1 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = 1; +$a[1] = &$ext; +$a[2] = 1; +check($a); + +echo "\n\n--- 2 refs external:\n"; +$ext = 1; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$a[2] = &$ext; +check($a); + +echo "\n\n--- 1,2 ref external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = &$ext; +$a[2] = 1; +check($a); + +echo "\n\n--- 1,2,3 ref external:\n"; +$ext = 1; +$a = array(); +$a[0] = &$ext; +$a[1] = &$ext; +$a[2] = &$ext; +check($a); + +echo "Done"; +?> +--EXPECTF-- + + +--- 0 refs external: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1 refs external: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 2 refs external: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2 ref external: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2,3 ref external: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +string(30) "a:3:{i:0;i:1;i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_arrays_004.phpt b/ext/standard/tests/serialize/serialization_arrays_004.phpt new file mode 100644 index 000000000..b6dfc733a --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_004.phpt @@ -0,0 +1,474 @@ +--TEST-- +serialization: arrays with references to the containing array +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + var_dump($b); + $b[0] = "b0.changed"; + var_dump($b); + $b[1] = "b1.changed"; + var_dump($b); + $b[2] = "b2.changed"; + var_dump($b); +} + +echo "\n\n--- 1 refs container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = 1; +$a[2] = 1; +check($a); +$a[0] = null; + +echo "\n\n--- 1,2 ref container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = &$a; +$a[2] = 1; +check($a); +$a[0] = null; +$a[1] = null; + +echo "\n\n--- 1,2,3 ref container:\n"; +$a = array(); +$a[0] = &$a; +$a[1] = &$a; +$a[2] = &$a; +check($a); +$a[0] = null; +$a[1] = null; +$a[2] = null; + + +echo "Done"; +?> +--EXPECTF-- + + +--- 1 refs container: +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;i:1;i:2;i:1;}i:1;i:1;i:2;i:1;}" +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) + } + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + %string(10) "b0.changed" + [1]=> + int(1) + [2]=> + int(1) +} +array(3) { + [0]=> + %string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + %string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2 ref container: +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) + } + [2]=> + int(1) +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;i:1;}i:1;R:2;i:2;i:1;}" +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + int(1) + } + [2]=> + int(1) + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + string(10) "b2.changed" +} + + +--- 1,2,3 ref container: +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } + [1]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } + [2]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } +} +string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;R:2;}i:1;R:2;i:2;R:2;}" +array(3) { + [0]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } + [1]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } + [2]=> + &array(3) { + [0]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [1]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + [2]=> + &array(3) { + [0]=> + *RECURSION* + [1]=> + *RECURSION* + [2]=> + *RECURSION* + } + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b0.changed" + [2]=> + &string(10) "b0.changed" +} +array(3) { + [0]=> + &string(10) "b1.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + &string(10) "b1.changed" +} +array(3) { + [0]=> + &string(10) "b2.changed" + [1]=> + &string(10) "b2.changed" + [2]=> + &string(10) "b2.changed" +} +Done diff --git a/ext/standard/tests/serialize/serialization_arrays_005.phpt b/ext/standard/tests/serialize/serialization_arrays_005.phpt new file mode 100644 index 000000000..c291ed764 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_arrays_005.phpt @@ -0,0 +1,571 @@ +--TEST-- +serialization: arrays with references, nested +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$a) { + var_dump($a); + $ser = serialize($a); + var_dump($ser); + + $b = unserialize($ser); + + // Change each element and dump result. + foreach($b as $k=>$v) { + if (is_array($v)){ + foreach($b[$k] as $sk=>$sv) { + $b[$k][$sk] = "b$k.$sk.changed"; + var_dump($b); + } + } else { + $b[$k] = "b$k.changed"; + var_dump($b); + } + } +} + +echo "\n\n--- Nested array references 1 element in containing array:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = &$c[0]; +$a[1] = 1; +check($c); + +echo "\n\n--- Nested array references 1 element in containing array (slightly different):\n"; +$a = array(); +$c = array(1,&$a,1); +$a[0] = 1; +$a[1] = &$c[0]; +check($c); + +echo "\n\n--- Nested array references 2 elements in containing array:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = &$c[0]; +$a[1] = &$c[1]; +check($c); + +echo "\n\n--- Containing array references 1 element in nested array:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$c = array(1,&$a[0],&$a); +check($c); + +echo "\n\n--- Containing array references 2 elements in nested array:\n"; +$a = array(); +$a[0] = 1; +$a[1] = 1; +$c = array(&$a[0],&$a[1],&$a); +check($c); + +echo "\n\n--- Nested array references container:\n"; +$a = array(); +$c = array(1,1,&$a); +$a[0] = 1; +$a[1] = &$c; +check($c); +$a[1] = null; + +?> +--EXPECTF-- + + +--- Nested array references 1 element in containing array: +array(3) { + [0]=> + &int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;i:1;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} + + +--- Nested array references 1 element in containing array (slightly different): +array(3) { + [0]=> + &int(1) + [1]=> + &array(2) { + [0]=> + int(1) + [1]=> + &int(1) + } + [2]=> + int(1) +} +string(48) "a:3:{i:0;i:1;i:1;a:2:{i:0;i:1;i:1;R:2;}i:2;i:1;}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + &string(10) "b0.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(10) "b0.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(12) "b1.1.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(12) "b1.1.changed" + } + [2]=> + int(1) +} +array(3) { + [0]=> + &string(12) "b1.1.changed" + [1]=> + array(2) { + [0]=> + string(12) "b1.0.changed" + [1]=> + &string(12) "b1.1.changed" + } + [2]=> + string(10) "b2.changed" +} + + +--- Nested array references 2 elements in containing array: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + &int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + } +} + + +--- Containing array references 1 element in nested array: +array(3) { + [0]=> + int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:3;i:1;i:1;}}" +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &int(1) + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b1.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(12) "b2.0.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + int(1) + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + &string(12) "b2.0.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} + + +--- Containing array references 2 elements in nested array: +array(3) { + [0]=> + &int(1) + [1]=> + &int(1) + [2]=> + &array(2) { + [0]=> + &int(1) + [1]=> + &int(1) + } +} +string(48) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;R:2;i:1;R:3;}}" +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &int(1) + } +} +array(3) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(10) "b0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(10) "b1.changed" + } +} +array(3) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + [2]=> + array(2) { + [0]=> + &string(12) "b2.0.changed" + [1]=> + &string(12) "b2.1.changed" + } +} + + +--- Nested array references container: +array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } + } + } +} +string(74) "a:3:{i:0;i:1;i:1;i:1;i:2;a:2:{i:0;i:1;i:1;a:3:{i:0;i:1;i:1;i:1;i:2;R:4;}}}" +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + string(12) "b2.0.changed" + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + &array(2) { + [0]=> + string(12) "b2.0.changed" + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + *RECURSION* + } + } + } + } +} +array(3) { + [0]=> + string(10) "b0.changed" + [1]=> + string(10) "b1.changed" + [2]=> + &array(2) { + [0]=> + string(12) "b2.0.changed" + [1]=> + string(12) "b2.1.changed" + } +} diff --git a/ext/standard/tests/serialize/serialization_error_001.phpt b/ext/standard/tests/serialize/serialization_error_001.phpt new file mode 100644 index 000000000..3f530580d --- /dev/null +++ b/ext/standard/tests/serialize/serialization_error_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test serialize() & unserialize() functions: error conditions - wrong number of args. +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +echo "*** Testing serialize()/unserialize() : error conditions ***\n"; + +// Zero arguments +var_dump( serialize() ); +var_dump( unserialize() ); + +//Test serialize with one more than the expected number of arguments +var_dump( serialize(1,2) ); +var_dump( unserialize(1,2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing serialize()/unserialize() : error conditions *** + +Warning: Wrong parameter count for serialize() in %s on line 16 +NULL + +Warning: unserialize() expects exactly 1 parameter, 0 given in %s on line 17 +bool(false) + +Warning: Wrong parameter count for serialize() in %s on line 20 +NULL + +Warning: unserialize() expects exactly 1 parameter, 2 given in %s on line 21 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_miscTypes_001.phpt b/ext/standard/tests/serialize/serialization_miscTypes_001.phpt Binary files differnew file mode 100644 index 000000000..276913524 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_miscTypes_001.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_001.phpt b/ext/standard/tests/serialize/serialization_objects_001.phpt Binary files differnew file mode 100644 index 000000000..5eba5304b --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_001.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_002.phpt b/ext/standard/tests/serialize/serialization_objects_002.phpt Binary files differnew file mode 100644 index 000000000..aeca6d81a --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_002.phpt diff --git a/ext/standard/tests/serialize/serialization_objects_003.phpt b/ext/standard/tests/serialize/serialization_objects_003.phpt new file mode 100644 index 000000000..c20590b79 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_003.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test serialize() & unserialize() functions: objects (abstract classes) +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +echo "\n--- Testing Abstract Class ---\n"; +// abstract class +abstract class Name +{ + public function Name() { + $this->a = 10; + $this->b = 12.222; + $this->c = "string"; + } + abstract protected function getClassName(); + public function printClassName () { + return $this->getClassName(); + } +} +// implement abstract class +class extendName extends Name +{ + var $a, $b, $c; + + protected function getClassName() { + return "extendName"; + } +} + +$obj_extendName = new extendName(); +$serialize_data = serialize($obj_extendName); +var_dump( $serialize_data ); +$unserialize_data = unserialize($serialize_data); +var_dump( $unserialize_data ); + +$serialize_data = serialize($obj_extendName->printClassName()); +var_dump( $serialize_data ); +$unserialize_data = unserialize($serialize_data); +var_dump( $unserialize_data ); + +echo "\nDone"; +?> +--EXPECTF-- +--- Testing Abstract Class --- +string(119) "O:10:"extendName":3:{s:1:"a";i:10;s:1:"b";d:12.2219999999999995310417943983338773250579833984375;s:1:"c";s:6:"string";}" +object(extendName)#%d (3) { + ["a"]=> + int(10) + ["b"]=> + float(12.222) + ["c"]=> + string(6) "string" +} +string(18) "s:10:"extendName";" +string(10) "extendName" + +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_004.phpt b/ext/standard/tests/serialize/serialization_objects_004.phpt new file mode 100644 index 000000000..6b826a398 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_004.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test serialize() & unserialize() functions: objects - ensure that COW references of objects are not serialized separately (unlike other types). +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +$x = new stdClass; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = 1; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = "a"; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = true; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = null; +$ref = &$x; +var_dump(serialize(array($x, $x))); + +$x = array(); +$ref = &$x; +var_dump(serialize(array($x, $x))); + +echo "Done"; +?> +--EXPECTF-- +string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}" +string(22) "a:2:{i:0;i:1;i:1;i:1;}" +string(30) "a:2:{i:0;s:1:"a";i:1;s:1:"a";}" +string(22) "a:2:{i:0;b:1;i:1;b:1;}" +string(18) "a:2:{i:0;N;i:1;N;}" +string(26) "a:2:{i:0;a:0:{}i:1;a:0:{}}" +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_005.phpt b/ext/standard/tests/serialize/serialization_objects_005.phpt new file mode 100644 index 000000000..35b159387 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_005.phpt @@ -0,0 +1,120 @@ +--TEST-- +Check behaviour of incomplete class +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +$serialized = 'O:1:"C":1:{s:1:"p";i:1;}'; + +$incomplete = unserialize($serialized); +eval('Class C {}'); +$complete = unserialize($serialized); + + +echo "\n\n---> Various types of access on complete class:\n" ; +var_dump($complete); +var_dump(is_object($complete)); +var_dump($complete->p); + +$ref1 = "ref1.original"; +$complete->p = &$ref1; +var_dump($complete->p); +$ref1 = "ref1.changed"; +var_dump($complete->p); +$complete->p = "p.changed"; +var_dump($ref1); + +var_dump(isset($complete->x)); +$complete->x = "x.new"; +var_dump(isset($complete->x)); +unset($complete->x); +var_dump($complete->x); + + +echo "\n\n---> Same types of access on incomplete class:\n" ; +var_dump($incomplete); +var_dump(is_object($incomplete)); +var_dump($incomplete->p); + +$ref2 = "ref1.original"; +$incomplete->p = &$ref2; +var_dump($incomplete->p); +$ref2 = "ref1.changed"; +var_dump($incomplete->p); +$incomplete->p = "p.changed"; +var_dump($ref1); + +var_dump(isset($incomplete->x)); +$incomplete->x = "x.new"; +var_dump(isset($incomplete->x)); +unset($incomplete->x); +var_dump($incomplete->x); + +$incomplete->f(); + +echo "Done"; +?> +--EXPECTF-- +---> Various types of access on complete class: +object(C)#%d (1) { + ["p"]=> + int(1) +} +bool(true) +int(1) +string(13) "ref1.original" +string(12) "ref1.changed" +string(9) "p.changed" +bool(false) +bool(true) + +Notice: Undefined property: C::$x in %s on line 37 +NULL + + +---> Same types of access on incomplete class: +object(__PHP_Incomplete_Class)#%d (2) { + ["__PHP_Incomplete_Class_Name"]=> + string(1) "C" + ["p"]=> + int(1) +} +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 43 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 46 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 47 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 49 +NULL + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 50 +string(9) "p.changed" + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 53 +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 54 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 55 +bool(false) + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 56 + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 57 +NULL + +Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "C" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 59
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_006.phpt b/ext/standard/tests/serialize/serialization_objects_006.phpt new file mode 100644 index 000000000..e223f4ee1 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_006.phpt @@ -0,0 +1,28 @@ +--TEST-- +Behaviour of incomplete class is preserved even when it was not created by unserialize(). +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +$a = new __PHP_Incomplete_Class; +var_dump($a); +var_dump($a->p); + +echo "Done"; +?> +--EXPECTF-- +object(__PHP_Incomplete_Class)#%d (0) { +} + +Notice: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "unknown" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_007.phpt b/ext/standard/tests/serialize/serialization_objects_007.phpt new file mode 100644 index 000000000..9cba9d13b --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_007.phpt @@ -0,0 +1,42 @@ +--TEST-- +Ensure __autoload is called twice if unserialize_callback_func is defined. +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function __autoload($name) { + echo "in __autoload($name)\n"; +} + +ini_set('unserialize_callback_func','check'); + +function check($name) { + echo "in check($name)\n"; +} + +$o = unserialize('O:3:"FOO":0:{}'); + +var_dump($o); + +echo "Done"; +?> +--EXPECTF-- +in __autoload(FOO) +in check(FOO) +in __autoload(FOO) + +Warning: unserialize(): Function check() hasn't defined the class it was called for in %s on line 23 +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(3) "FOO" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_008.phpt b/ext/standard/tests/serialize/serialization_objects_008.phpt new file mode 100644 index 000000000..b963872f2 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_008.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bad unserialize_callback_func +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +ini_set('unserialize_callback_func','Nonexistent'); +$o = unserialize('O:3:"FOO":0:{}'); +var_dump($o); +echo "Done"; +?> +--EXPECTF-- + +Warning: unserialize(): defined (Nonexistent) but not found in %s on line 14 +object(__PHP_Incomplete_Class)#%d (1) { + ["__PHP_Incomplete_Class_Name"]=> + string(3) "FOO" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_009.phpt b/ext/standard/tests/serialize/serialization_objects_009.phpt new file mode 100644 index 000000000..2e8b2dc80 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_009.phpt @@ -0,0 +1,36 @@ +--TEST-- +Custom unserialization of classes with no custom unserializer. +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +$ser = 'C:1:"C":6:{dasdas}'; +$a = unserialize($ser); +eval('class C {}'); +$b = unserialize($ser); + +var_dump($a, $b); + +echo "Done"; +?> +--EXPECTF-- + +Warning: Class __PHP_Incomplete_Class has no unserializer in %s on line 14 + +Notice: unserialize(): Error at offset 6 of 18 bytes in %s on line 14 + +Warning: Class C has no unserializer in %s on line 16 + +Notice: unserialize(): Error at offset 6 of 18 bytes in %s on line 16 +bool(false) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_010.phpt b/ext/standard/tests/serialize/serialization_objects_010.phpt new file mode 100644 index 000000000..0fbf0723d --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_010.phpt @@ -0,0 +1,37 @@ +--TEST-- +Serialize() must return a string or NULL +--SKIPIF-- +<?php if (!interface_exists('Serializable')) die('skip Interface Serialzable not defined'); ?> +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +Class C implements Serializable { + public function serialize() { + return $this; + } + + public function unserialize($blah) { + } +} + +try { + var_dump(serialize(new C)); +} catch (Exception $e) { + echo $e->getMessage(). "\n"; +} + +echo "Done"; +?> +--EXPECTF-- +C::serialize() must return a string or NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_011.phpt b/ext/standard/tests/serialize/serialization_objects_011.phpt new file mode 100644 index 000000000..870793780 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_011.phpt @@ -0,0 +1,196 @@ +--TEST-- +Object serialization / unserialization with inherited and hidden properties. +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +Class A { + private $APriv = "A.APriv"; + protected $AProt = "A.AProt"; + public $APub = "A.APub"; + + function audit() { + return isset($this->APriv, $this->AProt, $this->APub); + } +} + +Class B extends A { + private $BPriv = "B.BPriv"; + protected $BProt = "B.BProt"; + public $BPub = "B.BPub"; + + function audit() { + return parent::audit() && isset($this->AProt, $this->APub, + $this->BPriv, $this->BProt, $this->BPub); + } +} + +Class C extends B { + private $APriv = "C.APriv"; + protected $AProt = "C.AProt"; + public $APub = "C.APub"; + + private $CPriv = "C.CPriv"; + protected $CProt = "C.BProt"; + public $CPub = "C.CPub"; + + function audit() { + return parent::audit() && isset($this->APriv, $this->AProt, $this->APub, + $this->BProt, $this->BPub, + $this->CPriv, $this->CProt, $this->CPub); + } +} + +function prettyPrint($obj) { + echo "\n\nBefore serialization:\n"; + var_dump($obj); + + echo "Serialized form:\n"; + $ser = serialize($obj); + $serPrintable = str_replace("\0", '\0', $ser); + var_dump($serPrintable); + + echo "Unserialized:\n"; + $uobj = unserialize($ser); + var_dump($uobj); + + echo "Sanity check: "; + var_dump($uobj->audit()); +} + +echo "-- Test instance of A --\n"; +prettyPrint(new A); +echo "\n\n-- Test instance of B --\n"; +prettyPrint(new B); +echo "\n\n-- Test instance of C --\n"; +prettyPrint(new C); + +echo "Done"; +?> +--EXPECTF-- +-- Test instance of A -- + + +Before serialization: +object(A)#%d (3) { + ["APriv:private"]=> + string(7) "A.APriv" + ["AProt:protected"]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Serialized form: +string(98) "O:1:"A":3:{s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}" +Unserialized: +object(A)#%d (3) { + ["APriv:private"]=> + string(7) "A.APriv" + ["AProt:protected"]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Sanity check: bool(true) + + +-- Test instance of B -- + + +Before serialization: +object(B)#%d (6) { + ["BPriv:private"]=> + string(7) "B.BPriv" + ["BProt:protected"]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv:private"]=> + string(7) "A.APriv" + ["AProt:protected"]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Serialized form: +string(184) "O:1:"B":6:{s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}" +Unserialized: +object(B)#%d (6) { + ["BPriv:private"]=> + string(7) "B.BPriv" + ["BProt:protected"]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv:private"]=> + string(7) "A.APriv" + ["AProt:protected"]=> + string(7) "A.AProt" + ["APub"]=> + string(6) "A.APub" +} +Sanity check: bool(true) + + +-- Test instance of C -- + + +Before serialization: +object(C)#%d (10) { + ["APriv:private"]=> + string(7) "C.APriv" + ["AProt:protected"]=> + string(7) "C.AProt" + ["APub"]=> + string(6) "C.APub" + ["CPriv:private"]=> + string(7) "C.CPriv" + ["CProt:protected"]=> + string(7) "C.BProt" + ["CPub"]=> + string(6) "C.CPub" + ["BPriv:private"]=> + string(7) "B.BPriv" + ["BProt:protected"]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv:private"]=> + string(7) "A.APriv" +} +Serialized form: +string(302) "O:1:"C":10:{s:8:"\0C\0APriv";s:7:"C.APriv";s:8:"\0*\0AProt";s:7:"C.AProt";s:4:"APub";s:6:"C.APub";s:8:"\0C\0CPriv";s:7:"C.CPriv";s:8:"\0*\0CProt";s:7:"C.BProt";s:4:"CPub";s:6:"C.CPub";s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";}" +Unserialized: +object(C)#%d (10) { + ["APriv:private"]=> + string(7) "C.APriv" + ["AProt:protected"]=> + string(7) "C.AProt" + ["APub"]=> + string(6) "C.APub" + ["CPriv:private"]=> + string(7) "C.CPriv" + ["CProt:protected"]=> + string(7) "C.BProt" + ["CPub"]=> + string(6) "C.CPub" + ["BPriv:private"]=> + string(7) "B.BPriv" + ["BProt:protected"]=> + string(7) "B.BProt" + ["BPub"]=> + string(6) "B.BPub" + ["APriv:private"]=> + string(7) "A.APriv" +} +Sanity check: bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_012.phpt b/ext/standard/tests/serialize/serialization_objects_012.phpt new file mode 100644 index 000000000..f994d8e26 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_012.phpt @@ -0,0 +1,244 @@ +--TEST-- +Object serialization / unserialization: real references and COW references +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +echo "\n\nArray containing same object twice:\n"; +$obj = new stdclass; +$a[0] = $obj; +$a[1] = $a[0]; +var_dump($a); + +$ser = serialize($a); +var_dump($ser); + +$ua = unserialize($ser); +var_dump($ua); +$ua[0]->a = "newProp"; +var_dump($ua); +$ua[0] = "a0.changed"; +var_dump($ua); + + +echo "\n\nArray containing object and reference to that object:\n"; +$obj = new stdclass; +$a[0] = $obj; +$a[1] = &$a[0]; +var_dump($a); + +$ser = serialize($a); +var_dump($ser); + +$ua = unserialize($ser); +var_dump($ua); +$ua[0]->a = "newProp"; +var_dump($ua); +$ua[0] = "a0.changed"; +var_dump($ua); + +echo "\n\nObject containing same object twice:"; +$obj = new stdclass; +$contaner = new stdclass; +$contaner->a = $obj; +$contaner->b = $contaner->a; +var_dump($contaner); + +$ser = serialize($contaner); +var_dump($ser); + +$ucontainer = unserialize($ser); +var_dump($ucontainer); +$ucontainer->a->a = "newProp"; +var_dump($ucontainer); +$ucontainer->a = "container->a.changed"; +var_dump($ucontainer); + + +echo "\n\nObject containing object and reference to that object:\n"; +$obj = new stdclass; +$contaner = new stdclass; +$contaner->a = $obj; +$contaner->b = &$contaner->a; +var_dump($contaner); + +$ser = serialize($contaner); +var_dump($ser); + +$ucontainer = unserialize($ser); +var_dump($ucontainer); +$ucontainer->a->a = "newProp"; +var_dump($ucontainer); +$ucontainer->b = "container->a.changed"; +var_dump($ucontainer); + +echo "Done"; +?> +--EXPECTF-- + + +Array containing same object twice: +array(2) { + [0]=> + object(stdClass)#%d (0) { + } + [1]=> + object(stdClass)#%d (0) { + } +} +string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}" +array(2) { + [0]=> + object(stdClass)#%d (0) { + } + [1]=> + object(stdClass)#%d (0) { + } +} +array(2) { + [0]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } + [1]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} +array(2) { + [0]=> + string(10) "a0.changed" + [1]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} + + +Array containing object and reference to that object: +array(2) { + [0]=> + &object(stdClass)#%d (0) { + } + [1]=> + &object(stdClass)#%d (0) { + } +} +string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;R:2;}" +array(2) { + [0]=> + &object(stdClass)#%d (0) { + } + [1]=> + &object(stdClass)#%d (0) { + } +} +array(2) { + [0]=> + &object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } + [1]=> + &object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} +array(2) { + [0]=> + &string(10) "a0.changed" + [1]=> + &string(10) "a0.changed" +} + + +Object containing same object twice:object(stdClass)#%d (2) { + ["a"]=> + object(stdClass)#%d (0) { + } + ["b"]=> + object(stdClass)#%d (0) { + } +} +string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";r:2;}" +object(stdClass)#%d (2) { + ["a"]=> + object(stdClass)#%d (0) { + } + ["b"]=> + object(stdClass)#%d (0) { + } +} +object(stdClass)#%d (2) { + ["a"]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } + ["b"]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} +object(stdClass)#%d (2) { + ["a"]=> + string(20) "container->a.changed" + ["b"]=> + object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} + + +Object containing object and reference to that object: +object(stdClass)#%d (2) { + ["a"]=> + &object(stdClass)#%d (0) { + } + ["b"]=> + &object(stdClass)#%d (0) { + } +} +string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";R:2;}" +object(stdClass)#%d (2) { + ["a"]=> + &object(stdClass)#%d (0) { + } + ["b"]=> + &object(stdClass)#%d (0) { + } +} +object(stdClass)#%d (2) { + ["a"]=> + &object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } + ["b"]=> + &object(stdClass)#%d (1) { + ["a"]=> + string(7) "newProp" + } +} +object(stdClass)#%d (2) { + ["a"]=> + &string(20) "container->a.changed" + ["b"]=> + &string(20) "container->a.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_013.phpt b/ext/standard/tests/serialize/serialization_objects_013.phpt new file mode 100644 index 000000000..01b623cb0 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_013.phpt @@ -0,0 +1,494 @@ +--TEST-- +Object serialization / unserialization: references amongst properties +--INI-- +error_reporting = E_ALL & ~E_STRICT +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs b:\n"; +$obj = new stdClass; +$obj->a = &$obj->b; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a refs c:\n"; +$obj = new stdClass; +$obj->a = &$obj->c; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->a; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs c:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->c; +$obj->c = 1; +check($obj); + +echo "\n\n--- c refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$obj->a; +check($obj); + +echo "\n\n--- c refs b:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$obj->b; +check($obj); + +echo "\n\n--- a,b refs c:\n"; +$obj = new stdClass; +$obj->a = &$obj->c; +$obj->b = &$obj->c; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,c refs b:\n"; +$obj = new stdClass; +$obj->a = &$obj->b; +$obj->b = 1; +$obj->c = &$obj->b; +check($obj); + +echo "\n\n--- b,c refs a:\n"; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$obj->a; +$obj->c = &$obj->a; +check($obj); + +echo "Done"; +?> +--EXPECTF-- + +--- a refs b: +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a refs c: +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";i:1;}" +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + string(14) "obj->b.changed" +} + + +--- b refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- b refs c: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"c";i:1;s:1:"b";R:3;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" +} + + +--- c refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- c refs b: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:3;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- a,b refs c: +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";R:2;}" +object(stdClass)#%d (3) { + ["c"]=> + &int(1) + ["a"]=> + &int(1) + ["b"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["c"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" +} + + +--- a,c refs b: +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["b"]=> + &int(1) + ["a"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->a.changed" + ["a"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->b.changed" + ["a"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["b"]=> + &string(14) "obj->c.changed" + ["a"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- b,c refs a: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_014.phpt b/ext/standard/tests/serialize/serialization_objects_014.phpt new file mode 100644 index 000000000..234f5e084 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_014.phpt @@ -0,0 +1,295 @@ +--TEST-- +Object serialization / unserialization: references to external values +--INI-- +error_reporting = E_ALL & ~E_STRICT +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- b refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = 1; +$obj->b = &$ext; +$obj->c = 1; +check($obj); + +echo "\n\n--- c refs external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = 1; +$obj->b = 1; +$obj->c = &$ext; +check($obj); + +echo "\n\n--- a,b ref external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = &$ext; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b,c ref external:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$ext; +$obj->b = &$ext; +$obj->c = &$ext; +check($obj); + +echo "Done"; +?> +--EXPECTF-- + +--- a refs external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- b refs external: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- c refs external: +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + int(1) + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b ref external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b,c ref external: +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" +object(stdClass)#%d (3) { + ["a"]=> + &int(1) + ["b"]=> + &int(1) + ["c"]=> + &int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_objects_015.phpt b/ext/standard/tests/serialize/serialization_objects_015.phpt new file mode 100644 index 000000000..02e8279c4 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_objects_015.phpt @@ -0,0 +1,532 @@ +--TEST-- +Object serialization / unserialization: properties reference containing object +--INI-- +error_reporting = E_ALL & ~E_STRICT +--FILE-- +<?php + +function check(&$obj) { + var_dump($obj); + $ser = serialize($obj); + var_dump($ser); + + $uobj = unserialize($ser); + var_dump($uobj); + $uobj->a = "obj->a.changed"; + var_dump($uobj); + $uobj->b = "obj->b.changed"; + var_dump($uobj); + $uobj->c = "obj->c.changed"; + var_dump($uobj); +} + +echo "\n\n--- a refs container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a eqs container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = 1; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b ref container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = &$obj; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b eq container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = $obj; +$obj->c = 1; +check($obj); + +echo "\n\n--- a,b,c ref container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = &$obj; +$obj->b = &$obj; +$obj->c = &$obj; +check($obj); + +echo "\n\n--- a,b,c eq container:\n"; +$ext = 1; +$obj = new stdClass; +$obj->a = $obj; +$obj->b = $obj; +$obj->c = $obj; +check($obj); + +echo "Done"; +?> +--EXPECTF-- +--- a refs container: +object(stdClass)#%d (3) { + ["a"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) + } + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) + } + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a eqs container: +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) + } + ["b"]=> + int(1) + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";i:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + int(1) + ["c"]=> + int(1) + } + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + int(1) + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b ref container: +object(stdClass)#%d (3) { + ["a"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["b"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";R:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["b"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b eq container: +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["c"]=> + int(1) +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";r:1;s:1:"c";i:1;}" +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + *RECURSION* + ["c"]=> + int(1) + } + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + int(1) +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} + + +--- a,b,c ref container: +object(stdClass)#%d (3) { + ["a"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["b"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["c"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } +} +string(55) "O:8:"stdClass":3:{s:1:"a";R:1;s:1:"b";R:1;s:1:"c";R:1;}" +object(stdClass)#%d (3) { + ["a"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["b"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["c"]=> + &object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->a.changed" + ["b"]=> + &string(14) "obj->a.changed" + ["c"]=> + &string(14) "obj->a.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->b.changed" + ["b"]=> + &string(14) "obj->b.changed" + ["c"]=> + &string(14) "obj->b.changed" +} +object(stdClass)#%d (3) { + ["a"]=> + &string(14) "obj->c.changed" + ["b"]=> + &string(14) "obj->c.changed" + ["c"]=> + &string(14) "obj->c.changed" +} + + +--- a,b,c eq container: +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["c"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } +} +string(55) "O:8:"stdClass":3:{s:1:"a";r:1;s:1:"b";r:1;s:1:"c";r:1;}" +object(stdClass)#%d (3) { + ["a"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["c"]=> + object(stdClass)#%d (3) { + ["a"]=> + *RECURSION* + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } + ["c"]=> + object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + *RECURSION* + ["c"]=> + *RECURSION* + } +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + *RECURSION* + } +} +object(stdClass)#%d (3) { + ["a"]=> + string(14) "obj->a.changed" + ["b"]=> + string(14) "obj->b.changed" + ["c"]=> + string(14) "obj->c.changed" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_precision_001.phpt b/ext/standard/tests/serialize/serialization_precision_001.phpt new file mode 100644 index 000000000..eb633beb7 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_precision_001.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test serialize_precision (part 1) +--INI-- +serialize_precision=10 +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +var_dump(serialize(0.1)); +?> +--EXPECTF-- +string(6) "d:0.1;"
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_precision_002.phpt b/ext/standard/tests/serialize/serialization_precision_002.phpt new file mode 100644 index 000000000..653fabea3 --- /dev/null +++ b/ext/standard/tests/serialize/serialization_precision_002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test serialize_precision (part 2) +--INI-- +serialize_precision=75 +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +var_dump(serialize(0.1)); +?> +--EXPECTF-- +string(60) "d:0.1000000000000000055511151231257827021181583404541015625;"
\ No newline at end of file diff --git a/ext/standard/tests/serialize/serialization_resources_001.phpt b/ext/standard/tests/serialize/serialization_resources_001.phpt new file mode 100644 index 000000000..dbb7d3d3e --- /dev/null +++ b/ext/standard/tests/serialize/serialization_resources_001.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test serialize() & unserialize() functions: resources +--FILE-- +<?php +/* Prototype : proto string serialize(mixed variable) + * Description: Returns a string representation of variable (which can later be unserialized) + * Source code: ext/standard/var.c + * Alias to functions: + */ +/* Prototype : proto mixed unserialize(string variable_representation) + * Description: Takes a string representation of variable and recreates it + * Source code: ext/standard/var.c + * Alias to functions: + */ + +echo "\n--- Testing Resource ---\n"; +$file_handle = fopen( __FILE__, "r" ); +$serialized_data = serialize( $file_handle ); +fclose($file_handle); +var_dump($serialized_data); +var_dump(unserialize($serialized_data)); + +echo "\nDone"; +?> +--EXPECTF-- +--- Testing Resource --- +string(4) "i:%d;" +int(%d) + +Done
\ No newline at end of file diff --git a/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt new file mode 100644 index 000000000..f46c8fd70 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_dir_basic.phpt @@ -0,0 +1,50 @@ +--TEST-- +stream_get_meta_data() on directories +--FILE-- +<?php + +$dir = opendir(dirname(__FILE__)); +var_dump(stream_get_meta_data($dir)); +closedir($dir); + +$dirObject = dir(dirname(__FILE__)); +var_dump(stream_get_meta_data($dirObject->handle)); + +?> +--EXPECT-- +array(8) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(3) "dir" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(8) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(3) "dir" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt new file mode 100644 index 000000000..4758c750f --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +stream_get_meta_data() basic functionality +--FILE-- +<?php + +$fp = fopen(__FILE__, "r"); + +var_dump(stream_get_meta_data($fp)); + +fclose($fp); + +?> +--EXPECTF-- +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%sstream_get_meta_data_file_basic.php" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt new file mode 100644 index 000000000..912c4055a --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_error.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test stream_get_meta_data() function : error conditions +--FILE-- +<?php +/* Prototype : proto array stream_get_meta_data(resource fp) + * Description: Retrieves header/meta data from streams/file pointers + * Source code: ext/standard/streamsfuncs.c + * Alias to functions: socket_get_status + */ + +echo "*** Testing stream_get_meta_data() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing stream_get_meta_data() function with Zero arguments --\n"; +var_dump( stream_get_meta_data() ); + +//Test stream_get_meta_data with one more than the expected number of arguments +echo "\n-- Testing stream_get_meta_data() function with more than expected no. of arguments --\n"; + +$fp = null; +$extra_arg = 10; +var_dump( stream_get_meta_data($fp, $extra_arg) ); + +echo "\n-- Testing stream_get_meta_data() function with invalid stream resource --\n"; +$fp = null; +var_dump(stream_get_meta_data($fp)); + +echo "\n-- Testing stream_get_meta_data() function with closed stream resource --\n"; +$fp = fopen(__FILE__, 'r'); +fclose($fp); +var_dump(stream_get_meta_data($fp)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing stream_get_meta_data() : error conditions *** + +-- Testing stream_get_meta_data() function with Zero arguments -- + +Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i +NULL + +-- Testing stream_get_meta_data() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i +NULL + +-- Testing stream_get_meta_data() function with invalid stream resource -- + +Warning: stream_get_meta_data(): supplied argument is not a valid stream resource in %s on line %i +bool(false) + +-- Testing stream_get_meta_data() function with closed stream resource -- + +Warning: stream_get_meta_data(): %i is not a valid stream resource in %s on line %i +bool(false) +Done diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt new file mode 100644 index 000000000..572653e3d --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation1.phpt @@ -0,0 +1,510 @@ +--TEST-- +stream_get_meta_data() with differing file access modes +--FILE-- +<?php + +// array of all file access modes +$filemodes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', + 'rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+', 'xb', 'xb+', + 'rt', 'rt+', 'wt', 'wt+', 'at', 'at+', 'xt', 'xt+'); + +//create a file +$filename = __FILE__ . '.tmp'; +$fp = fopen($filename, 'w+'); +fclose($fp); + +// open file in each access mode and get meta data +foreach ($filemodes as $mode) { + if (strncmp($mode, 'x', 1) == 0) { + // x modes require that file does not exist + unlink($filename); + } + $fp = fopen($filename, $mode); + var_dump(stream_get_meta_data($fp)); + fclose($fp); +} + +unlink($filename); + +?> +--EXPECTF-- +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "w" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "a" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "a+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "x" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "x+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "rb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "rb+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "wb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "wb+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "ab" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "ab+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "xb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "xb+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "rt" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "rt+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "wt" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "wt+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "at" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "at+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "xt" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(3) "xt+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt new file mode 100644 index 000000000..d186cb7e9 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation2.phpt @@ -0,0 +1,135 @@ +--TEST-- +Testing stream_get_meta_data() "unread_bytes" field +--FILE-- +<?php + +$filename = __FILE__ . '.tmp'; + +$fp = fopen($filename, "w+"); + +echo "Write some data to the file:\n"; +$i = 0; +while ($i++ < 20) { + fwrite($fp, "a line of data\n"); +} + +var_dump(stream_get_meta_data($fp)); + +//seek to start of file +rewind($fp); + +echo "\n\nRead a line of the file, causing data to be buffered:\n"; +var_dump(fgets($fp)); + +var_dump(stream_get_meta_data($fp)); + +echo "\n\nRead 20 bytes from the file:\n"; +fread($fp, 20); + +var_dump(stream_get_meta_data($fp)); + +echo "\n\nRead entire file:\n"; +while(!feof($fp)) { + fread($fp, 1); +} + +var_dump(stream_get_meta_data($fp)); + +fclose($fp); + +unlink($filename); + +?> +--EXPECTF-- +Write some data to the file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read a line of the file, causing data to be buffered: +string(15) "a line of data +" +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(285) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read 20 bytes from the file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(265) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read entire file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(true) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt new file mode 100644 index 000000000..c51d9bd08 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation4.phpt @@ -0,0 +1,71 @@ +--TEST-- +stream_get_meta_data() with a relative file path +--FILE-- +<?php + +echo "Create a file:\n"; +$filename = __FILE__ . '.tmp'; +$fp = fopen('File://' . $filename, 'w+'); + +var_dump(stream_get_meta_data($fp)); + +fclose($fp); + +echo "\nChange to file's directory and open with a relative path:\n"; + +$dirname = dirname($filename); +chdir($dirname); +$relative_filename = basename($filename); + +$fp = fopen($relative_filename, 'r'); +var_dump(stream_get_meta_data($fp)); + +fclose($fp); + +unlink($filename); + +?> +--EXPECTF-- +Create a file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "File://%sstream_get_meta_data_file_variation4.php.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + +Change to file's directory and open with a relative path: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "stream_get_meta_data_file_variation4.php.tmp" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt b/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt new file mode 100644 index 000000000..386b92f42 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_file_variation5.phpt @@ -0,0 +1,77 @@ +--TEST-- +testing stream_get_meta_data() "eof" field for a file stream +--FILE-- +<?php + +$filename = __FILE__ . '.tmp'; + +$fp = fopen($filename, "w+"); + +echo "Write some data to the file:\n"; +$i = 0; +while ($i++ < 20) { + fwrite($fp, "a line of data\n"); +} + +var_dump(stream_get_meta_data($fp)); + +//seek to start of file +rewind($fp); + +echo "\n\nRead entire file:\n"; +while(!feof($fp)) { + fread($fp, 1); +} + +var_dump(stream_get_meta_data($fp)); + +fclose($fp); + +unlink($filename); + +?> +--EXPECTF-- +Write some data to the file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read entire file: +array(9) { + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "w+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%i) "%s" + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(true) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_process_basic-win32.phpt b/ext/standard/tests/streams/stream_get_meta_data_process_basic-win32.phpt new file mode 100644 index 000000000..97b7d780a --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_process_basic-win32.phpt @@ -0,0 +1,43 @@ +--TEST-- +Testing stream_get_meta_data() on a process stream. +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + // windows retains the 'b' in the mode string + die('skip.. only for Windows'); +} +?> +--FILE-- +<?php + +$output_file = __FILE__.'.tmp'; +$cmd = "echo here is some output"; +$mode = 'rb'; +$handle = popen($cmd, $mode); +$data = fread($handle, 100); + +var_dump(stream_get_meta_data($handle)); + +pclose($handle); + +echo "Done"; + +?> +--EXPECT-- +array(7) { + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(2) "rb" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +Done diff --git a/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt new file mode 100644 index 000000000..6b383e75d --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_process_basic.phpt @@ -0,0 +1,43 @@ +--TEST-- +Testing stream_get_meta_data() on a process stream. +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + // non-windows platforms discard the 'b' from the mode string + die('skip Not valid for Windows'); +} +?> +--FILE-- +<?php + +$output_file = __FILE__.'.tmp'; +$cmd = "echo here is some output"; +$mode = 'rb'; +$handle = popen($cmd, $mode); +$data = fread($handle, 100); + +var_dump(stream_get_meta_data($handle)); + +pclose($handle); + +echo "Done"; + +?> +--EXPECT-- +array(7) { + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} +Done diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt new file mode 100644 index 000000000..86056114b --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +stream_get_meta_data() on a udp socket +--FILE-- +<?php + +$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337'); +var_dump(stream_get_meta_data($tcp_socket)); +fclose($tcp_socket); + +?> +--EXPECTF-- +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt new file mode 100644 index 000000000..649311039 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation1.phpt @@ -0,0 +1,110 @@ +--TEST-- +Testing stream_get_meta_data() "unread_bytes" field on a udp socket +--FILE-- +<?php + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +echo "Write some data:\n"; +fwrite($socket, "abcdefg\n1234567\nxyzxyz\n"); +var_dump(stream_get_meta_data($client)); + +echo "\n\nRead a line from the client, causing data to be buffered:\n"; +fgets($client); +var_dump(stream_get_meta_data($client)); + +echo "\n\nRead 3 bytes of data from the client:\n"; +fread($client, 3); +var_dump(stream_get_meta_data($client)); + +echo "\n\nClose the server side socket and read the remaining data from the client:\n"; +fclose($socket); +fclose($server); +while(!feof($client)) { + fread($client, 1); +} +var_dump(stream_get_meta_data($client)); + +?> +--EXPECTF-- +Write some data: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read a line from the client, causing data to be buffered: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(15) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read 3 bytes of data from the client: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(12) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Close the server side socket and read the remaining data from the client: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(true) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt new file mode 100644 index 000000000..c04f3cb5d --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation2.phpt @@ -0,0 +1,108 @@ +--TEST-- +Testing stream_get_meta_data() "timed_out" field on a udp socket +--FILE-- +<?php + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +var_dump(stream_get_meta_data($client)); + +echo "\n\nSet a timeout on the client and attempt a read:\n"; +socket_set_timeout($client, 0, 1000); +fread($client, 1); +var_dump(stream_get_meta_data($client)); + +echo "\n\nWrite some data from the server:\n"; +fwrite($socket, "12345"); +var_dump(stream_get_meta_data($client)); + +echo "\n\nRead some data from the client:\n"; +fread($client, 5); +var_dump(stream_get_meta_data($client)); + +fclose($client); +fclose($socket); +fclose($server); + +?> +--EXPECTF-- +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Set a timeout on the client and attempt a read: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(true) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Write some data from the server: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(true) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read some data from the client: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt new file mode 100644 index 000000000..4ec00b3fd --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation3.phpt @@ -0,0 +1,86 @@ +--TEST-- +Testing stream_get_meta_data() "blocked" field on a udp socket +--FILE-- +<?php + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +var_dump(stream_get_meta_data($client)); + +echo "\n\nSet blocking to false:\n"; +var_dump(socket_set_blocking($client, 0)); +var_dump(stream_get_meta_data($client)); + +echo "\n\nSet blocking to true:\n"; +var_dump(socket_set_blocking($client, 1)); +var_dump(stream_get_meta_data($client)); + +fclose($client); +fclose($socket); +fclose($server); + +?> +--EXPECTF-- +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Set blocking to false: +bool(true) +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(false) + ["eof"]=> + bool(false) +} + + +Set blocking to true: +bool(true) +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} diff --git a/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt new file mode 100644 index 000000000..dae4f470f --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_socket_variation4.phpt @@ -0,0 +1,89 @@ +--TEST-- +Testing stream_get_meta_data() "eof" field on a udp socket +--FILE-- +<?php + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); + +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +/* Accept that connection */ +$socket = stream_socket_accept($server); + +echo "Write some data:\n"; +fwrite($socket, "abcdefg\n1234567\nxyzxyz\n"); +var_dump(stream_get_meta_data($client)); + +echo "\n\nRead a line from the client:\n"; +fgets($client); +var_dump(stream_get_meta_data($client)); + +echo "\n\nClose the server side socket and read the remaining data from the client:\n"; +fclose($socket); +fclose($server); +while(!feof($client)) { + fread($client, 1); +} +var_dump(stream_get_meta_data($client)); + +fclose($client); + +?> +--EXPECTF-- +Write some data: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(%i) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Read a line from the client: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(%i) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) +} + + +Close the server side socket and read the remaining data from the client: +array(7) { + ["stream_type"]=> + string(%d) "tcp_socke%s" + ["mode"]=> + string(2) "r+" + ["unread_bytes"]=> + int(%i) + ["seekable"]=> + bool(false) + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(true) +} diff --git a/ext/standard/tests/streams/stream_set_timeout_error.phpt b/ext/standard/tests/streams/stream_set_timeout_error.phpt new file mode 100644 index 000000000..1e8e60bd2 --- /dev/null +++ b/ext/standard/tests/streams/stream_set_timeout_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test stream_set_timeout() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool stream_set_timeout(resource stream, int seconds, int microseconds) + * Description: Set timeout on stream read to seconds + microseonds + * Source code: ext/standard/streamsfuncs.c + * Alias to functions: socket_set_timeout + */ + +/* + * add a comment here to say what the test is supposed to do + */ + +echo "*** Testing stream_set_timeout() : error conditions ***\n"; + + +//Test stream_set_timeout with one more than the expected number of arguments +echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n"; + +/* Setup socket server */ +$server = stream_socket_server('tcp://127.0.0.1:31337'); +/* Connect to it */ +$client = fsockopen('tcp://127.0.0.1:31337'); + +$seconds = 10; +$microseconds = 10; +$extra_arg = 10; +var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) ); + +// Testing stream_set_timeout with one less than the expected number of arguments +echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n"; + +$seconds = 10; +var_dump( stream_set_timeout($client) ); + + +echo "\n-- Testing stream_set_timeout() function with a closed socket --\n"; +fclose($client); +var_dump( stream_set_timeout($client, $seconds) ); + +echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n"; +var_dump( stream_set_timeout($seconds, $seconds) ); + +echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n"; +$filestream = fopen(__FILE__, "r"); +var_dump( stream_set_timeout($filestream, $seconds) ); + +fclose($filestream); +fclose($server); + +echo "Done"; +?> +--EXPECTF-- +*** Testing stream_set_timeout() : error conditions *** + +-- Testing stream_set_timeout() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for stream_set_timeout() in %s on line %i +NULL + +-- Testing stream_set_timeout() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for stream_set_timeout() in %s on line %i +NULL + +-- Testing stream_set_timeout() function with a closed socket -- + +Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i +bool(false) + +-- Testing stream_set_timeout() function with an invalid stream -- + +Warning: stream_set_timeout(): supplied argument is not a valid stream resource in %s on line %i +bool(false) + +-- Testing stream_set_timeout() function with a stream that does not support timeouts -- +bool(false) +Done diff --git a/ext/standard/tests/strings/bug37262.phpt b/ext/standard/tests/strings/bug37262.phpt index 474251a81..6fe2d9f37 100644 --- a/ext/standard/tests/strings/bug37262.phpt +++ b/ext/standard/tests/strings/bug37262.phpt @@ -6,4 +6,4 @@ $func = create_function('$a', 'return $a;'); var_export($func); ?> --EXPECT-- -'\000lambda_1' +'' . "\0" . 'lambda_1' diff --git a/ext/standard/tests/strings/bug43927.phpt b/ext/standard/tests/strings/bug43927.phpt new file mode 100644 index 000000000..b780c4aac --- /dev/null +++ b/ext/standard/tests/strings/bug43927.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #43927 (koi8r is missing from html_entity_decode()) +--FILE-- +<?php +var_dump(html_entity_decode("&lt;", ENT_COMPAT, 'koi8-r')); +var_dump(html_entity_decode("&#38;", ENT_COMPAT, 'koi8-r')); +var_dump(html_entity_decode("&#38;lt;", ENT_COMPAT, 'koi8-r')); +?> +--EXPECT-- +string(4) "<" +string(5) "&" +string(8) "&lt;" diff --git a/ext/standard/tests/strings/bug44242.phpt b/ext/standard/tests/strings/bug44242.phpt new file mode 100644 index 000000000..00adda2be --- /dev/null +++ b/ext/standard/tests/strings/bug44242.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #44242 (metaphone('CMXFXM') crashes PHP) +--FILE-- +<?php + +echo metaphone('CMXFXZ'), "\n"; +echo metaphone('CMXFXV'), "\n"; +echo metaphone('CMXFXZXZ'), "\n"; + +?> +--EXPECT-- +KMKSFKSS +KMKSFKSF +KMKSFKSSKSS diff --git a/ext/standard/tests/strings/bug44703.phpt b/ext/standard/tests/strings/bug44703.phpt new file mode 100644 index 000000000..d2cdce9bf --- /dev/null +++ b/ext/standard/tests/strings/bug44703.phpt @@ -0,0 +1,48 @@ +--TEST-- +Bug #44703 (htmlspecialchars() does not detect bad character set argument) +--FILE-- +<?php + +var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_COMPAT, 1)); +var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_COMPAT, 12)); +var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_COMPAT, 125)); +var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_COMPAT, 1252)); +var_dump(htmlspecialchars("<a href='test'>Test</a>", ENT_COMPAT, 12526)); + +var_dump(htmlspecialchars("<>", ENT_COMPAT, 866)); +var_dump(htmlspecialchars("<>", ENT_COMPAT, 8666)); + +var_dump(htmlspecialchars("<>", ENT_COMPAT, NULL)); + + +var_dump(htmlspecialchars("<>", ENT_COMPAT, 'SJIS')); +var_dump(htmlspecialchars("<>", ENT_COMPAT, 'SjiS')); + +var_dump(htmlspecialchars("<>", ENT_COMPAT, str_repeat('a', 100))); + +?> +--EXPECTF-- +Warning: htmlspecialchars(): charset `1' not supported, assuming iso-8859-1 in %s on line %d +string(35) "<a href='test'>Test</a>" + +Warning: htmlspecialchars(): charset `12' not supported, assuming iso-8859-1 in %s on line %d +string(35) "<a href='test'>Test</a>" + +Warning: htmlspecialchars(): charset `125' not supported, assuming iso-8859-1 in %s on line %d +string(35) "<a href='test'>Test</a>" +string(35) "<a href='test'>Test</a>" + +Warning: htmlspecialchars(): charset `12526' not supported, assuming iso-8859-1 in %s on line %d +string(35) "<a href='test'>Test</a>" +string(8) "<>" + +Warning: htmlspecialchars(): charset `8666' not supported, assuming iso-8859-1 in %s on line %d +string(8) "<>" +string(8) "<>" +string(8) "<>" +string(8) "<>" + +Warning: htmlspecialchars(): charset `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' not supported, assuming iso-8859-1 in %s on line %d +string(8) "<>" + + diff --git a/ext/standard/tests/strings/chunk_split_variation1.phpt b/ext/standard/tests/strings/chunk_split_variation1.phpt index 58cb0515c..e34ce3a51 100644 --- a/ext/standard/tests/strings/chunk_split_variation1.phpt +++ b/ext/standard/tests/strings/chunk_split_variation1.phpt @@ -1,167 +1,167 @@ ---TEST-- -Test chunk_split() function : usage variations - with unexpected values for 'str' argument ---FILE-- -<?php -/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]]) - * Description: Returns split line %d%d - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -echo "*** Testing chunk_split() : with unexpected values for 'str' argument ***\n"; - -// Initialising variables -$chunklen = 2; -$ending = ' '; - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -//class for object variable -class MyClass -{ - public function __toString() - { - return "object"; - } -} - -//resource variable -$fp = fopen(__FILE__, 'r'); - -//different values for 'str' -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // string data - "string", - 'string', - - // object data - new MyClass(), - - // undefined data - @$undefined_var, - - // unset data - @$unset_var, - - // resource data - $fp -); - -// loop through each element of the array for 'str' -for($count = 0; $count < count($values); $count++) { - echo "-- Iteration ".($count+1)." --\n"; - var_dump( chunk_split($values[$count], $chunklen, $ending) ); -}; - -echo "Done"; - -// close the resource -fclose($fp); - -?> ---EXPECTF-- -*** Testing chunk_split() : with unexpected values for 'str' argument *** --- Iteration 1 -- -string(2) "0 " --- Iteration 2 -- -string(2) "1 " --- Iteration 3 -- -string(8) "12 34 5 " --- Iteration 4 -- -string(8) "-2 34 5 " --- Iteration 5 -- -string(6) "10 .5 " --- Iteration 6 -- -string(8) "-1 0. 5 " --- Iteration 7 -- -string(18) "10 50 00 00 00 00 " --- Iteration 8 -- -string(11) "1. 06 E- 9 " --- Iteration 9 -- -string(5) "0. 5 " --- Iteration 10 -- - -Notice: Array to string conversion in %s on line %d -string(8) "Ar ra y " --- Iteration 11 -- - -Notice: Array to string conversion in %s on line %d -string(8) "Ar ra y " --- Iteration 12 -- - -Notice: Array to string conversion in %s on line %d -string(8) "Ar ra y " --- Iteration 13 -- - -Notice: Array to string conversion in %s on line %d -string(8) "Ar ra y " --- Iteration 14 -- - -Notice: Array to string conversion in %s on line %d -string(8) "Ar ra y " --- Iteration 15 -- -string(1) " " --- Iteration 16 -- -string(1) " " --- Iteration 17 -- -string(2) "1 " --- Iteration 18 -- -string(1) " " --- Iteration 19 -- -string(2) "1 " --- Iteration 20 -- -string(1) " " --- Iteration 21 -- -string(1) " " --- Iteration 22 -- -string(1) " " --- Iteration 23 -- -string(9) "st ri ng " --- Iteration 24 -- -string(9) "st ri ng " --- Iteration 25 -- -string(9) "ob je ct " --- Iteration 26 -- -string(1) " " --- Iteration 27 -- -string(1) " " --- Iteration 28 -- -string(%d) "Re so ur ce i d #%d " -Done +--TEST--
+Test chunk_split() function : usage variations - with unexpected values for 'str' argument
+--FILE--
+<?php
+/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
+ * Description: Returns split line %d%d
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing chunk_split() : with unexpected values for 'str' argument ***\n";
+
+// Initialising variables
+$chunklen = 2;
+$ending = ' ';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+//class for object variable
+class MyClass
+{
+ public function __toString()
+ {
+ return "object";
+ }
+}
+
+//resource variable
+$fp = fopen(__FILE__, 'r');
+
+//different values for 'str'
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // string data
+ "string",
+ 'string',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+
+ // resource data
+ $fp
+);
+
+// loop through each element of the array for 'str'
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count+1)." --\n";
+ var_dump( chunk_split($values[$count], $chunklen, $ending) );
+};
+
+echo "Done";
+
+// close the resource
+fclose($fp);
+
+?>
+--EXPECTF--
+*** Testing chunk_split() : with unexpected values for 'str' argument ***
+-- Iteration 1 --
+string(2) "0 "
+-- Iteration 2 --
+string(2) "1 "
+-- Iteration 3 --
+string(8) "12 34 5 "
+-- Iteration 4 --
+string(8) "-2 34 5 "
+-- Iteration 5 --
+string(6) "10 .5 "
+-- Iteration 6 --
+string(8) "-1 0. 5 "
+-- Iteration 7 --
+string(18) "10 12 34 56 70 00 "
+-- Iteration 8 --
+string(20) "1. 07 65 43 21 E- 9 "
+-- Iteration 9 --
+string(5) "0. 5 "
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line 87
+string(8) "Ar ra y "
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line 87
+string(8) "Ar ra y "
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line 87
+string(8) "Ar ra y "
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line 87
+string(8) "Ar ra y "
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line 87
+string(8) "Ar ra y "
+-- Iteration 15 --
+string(1) " "
+-- Iteration 16 --
+string(1) " "
+-- Iteration 17 --
+string(2) "1 "
+-- Iteration 18 --
+string(1) " "
+-- Iteration 19 --
+string(2) "1 "
+-- Iteration 20 --
+string(1) " "
+-- Iteration 21 --
+string(1) " "
+-- Iteration 22 --
+string(1) " "
+-- Iteration 23 --
+string(9) "st ri ng "
+-- Iteration 24 --
+string(9) "st ri ng "
+-- Iteration 25 --
+string(9) "ob je ct "
+-- Iteration 26 --
+string(1) " "
+-- Iteration 27 --
+string(1) " "
+-- Iteration 28 --
+string(%d) "Re so ur ce i d #%s "
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/chunk_split_variation2.phpt b/ext/standard/tests/strings/chunk_split_variation2.phpt index 3498f5fce..a6d876df0 100644 --- a/ext/standard/tests/strings/chunk_split_variation2.phpt +++ b/ext/standard/tests/strings/chunk_split_variation2.phpt @@ -1,172 +1,174 @@ ---TEST-- -Test chunk_split() function : usage variations - unexpected values for 'chunklen' argument(Bug#42796) ---FILE-- -<?php -/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]]) - * Description: Returns split line - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -echo "*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***\n"; - -// Initialise function arguments -$str = 'This is chuklen variation'; -$ending = '*'; - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -//get resource variable -$fp = fopen(__FILE__, 'r'); - -//Class to get object variable -class MyClass -{ - public function __toString() { - return "object"; - } -} - -//array of values to iterate over -$values = array( - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // string data - "string", - 'string', - - // object data - new MyClass(), - - // undefined data - @$undefined_var, - - // unset data - @$unset_var, - - // resource variable - $fp -); - -// loop through each element of the values for 'chunklen' -for($count = 0; $count < count($values); $count++) { - echo "-- Iteration ".($count+1)." --\n"; - var_dump( chunk_split($str, $values[$count], $ending) ); -} - -echo "Done"; - -//closing resource -fclose($fp); - -?> ---EXPECTF-- -*** Testing chunk_split() : with unexpected values for 'chunklen' argument *** --- Iteration 1 -- -string(28) "This is ch*uklen vari*ation*" --- Iteration 2 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 3 -- -string(26) "This is chuklen variation*" --- Iteration 4 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 5 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 6 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 7 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 8 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 9 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 10 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 11 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 12 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 13 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 14 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 15 -- -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 16 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 17 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 18 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 19 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 20 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 21 -- - -Notice: Object of class MyClass could not be converted to int in %s on line %d -string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*" --- Iteration 22 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 23 -- - -Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d -bool(false) --- Iteration 24 -- -string(30) "This *is ch*uklen* vari*ation*" -Done +--TEST--
+Test chunk_split() function : usage variations - unexpected values for 'chunklen' argument(Bug#42796)
+--FILE--
+<?php
+/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
+ * Description: Returns split line
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***\n";
+
+// Initialise function arguments
+$str = 'This is chuklen variation';
+$ending = '*';
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+//get resource variable
+$fp = fopen(__FILE__, 'r');
+
+//Class to get object variable
+class MyClass
+{
+ public function __toString() {
+ return "object";
+ }
+}
+
+//array of values to iterate over
+$values = array(
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // string data
+ "string",
+ 'string',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+
+ // resource variable
+ $fp
+);
+
+// loop through each element of the values for 'chunklen'
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count+1)." --\n";
+ var_dump( chunk_split($str, $values[$count], $ending) );
+}
+
+echo "Done";
+
+//closing resource
+fclose($fp);
+
+?>
+--EXPECTF--
+*** Testing chunk_split() : with unexpected values for 'chunklen' argument ***
+-- Iteration 1 --
+string(28) "This is ch*uklen vari*ation*"
+-- Iteration 2 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 7 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 8 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 9 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 10 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 11 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 12 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 13 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 14 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 15 --
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 16 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 21 --
+
+Notice: Object of class MyClass could not be converted to int in %s on line %d
+string(50) "T*h*i*s* *i*s* *c*h*u*k*l*e*n* *v*a*r*i*a*t*i*o*n*"
+-- Iteration 22 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 23 --
+
+Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
+bool(false)
+-- Iteration 24 --
+string(%d) "%s"
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/chunk_split_variation3.phpt b/ext/standard/tests/strings/chunk_split_variation3.phpt index 00dbbdeee..947cdefde 100644 --- a/ext/standard/tests/strings/chunk_split_variation3.phpt +++ b/ext/standard/tests/strings/chunk_split_variation3.phpt @@ -1,158 +1,158 @@ ---TEST-- -Test chunk_split() function : usage variations - unexpected values for 'ending' argument ---FILE-- -<?php -/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]]) - * Description: Returns split line - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -echo "*** Testing chunk_split() : unexpected values for 'ending' ***\n"; - -// Initializing variables -$str = 'This is simple string.'; -$chunklen = 4.9; - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -//resource variable -$fp = fopen(__FILE__,'r'); - -//Class to get object variable -class MyClass -{ - public function __toString() - { - return "object"; - } -} - -//different values for 'ending' -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new MyClass(), - - // undefined data - @$undefined_var, - - // unset data - @$unset_var, - - // resource data - $fp -); - -// loop through each element of values for 'ending' -for($count = 0; $count < count($values); $count++) { - echo "-- Iteration ".($count+1)." --\n"; - var_dump( chunk_split($str, $chunklen, $values[$count]) ); -} - -echo "Done"; - -//closing resource -fclose($fp); -?> ---EXPECTF-- -*** Testing chunk_split() : unexpected values for 'ending' *** --- Iteration 1 -- -string(28) "This0 is 0simp0le s0trin0g.0" --- Iteration 2 -- -string(28) "This1 is 1simp1le s1trin1g.1" --- Iteration 3 -- -string(52) "This12345 is 12345simp12345le s12345trin12345g.12345" --- Iteration 4 -- -string(52) "This-2345 is -2345simp-2345le s-2345trin-2345g.-2345" --- Iteration 5 -- -string(46) "This10.5 is 10.5simp10.5le s10.5trin10.5g.10.5" --- Iteration 6 -- -string(52) "This-10.5 is -10.5simp-10.5le s-10.5trin-10.5g.-10.5" --- Iteration 7 -- -string(94) "This105000000000 is 105000000000simp105000000000le s105000000000trin105000000000g.105000000000" --- Iteration 8 -- -string(64) "This1.06E-9 is 1.06E-9simp1.06E-9le s1.06E-9trin1.06E-9g.1.06E-9" --- Iteration 9 -- -string(40) "This0.5 is 0.5simp0.5le s0.5trin0.5g.0.5" --- Iteration 10 -- - -Notice: Array to string conversion in %s on line %d -string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array" --- Iteration 11 -- - -Notice: Array to string conversion in %s on line %d -string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array" --- Iteration 12 -- - -Notice: Array to string conversion in %s on line %d -string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array" --- Iteration 13 -- - -Notice: Array to string conversion in %s on line %d -string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array" --- Iteration 14 -- - -Notice: Array to string conversion in %s on line %d -string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array" --- Iteration 15 -- -string(22) "This is simple string." --- Iteration 16 -- -string(22) "This is simple string." --- Iteration 17 -- -string(28) "This1 is 1simp1le s1trin1g.1" --- Iteration 18 -- -string(22) "This is simple string." --- Iteration 19 -- -string(28) "This1 is 1simp1le s1trin1g.1" --- Iteration 20 -- -string(22) "This is simple string." --- Iteration 21 -- -string(22) "This is simple string." --- Iteration 22 -- -string(22) "This is simple string." --- Iteration 23 -- -string(58) "Thisobject is objectsimpobjectle sobjecttrinobjectg.object" --- Iteration 24 -- -string(22) "This is simple string." --- Iteration 25 -- -string(22) "This is simple string." --- Iteration 26 -- -string(%d) "ThisResource id #%d is Resource id #%dsimpResource id #%dle sResource id #%dtrinResource id #%dg.Resource id #%d" -Done +--TEST--
+Test chunk_split() function : usage variations - unexpected values for 'ending' argument
+--FILE--
+<?php
+/* Prototype : string chunk_split(string $str [, int $chunklen [, string $ending]])
+ * Description: Returns split line
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+echo "*** Testing chunk_split() : unexpected values for 'ending' ***\n";
+
+// Initializing variables
+$str = 'This is simple string.';
+$chunklen = 4.9;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+//resource variable
+$fp = fopen(__FILE__,'r');
+
+//Class to get object variable
+class MyClass
+{
+ public function __toString()
+ {
+ return "object";
+ }
+}
+
+//different values for 'ending'
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.123456e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new MyClass(),
+
+ // undefined data
+ @$undefined_var,
+
+ // unset data
+ @$unset_var,
+
+ // resource data
+ $fp
+);
+
+// loop through each element of values for 'ending'
+for($count = 0; $count < count($values); $count++) {
+ echo "-- Iteration ".($count+1)." --\n";
+ var_dump( chunk_split($str, $chunklen, $values[$count]) );
+}
+
+echo "Done";
+
+//closing resource
+fclose($fp);
+?>
+--EXPECTF--
+*** Testing chunk_split() : unexpected values for 'ending' ***
+-- Iteration 1 --
+string(28) "This0 is 0simp0le s0trin0g.0"
+-- Iteration 2 --
+string(28) "This1 is 1simp1le s1trin1g.1"
+-- Iteration 3 --
+string(52) "This12345 is 12345simp12345le s12345trin12345g.12345"
+-- Iteration 4 --
+string(52) "This-2345 is -2345simp-2345le s-2345trin-2345g.-2345"
+-- Iteration 5 --
+string(46) "This10.5 is 10.5simp10.5le s10.5trin10.5g.10.5"
+-- Iteration 6 --
+string(52) "This-10.5 is -10.5simp-10.5le s-10.5trin-10.5g.-10.5"
+-- Iteration 7 --
+string(94) "This101234560000 is 101234560000simp101234560000le s101234560000trin101234560000g.101234560000"
+-- Iteration 8 --
+string(100) "This1.07654321E-9 is 1.07654321E-9simp1.07654321E-9le s1.07654321E-9trin1.07654321E-9g.1.07654321E-9"
+-- Iteration 9 --
+string(40) "This0.5 is 0.5simp0.5le s0.5trin0.5g.0.5"
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line %d
+string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line %d
+string(52) "ThisArray is ArraysimpArrayle sArraytrinArrayg.Array"
+-- Iteration 15 --
+string(22) "This is simple string."
+-- Iteration 16 --
+string(22) "This is simple string."
+-- Iteration 17 --
+string(28) "This1 is 1simp1le s1trin1g.1"
+-- Iteration 18 --
+string(22) "This is simple string."
+-- Iteration 19 --
+string(28) "This1 is 1simp1le s1trin1g.1"
+-- Iteration 20 --
+string(22) "This is simple string."
+-- Iteration 21 --
+string(22) "This is simple string."
+-- Iteration 22 --
+string(22) "This is simple string."
+-- Iteration 23 --
+string(58) "Thisobject is objectsimpobjectle sobjecttrinobjectg.object"
+-- Iteration 24 --
+string(22) "This is simple string."
+-- Iteration 25 --
+string(22) "This is simple string."
+-- Iteration 26 --
+string(%d) "ThisResource id #%d is Resource id #%dsimpResource id #%dle sResource id #%dtrinResource id #%dg.Resource id #%d"
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/crc32_variation1.phpt b/ext/standard/tests/strings/crc32_variation1.phpt index de7ca5d25..ef0729c21 100644 --- a/ext/standard/tests/strings/crc32_variation1.phpt +++ b/ext/standard/tests/strings/crc32_variation1.phpt @@ -1,196 +1,197 @@ ---TEST-- -Test crc32() function : usage variations - unexpected values ---SKIPIF-- -<?php -if (PHP_INT_SIZE != 4) - die("skip this test is for 32bit platform only"); -?> - ---FILE-- -<?php -/* Prototype : string crc32(string $str) - * Description: Calculate the crc32 polynomial of a string - * Source code: ext/standard/crc32.c - * Alias to functions: none -*/ - -/* - * Testing crc32() : with unexpected values for str argument -*/ - -echo "*** Testing crc32() : with unexpected values for str argument ***\n"; - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -// declaring class -class sample { - public function __toString() { - return "object"; - } -} - -// creating a file resource -$file_handle = fopen(__FILE__, 'r'); - -//array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new sample(), - - // undefined data - $undefined_var, - - // unset data - $unset_var, - - // resource - $file_handle -); - -// loop through each element of the array for str - -$count = 1; -foreach($values as $value) { - echo "\n-- Iteration $count --\n"; - var_dump( crc32($value) ); -}; - -// closing the resource -fclose($file_handle); - -echo "Done"; -?> ---EXPECTF-- -*** Testing crc32() : with unexpected values for str argument *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration 1 -- -int(-186917087) - --- Iteration 1 -- -int(-2082672713) - --- Iteration 1 -- -int(-873121252) - --- Iteration 1 -- -int(1860518047) - --- Iteration 1 -- -int(269248583) - --- Iteration 1 -- -int(-834950157) - --- Iteration 1 -- -int(-638440228) - --- Iteration 1 -- -int(-742287383) - --- Iteration 1 -- -int(-2036403827) - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(-2082672713) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(-2082672713) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(-1465013268) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- -int(0) - --- Iteration 1 -- - -Warning: crc32() expects parameter 1 to be string, resource given in %s on line %d -NULL -Done +--TEST--
+Test crc32() function : usage variations - unexpected values
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE != 4)
+ die("skip this test is for 32bit platform only");
+?>
+
+--FILE--
+<?php
+/* Prototype : string crc32(string $str)
+ * Description: Calculate the crc32 polynomial of a string
+ * Source code: ext/standard/crc32.c
+ * Alias to functions: none
+*/
+
+/*
+ * Testing crc32() : with unexpected values for str argument
+*/
+
+echo "*** Testing crc32() : with unexpected values for str argument ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new sample(),
+
+ // undefined data
+ $undefined_var,
+
+ // unset data
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+// loop through each element of the array for str
+
+$count = 1;
+foreach($values as $value) {
+ echo "\n-- Iteration $count --\n";
+ var_dump( crc32($value) );
+ $count++;
+};
+
+// closing the resource
+fclose($file_handle);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing crc32() : with unexpected values for str argument ***
+
+Notice: Undefined variable: undefined_var in %s on line %d
+
+Notice: Undefined variable: unset_var in %s on line %d
+
+-- Iteration 1 --
+int(-186917087)
+
+-- Iteration 2 --
+int(-2082672713)
+
+-- Iteration 3 --
+int(-873121252)
+
+-- Iteration 4 --
+int(1860518047)
+
+-- Iteration 5 --
+int(269248583)
+
+-- Iteration 6 --
+int(-834950157)
+
+-- Iteration 7 --
+int(-965354630)
+
+-- Iteration 8 --
+int(1376932222)
+
+-- Iteration 9 --
+int(-2036403827)
+
+-- Iteration 10 --
+
+Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: crc32() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration 15 --
+int(0)
+
+-- Iteration 16 --
+int(0)
+
+-- Iteration 17 --
+int(-2082672713)
+
+-- Iteration 18 --
+int(0)
+
+-- Iteration 19 --
+int(-2082672713)
+
+-- Iteration 20 --
+int(0)
+
+-- Iteration 21 --
+int(0)
+
+-- Iteration 22 --
+int(0)
+
+-- Iteration 23 --
+int(-1465013268)
+
+-- Iteration 24 --
+int(0)
+
+-- Iteration 25 --
+int(0)
+
+-- Iteration 26 --
+
+Warning: crc32() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt index defb79c22..6d54b6609 100644 --- a/ext/standard/tests/strings/explode.phpt +++ b/ext/standard/tests/strings/explode.phpt @@ -5,6 +5,7 @@ error_reporting=2047 --FILE-- <?php /* From http://bugs.php.net/19865 */ +echo var_export(explode("\1", "a". chr(1). "b". chr(0). "d" . chr(1) . "f" . chr(1). "1" . chr(1) . "d"), TRUE); echo md5(var_export(explode("\1", "a". chr(1). "b". chr(0). "d" . chr(1) . "f" . chr(1). "1" . chr(1) . "d"), TRUE)); echo "\n"; var_dump(@explode("", "")); @@ -29,7 +30,13 @@ var_dump(explode(":^:","a lazy dog:^:jumps::over:^:",-1)); var_dump(explode(":^:","a lazy dog:^:jumps::over:^:",-2)); ?> --EXPECTF-- -6e5d59d5afd6693547a733219d079658 +array ( + 0 => 'a', + 1 => 'b' . "\0" . 'd', + 2 => 'f', + 3 => '1', + 4 => 'd', +)d6bee42a771449205344c0938ad4f035 bool(false) bool(false) bool(false) diff --git a/ext/standard/tests/strings/join_variation1.phpt b/ext/standard/tests/strings/join_variation1.phpt index a42c543b5..4cebcf2fe 100644 --- a/ext/standard/tests/strings/join_variation1.phpt +++ b/ext/standard/tests/strings/join_variation1.phpt @@ -1,167 +1,167 @@ ---TEST-- -Test join() function : usage variations - unexpected values for 'glue' argument ---FILE-- -<?php -/* Prototype : string join( string $glue, array $pieces ) - * Description: Join array elements with a string - * Source code: ext/standard/string.c - * Alias of function: implode() -*/ - -/* - * testing join() by passing different unexpected value for glue argument -*/ - -echo "*** Testing join() : usage variations ***\n"; -// initialize all required variables -$pieces = array("element1", "element2"); - -// get an unset variable -$unset_var = 'string_val'; -unset($unset_var); - -// get a resource variable -$fp = fopen(__FILE__, "r"); - -// define a class -class test -{ - var $t = 10; - function __toString() { - return "testObject"; - } -} - -// array with different values -$values = array ( - - // integer values - 0, - 1, - 12345, - -2345, - - // float values - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array values - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // boolean values - true, - false, - TRUE, - FALSE, - - // objects - new test(), - - // empty string - "", - '', - - // null vlaues - NULL, - null, - - // resource variable - $fp, - - // undefined variable - @$undefined_var, - - // unset variable - @$unset_var -); - - -// loop through each element of the array and check the working of join() -// when $glue arugment is supplied with different values -echo "\n--- Testing join() by supplying different values for 'glue' argument ---\n"; -$counter = 1; -for($index = 0; $index < count($values); $index ++) { - echo "-- Iteration $counter --\n"; - $glue = $values [$index]; - - var_dump( join($glue, $pieces) ); - - $counter ++; -} - -echo "Done\n"; -?> ---EXPECTF-- -*** Testing join() : usage variations *** - ---- Testing join() by supplying different values for 'glue' argument --- --- Iteration 1 -- -string(17) "element10element2" --- Iteration 2 -- -string(17) "element11element2" --- Iteration 3 -- -string(21) "element112345element2" --- Iteration 4 -- -string(21) "element1-2345element2" --- Iteration 5 -- -string(20) "element110.5element2" --- Iteration 6 -- -string(21) "element1-10.5element2" --- Iteration 7 -- -string(28) "element1105000000000element2" --- Iteration 8 -- -string(23) "element11.06E-9element2" --- Iteration 9 -- -string(19) "element10.5element2" --- Iteration 10 -- - -Notice: Array to string conversion in %s on line %d -string(0) "" --- Iteration 11 -- - -Notice: Array to string conversion in %s on line %d -string(1) "0" --- Iteration 12 -- - -Notice: Array to string conversion in %s on line %d -string(1) "1" --- Iteration 13 -- - -Notice: Array to string conversion in %s on line %d -string(7) "1Array2" --- Iteration 14 -- - -Notice: Array to string conversion in %s on line %d -string(11) "redArraypen" --- Iteration 15 -- -string(17) "element11element2" --- Iteration 16 -- -string(16) "element1element2" --- Iteration 17 -- -string(17) "element11element2" --- Iteration 18 -- -string(16) "element1element2" --- Iteration 19 -- -string(26) "element1testObjectelement2" --- Iteration 20 -- -string(16) "element1element2" --- Iteration 21 -- -string(16) "element1element2" --- Iteration 22 -- -string(16) "element1element2" --- Iteration 23 -- -string(16) "element1element2" --- Iteration 24 -- -string(%d) "element1Resource id #%delement2" --- Iteration 25 -- -string(16) "element1element2" --- Iteration 26 -- -string(16) "element1element2" -Done +--TEST--
+Test join() function : usage variations - unexpected values for 'glue' argument
+--FILE--
+<?php
+/* Prototype : string join( string $glue, array $pieces )
+ * Description: Join array elements with a string
+ * Source code: ext/standard/string.c
+ * Alias of function: implode()
+*/
+
+/*
+ * testing join() by passing different unexpected value for glue argument
+*/
+
+echo "*** Testing join() : usage variations ***\n";
+// initialize all required variables
+$pieces = array("element1", "element2");
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// define a class
+class test
+{
+ var $t = 10;
+ function __toString() {
+ return "testObject";
+ }
+}
+
+// array with different values
+$values = array (
+
+ // integer values
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float values
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array values
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // boolean values
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // objects
+ new test(),
+
+ // empty string
+ "",
+ '',
+
+ // null vlaues
+ NULL,
+ null,
+
+ // resource variable
+ $fp,
+
+ // undefined variable
+ @$undefined_var,
+
+ // unset variable
+ @$unset_var
+);
+
+
+// loop through each element of the array and check the working of join()
+// when $glue arugment is supplied with different values
+echo "\n--- Testing join() by supplying different values for 'glue' argument ---\n";
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+ echo "-- Iteration $counter --\n";
+ $glue = $values [$index];
+
+ var_dump( join($glue, $pieces) );
+
+ $counter ++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing join() : usage variations ***
+
+--- Testing join() by supplying different values for 'glue' argument ---
+-- Iteration 1 --
+string(17) "element10element2"
+-- Iteration 2 --
+string(17) "element11element2"
+-- Iteration 3 --
+string(21) "element112345element2"
+-- Iteration 4 --
+string(21) "element1-2345element2"
+-- Iteration 5 --
+string(20) "element110.5element2"
+-- Iteration 6 --
+string(21) "element1-10.5element2"
+-- Iteration 7 --
+string(28) "element1101234567000element2"
+-- Iteration 8 --
+string(29) "element11.07654321E-9element2"
+-- Iteration 9 --
+string(19) "element10.5element2"
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+string(0) ""
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+string(1) "0"
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+string(1) "1"
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line %d
+string(7) "1Array2"
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line %d
+string(11) "redArraypen"
+-- Iteration 15 --
+string(17) "element11element2"
+-- Iteration 16 --
+string(16) "element1element2"
+-- Iteration 17 --
+string(17) "element11element2"
+-- Iteration 18 --
+string(16) "element1element2"
+-- Iteration 19 --
+string(26) "element1testObjectelement2"
+-- Iteration 20 --
+string(16) "element1element2"
+-- Iteration 21 --
+string(16) "element1element2"
+-- Iteration 22 --
+string(16) "element1element2"
+-- Iteration 23 --
+string(16) "element1element2"
+-- Iteration 24 --
+string(%d) "element1Resource id #%delement2"
+-- Iteration 25 --
+string(16) "element1element2"
+-- Iteration 26 --
+string(16) "element1element2"
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/setlocale_basic1.phpt b/ext/standard/tests/strings/setlocale_basic1.phpt index 28bea0bf8..f75311175 100644 --- a/ext/standard/tests/strings/setlocale_basic1.phpt +++ b/ext/standard/tests/strings/setlocale_basic1.phpt @@ -47,8 +47,8 @@ echo "*** Testing setlocale() : basic functionality - set to a specific locale * //set of locales to be used $common_locales = array( - "english_US"=> "en_US.utf8gfd", - "english_AU" => "en_AU.utf8hgg", + "english_US"=> "en_US.utf8", + "english_AU" => "en_AU.utf8", "korean_KR" => "ko_KR.utf8", "Chinese_zh" => "zh_CN.utf8", "germen_DE" => "de_DE.utf8", diff --git a/ext/standard/tests/strings/setlocale_variation4.phpt b/ext/standard/tests/strings/setlocale_variation4.phpt index 3968be102..4ab1db7ad 100644 --- a/ext/standard/tests/strings/setlocale_variation4.phpt +++ b/ext/standard/tests/strings/setlocale_variation4.phpt @@ -5,6 +5,9 @@ Test setlocale() function : usage variations - setting system locale as null if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not valid for windows'); } +if (setlocale(LC_ALL,'en_US.utf8') === false || setlocale(LC_ALL,'en_AU.utf8') === false) { + die('skip en_US.utf8/en_AU.utf8 locales not available'); +} ?> --ENV-- LC_ALL=en_US.utf8; diff --git a/ext/standard/tests/strings/setlocale_variation5.phpt b/ext/standard/tests/strings/setlocale_variation5.phpt index d2c3cf08a..c8e947b09 100644 --- a/ext/standard/tests/strings/setlocale_variation5.phpt +++ b/ext/standard/tests/strings/setlocale_variation5.phpt @@ -5,6 +5,9 @@ Test setlocale() function : usage variations - Setting system locale as empty st if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not valid for windows'); } +if (setlocale(LC_ALL,'en_AU.utf8') === false || setlocale(LC_ALL,'en_US.utf8') === false) { + die('skip en_AU.utf8/en_US.utf8 locales not available'); +} ?> --ENV-- LC_ALL=en_US.utf8; diff --git a/ext/standard/tests/strings/sprintf_variation1.phpt b/ext/standard/tests/strings/sprintf_variation1.phpt index a226bba7e..2a5bdfdec 100644 --- a/ext/standard/tests/strings/sprintf_variation1.phpt +++ b/ext/standard/tests/strings/sprintf_variation1.phpt @@ -44,8 +44,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array data @@ -139,14 +139,14 @@ string(5) "-10.5" string(5) "-10.5" -- Iteration 7 -- -string(12) "105000000000" -string(12) "105000000000" -string(12) "105000000000" +string(12) "101234567000" +string(12) "101234567000" +string(12) "101234567000" -- Iteration 8 -- -string(7) "1.06E-9" -string(7) "1.06E-9" -string(7) "1.06E-9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" -- Iteration 9 -- string(3) "0.5" @@ -267,4 +267,4 @@ string(0) "" string(%d) "Resource id #%d" string(%d) "Resource id #%d" string(%d) "Resource id #%d" -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/sprintf_variation11.phpt b/ext/standard/tests/strings/sprintf_variation11.phpt index d15928dd9..31097d8dd 100644 --- a/ext/standard/tests/strings/sprintf_variation11.phpt +++ b/ext/standard/tests/strings/sprintf_variation11.phpt @@ -40,7 +40,7 @@ foreach($resource_values as $resource_value) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; ?> @@ -58,8 +58,8 @@ string(%d) " %d.000000" string(%d) " %d.000000" string(%d) "%d.000000" -string(%d) " %d.000000" -string(4) "0-9]" +string(%d) "%s%d.000000" +string(%d) "0-9]" string(1) "f" -- Iteration 2 -- @@ -73,7 +73,7 @@ string(%d) " %d.000000" string(%d) " %d.000000" string(%d) "%d.000000" -string(%d) " %d.000000" -string(4) "0-9]" +string(%d) "%s%d.000000" +string(%d) "0-9]" string(1) "f" Done diff --git a/ext/standard/tests/strings/sprintf_variation16.phpt b/ext/standard/tests/strings/sprintf_variation16.phpt index 523eb5fb9..57965315e 100644 --- a/ext/standard/tests/strings/sprintf_variation16.phpt +++ b/ext/standard/tests/strings/sprintf_variation16.phpt @@ -20,12 +20,12 @@ $float_values = array( 0.0, -0.1, 1.0, - 1e5, - -1e6, - 1E8, - -1E9, + 1e3, + -1e2, + 1.23456E8, + -1.234567E9, 10.0000000000000000005, - 10.5e+5 + 10.123e+5 ); // array of string formats @@ -187,62 +187,62 @@ string(10) "a-zA-Z0-9]" string(1) "s" -- Iteration 10 -- -string(6) "100000" +string(4) "1000" string(1) "s" -string(6) "100000" +string(4) "1000" string(1) "s" -string(7) " 100000" -string(7) "100000 " -string(7) " 100000" -string(7) " -100000" -string(6) "100000" -string(30) " 100000" +string(5) " 1000" +string(5) "1000 " +string(5) " 1000" +string(5) " +1000" +string(4) "1000" +string(30) " 1000" string(10) "a-zA-Z0-9]" string(1) "s" -- Iteration 11 -- -string(8) "-1000000" +string(4) "-100" string(1) "s" -string(8) "-1000000" +string(4) "-100" string(1) "s" -string(9) " -1000000" -string(9) "-1000000 " -string(9) " -1000000" -string(9) " --1000000" -string(8) "-1000000" -string(30) " -1000000" +string(5) " -100" +string(5) "-100 " +string(5) " -100" +string(5) " +-100" +string(4) "-100" +string(30) " -100" string(10) "a-zA-Z0-9]" string(1) "s" -- Iteration 12 -- -string(9) "100000000" +string(9) "123456000" string(1) "s" -string(9) "100000000" +string(9) "123456000" string(1) "s" -string(10) " 100000000" -string(10) "100000000 " -string(10) " 100000000" +string(10) " 123456000" +string(10) "123456000 " +string(10) " 123456000" string(10) " -100000000" -string(9) "100000000" -string(30) " 100000000" +123456000" +string(9) "123456000" +string(30) " 123456000" string(10) "a-zA-Z0-9]" string(1) "s" -- Iteration 13 -- -string(11) "-1000000000" +string(11) "-1234567000" string(1) "s" -string(11) "-1000000000" +string(11) "-1234567000" string(1) "s" -string(12) " -1000000000" -string(12) "-1000000000 " -string(12) " -1000000000" +string(12) " -1234567000" +string(12) "-1234567000 " +string(12) " -1234567000" string(12) " --1000000000" -string(11) "-1000000000" -string(30) " -1000000000" +-1234567000" +string(11) "-1234567000" +string(30) " -1234567000" string(10) "a-zA-Z0-9]" string(1) "s" @@ -262,17 +262,17 @@ string(10) "a-zA-Z0-9]" string(1) "s" -- Iteration 15 -- -string(7) "1050000" +string(7) "1012300" string(1) "s" -string(7) "1050000" +string(7) "1012300" string(1) "s" -string(8) " 1050000" -string(8) "1050000 " -string(8) " 1050000" +string(8) " 1012300" +string(8) "1012300 " +string(8) " 1012300" string(8) " -1050000" -string(7) "1050000" -string(30) " 1050000" +1012300" +string(7) "1012300" +string(30) " 1012300" string(10) "a-zA-Z0-9]" string(1) "s" -Done
\ No newline at end of file +Done diff --git a/ext/standard/tests/strings/sprintf_variation17.phpt b/ext/standard/tests/strings/sprintf_variation17.phpt index 08028f8fe..4d9cc6de9 100644 --- a/ext/standard/tests/strings/sprintf_variation17.phpt +++ b/ext/standard/tests/strings/sprintf_variation17.phpt @@ -39,7 +39,7 @@ foreach($resource_values as $resource_value) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; ?> @@ -57,8 +57,8 @@ string(%d) " Resource id #%d" string(%d) " Resource id #%d" string(%d) "Resource id #%d" -string(%d) " Resource id #%d" -string(10) "a-zA-Z0-9]" +string(%d) "%sResource id #%d" +string(%d) "a-zA-Z0-9]" string(1) "s" -- Iteration 2 -- @@ -72,7 +72,7 @@ string(%d) " Resource id #%d" string(%d) " Resource id #%d" string(%d) "Resource id #%d" -string(%d) " Resource id #%d" -string(10) "a-zA-Z0-9]" +string(%d) "%sResource id #%d" +string(%d) "a-zA-Z0-9]" string(1) "s" Done diff --git a/ext/standard/tests/strings/sprintf_variation18.phpt b/ext/standard/tests/strings/sprintf_variation18.phpt index b0013a4e9..960bcd0e7 100644 --- a/ext/standard/tests/strings/sprintf_variation18.phpt +++ b/ext/standard/tests/strings/sprintf_variation18.phpt @@ -7,6 +7,8 @@ Test sprintf() function : usage variations - string formats with array values * Source code: ext/standard/formatted_print.c */ +error_reporting(E_ALL & ~E_NOTICE); + echo "*** Testing sprintf() : string formats with array values ***\n"; // different arrays used to test he function diff --git a/ext/standard/tests/strings/sprintf_variation2.phpt b/ext/standard/tests/strings/sprintf_variation2.phpt index fcd3f2123..a663df444 100644 --- a/ext/standard/tests/strings/sprintf_variation2.phpt +++ b/ext/standard/tests/strings/sprintf_variation2.phpt @@ -7,6 +7,8 @@ Test sprintf() function : usage variations - with all types of values for arg1 a * Source code: ext/standard/formatted_print.c */ +error_reporting(E_ALL & ~E_NOTICE); + echo "*** Testing sprintf() : with different types of values passed for arg1 argument ***\n"; // initialing required variables @@ -40,8 +42,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array data @@ -130,12 +132,12 @@ string(5) "-10.5" string(5) "-10.5" -- Iteration 7 -- -string(12) "105000000000" -string(12) "105000000000" +string(12) "101234567000" +string(12) "101234567000" -- Iteration 8 -- -string(7) "1.06E-9" -string(7) "1.06E-9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" -- Iteration 9 -- string(3) "0.5" @@ -216,4 +218,4 @@ string(0) "" -- Iteration 28 -- string(%d) "Resource id #%d" string(%d) "Resource id #%d" -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/sprintf_variation30.phpt b/ext/standard/tests/strings/sprintf_variation30.phpt index 57c5abbd8..cc80d7bb4 100644 --- a/ext/standard/tests/strings/sprintf_variation30.phpt +++ b/ext/standard/tests/strings/sprintf_variation30.phpt @@ -39,7 +39,7 @@ foreach($resource_values as $resource_value) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; ?> @@ -56,9 +56,9 @@ string(%d) "%d " string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(%d) " %d" -string(4) "0-7]" +string(%d) "%s%d" +string(%d) "%s%d" +string(%d) "0-7]" string(1) "o" -- Iteration 2 -- @@ -71,8 +71,8 @@ string(%d) "%d " string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(%d) " %d" -string(4) "0-7]" +string(%d) "%s%d" +string(%d) "%s%d" +string(%d) "0-7]" string(1) "o" Done diff --git a/ext/standard/tests/strings/sprintf_variation42.phpt b/ext/standard/tests/strings/sprintf_variation42.phpt index a1c01ff6b..3c5bd1f1b 100644 --- a/ext/standard/tests/strings/sprintf_variation42.phpt +++ b/ext/standard/tests/strings/sprintf_variation42.phpt @@ -40,7 +40,7 @@ foreach($resource_values as $resource_value) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; ?> @@ -57,9 +57,9 @@ string(%d) "%d " string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(%d) " %d" -string(4) "0-9]" +string(%d) "%s%d" +string(%d) "%s%d" +string(%d) "0-9]" string(1) "u" -- Iteration 2 -- @@ -72,8 +72,8 @@ string(%d) "%d " string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(%d) " %d" -string(4) "0-9]" +string(%d) "%s%d" +string(%d) "%s%d" +string(%d) "0-9]" string(1) "u" Done diff --git a/ext/standard/tests/strings/sprintf_variation48.phpt b/ext/standard/tests/strings/sprintf_variation48.phpt index df28784eb..ce7bdf8ae 100644 --- a/ext/standard/tests/strings/sprintf_variation48.phpt +++ b/ext/standard/tests/strings/sprintf_variation48.phpt @@ -39,7 +39,7 @@ foreach($resource_values as $resource_value) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; @@ -48,32 +48,32 @@ echo "Done"; *** Testing sprintf() : scientific formats with resource values *** -- Iteration 1 -- -string(%d) "%d.000000e+0" +string(%d) "%f" string(1) "e" -string(%d) "%d.000000e+0" +string(%d) "%f" string(1) "e" -string(%d) " %d.000000e+0" -string(%d) "%d.000000e+0 " -string(%d) " %d.000000e+0" +string(%d) " %f" +string(%d) "%f " +string(%d) " %f" string(%d) " -%d.000000e+0" -string(%d) "%d.000000e+0" -string(%d) " %d.000000e+0" -string(4) "0-1]" +%f" +string(%d) "%f" +string(%d) "%s%f" +string(%d) "0-1]" string(1) "e" -- Iteration 2 -- -string(%d) "%d.000000e+0" +string(%d) "%f" string(1) "e" -string(%d) "%d.000000e+0" +string(%d) "%f" string(1) "e" -string(%d) " %d.000000e+0" -string(%d) "%d.000000e+0 " -string(%d) " %d.000000e+0" +string(%d) " %f" +string(%d) "%f " +string(%d) " %f" string(%d) " -%d.000000e+0" -string(%d) "%d.000000e+0" -string(%d) " %d.000000e+0" -string(4) "0-1]" +%f" +string(%d) "%f" +string(%d) "%s%f" +string(%d) "0-1]" string(1) "e" Done diff --git a/ext/standard/tests/strings/sprintf_variation5.phpt b/ext/standard/tests/strings/sprintf_variation5.phpt index b703d749f..ee13d3d64 100644 --- a/ext/standard/tests/strings/sprintf_variation5.phpt +++ b/ext/standard/tests/strings/sprintf_variation5.phpt @@ -12,11 +12,14 @@ echo "*** Testing sprintf() : integer formats with resource values ***\n"; // resource type variable $fp = fopen (__FILE__, "r"); $dfp = opendir ( dirname(__FILE__) ); + +$fp_copy = $fp; +$dfp_copy = $dfp; // array of resource types $resource_types = array ( - $fp, - $dfp + $fp_copy, + $dfp_copy ); // various integer formats @@ -38,7 +41,7 @@ foreach($resource_types as $res) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "Done"; @@ -53,8 +56,8 @@ string(%d) " %d" string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(4) "0-9]" +string(%d) "%s%d" +string(%d) "0-9]" string(1) "d" -- Iteration 2 -- @@ -64,7 +67,7 @@ string(%d) " %d" string(%d) " %d" string(%d) " %d" -string(%d) " %d" -string(4) "0-9]" +string(%d) "%s%d" +string(%d) "0-9]" string(1) "d" Done diff --git a/ext/standard/tests/strings/str_replace.phpt b/ext/standard/tests/strings/str_replace.phpt index ae71aaaf5..2408c82f0 100644 --- a/ext/standard/tests/strings/str_replace.phpt +++ b/ext/standard/tests/strings/str_replace.phpt @@ -27,8 +27,10 @@ var_dump( str_replace("long string here", "", "", $count) ); var_dump( $count ); $fp = fopen( __FILE__, "r" ); -var_dump( str_replace($fp, $fp, $fp, $fp) ); -var_dump( $fp ); +$fp_copy = $fp; +var_dump( str_replace($fp_copy, $fp_copy, $fp_copy, $fp_copy) ); +var_dump( $fp_copy ); +fclose($fp); echo "\n*** Testing str_replace() with various search values ***"; $search_arr = array( TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, @@ -230,12 +232,9 @@ var_dump( str_replace(NULL) ); var_dump( str_replace(1, 2) ); var_dump( str_replace(1,2,3,$var,5) ); -echo "Done\n"; - ---CLEAN-- -fclose($fp); fclose($resource1); closedir($resource2); +echo "Done\n"; ?> --EXPECTF-- @@ -248,7 +247,7 @@ string(1) "q" int(1) string(0) "" int(0) -string(14) "Resource id #5" +string(%d) "Resource id #%d" int(1) *** Testing str_replace() with various search values *** @@ -910,9 +909,9 @@ array(2) { int(1) -- Testing Resources -- -string(14) "Resource id #6" +string(%d) "Resource id #%d" int(0) -string(14) "Resource id #7" +string(%d) "Resource id #%d" int(0) -- Testing a longer and heredoc string -- diff --git a/ext/standard/tests/strings/strcspn_variation1.phpt b/ext/standard/tests/strings/strcspn_variation1.phpt index f80e4615e..6a1c6d669 100644 --- a/ext/standard/tests/strings/strcspn_variation1.phpt +++ b/ext/standard/tests/strings/strcspn_variation1.phpt @@ -1,276 +1,273 @@ ---TEST-- -Test strcspn() function : usage variations - unexpected values for str argument ---FILE-- -<?php -/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]]) - * Description: Finds length of initial segment consisting entirely of characters not found in mask. - If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars) - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - - -/* -* Testing strspn() : with different unexpected values for str argument -*/ - -echo "*** Testing strcspn() : with unexpected values for str argument ***\n"; - -// Initialise function arguments not being substititued (if any) -$mask = 'abons1234567890'; -$start = 1; -$len = 10; - - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -// declaring class -class sample { - public function __toString() { - return "object"; - } -} - -// creating a file resource -$file_handle = fopen(__FILE__, 'r'); - - -//array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new sample, - - // undefined data - $undefined_var, - - // unset data - $unset_var, - - // resource - $file_handle -); - -// loop through each element of the array for str - -foreach($values as $value) { - echo "\n-- Iteration with str value as \"$value\" \n"; - var_dump( strcspn($value,$mask) ); // with default args - var_dump( strcspn($value,$mask,$start) ); // with default len value - var_dump( strcspn($value,$mask,$start,$len) ); // with all args -}; - -// closing the resource -fclose($file_handle); - -echo "Done" -?> ---EXPECTF-- -*** Testing strcspn() : with unexpected values for str argument *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration with str value as "0" -int(0) -int(0) -int(0) - --- Iteration with str value as "1" -int(0) -int(0) -int(0) - --- Iteration with str value as "12345" -int(0) -int(0) -int(0) - --- Iteration with str value as "-2345" -int(1) -int(0) -int(0) - --- Iteration with str value as "10.5" -int(0) -int(0) -int(0) - --- Iteration with str value as "-10.5" -int(1) -int(0) -int(0) - --- Iteration with str value as "105000000000" -int(0) -int(0) -int(0) - --- Iteration with str value as "1.06E-9" -int(0) -int(1) -int(1) - --- Iteration with str value as "0.5" -int(0) -int(1) -int(1) - --- Iteration with str value as "Array" - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "1" -int(0) -int(0) -int(0) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "1" -int(0) -int(0) -int(0) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "object" -int(0) -int(0) -int(0) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "Resource id #%d" - -Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d -NULL - -Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d -NULL -Done +--TEST--
+Test strcspn() function : usage variations - unexpected values for str argument
+--FILE--
+<?php
+/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
+ * Description: Finds length of initial segment consisting entirely of characters not found in mask.
+ If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+error_reporting(E_ALL & ~E_NOTICE);
+
+/*
+* Testing strspn() : with different unexpected values for str argument
+*/
+
+echo "*** Testing strcspn() : with unexpected values for str argument ***\n";
+
+// Initialise function arguments not being substititued (if any)
+$mask = 'abons1234567890';
+$start = 1;
+$len = 10;
+
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new sample,
+
+ // undefined data
+ $undefined_var,
+
+ // unset data
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+// loop through each element of the array for str
+
+foreach($values as $value) {
+ echo "\n-- Iteration with str value as \"$value\"\n";
+ var_dump( strcspn($value,$mask) ); // with default args
+ var_dump( strcspn($value,$mask,$start) ); // with default len value
+ var_dump( strcspn($value,$mask,$start,$len) ); // with all args
+};
+
+// closing the resource
+fclose($file_handle);
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing strcspn() : with unexpected values for str argument ***
+
+-- Iteration with str value as "0"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as "1"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as "12345"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as "-2345"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "10.5"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as "-10.5"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "101234567000"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as "1.07654321E-9"
+int(0)
+int(1)
+int(1)
+
+-- Iteration with str value as "0.5"
+int(0)
+int(1)
+int(1)
+
+-- Iteration with str value as "Array"
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "1"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "1"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "object"
+int(0)
+int(0)
+int(0)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "Resource id #%d"
+
+Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strcspn_variation2.phpt b/ext/standard/tests/strings/strcspn_variation2.phpt index df79e9afd..0924e4598 100644 --- a/ext/standard/tests/strings/strcspn_variation2.phpt +++ b/ext/standard/tests/strings/strcspn_variation2.phpt @@ -1,274 +1,272 @@ ---TEST-- -Test strcspn() function : usage variations - unexpected values for mask argument ---FILE-- -<?php -/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]]) - * Description: Finds length of initial segment consisting entirely of characters not found in mask. - If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars) - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -/* -* Testing strcspn() : with different unexpected values for mask argument -*/ - -echo "*** Testing strcspn() : with diferent unexpected values of mask argument ***\n"; - -$str = 'string_val'; -$start = 1; -$len = 10; - - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -// declaring class -class sample { - public function __toString() { - return "object"; - } -} - -// creating a file resource -$file_handle = fopen(__FILE__, 'r'); - - -//array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new sample(), - - // undefined data - $undefined_var, - - // unset data - $unset_var, - - // resource - $file_handle -); - -// loop through each element of the array for mask - -foreach($values as $value) { - echo "\n-- Iteration with mask value as \"$value\" -- \n"; - var_dump( strcspn($str,$value) ); // with defalut args - var_dump( strcspn($str,$value,$start) ); // with default len value - var_dump( strcspn($str,$value,$start,$len) ); // with all args -}; - -// close the resource -fclose($file_handle); - -echo "Done" -?> ---EXPECTF-- -*** Testing strcspn() : with diferent unexpected values of mask argument *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration with mask value as "0" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "1" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "12345" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "-2345" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "10.5" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "-10.5" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "105000000000" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "1.06E-9" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "0.5" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "Array" -- - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - --- Iteration with mask value as "Array" -- - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - --- Iteration with mask value as "Array" -- - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - --- Iteration with mask value as "Array" -- - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - --- Iteration with mask value as "Array" -- - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d -NULL - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "1" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "1" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "object" -- -int(1) -int(0) -int(0) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "" -- -int(10) -int(9) -int(9) - --- Iteration with mask value as "Resource id #%d" -- - -Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d -NULL - -Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d -NULL -Done +--TEST--
+Test strcspn() function : usage variations - unexpected values for mask argument
+--FILE--
+<?php
+/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
+ * Description: Finds length of initial segment consisting entirely of characters not found in mask.
+ If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+error_reporting(E_ALL & ~E_NOTICE);
+
+/*
+* Testing strcspn() : with different unexpected values for mask argument
+*/
+
+echo "*** Testing strcspn() : with diferent unexpected values of mask argument ***\n";
+
+$str = 'string_val';
+$start = 1;
+$len = 10;
+
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new sample(),
+
+ // undefined data
+ $undefined_var,
+
+ // unset data
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+// loop through each element of the array for mask
+
+foreach($values as $value) {
+ echo "\n-- Iteration with mask value as \"$value\" --\n";
+ var_dump( strcspn($str,$value) ); // with defalut args
+ var_dump( strcspn($str,$value,$start) ); // with default len value
+ var_dump( strcspn($str,$value,$start,$len) ); // with all args
+};
+
+// close the resource
+fclose($file_handle);
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing strcspn() : with diferent unexpected values of mask argument ***
+
+-- Iteration with mask value as "0" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "1" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "12345" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "-2345" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "10.5" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "-10.5" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "101234567000" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "1.07654321E-9" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "0.5" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "Array" --
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with mask value as "Array" --
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with mask value as "Array" --
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with mask value as "Array" --
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with mask value as "Array" --
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "1" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "1" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "object" --
+int(1)
+int(0)
+int(0)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "" --
+int(10)
+int(9)
+int(9)
+
+-- Iteration with mask value as "Resource id #%d" --
+
+Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+
+Warning: strcspn() expects parameter 2 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strcspn_variation3.phpt b/ext/standard/tests/strings/strcspn_variation3.phpt index 869f46537..8b1923efd 100644 --- a/ext/standard/tests/strings/strcspn_variation3.phpt +++ b/ext/standard/tests/strings/strcspn_variation3.phpt @@ -9,6 +9,8 @@ Test strcspn() function : usage variations - unexpected values of start argument * Alias to functions: none */ +error_reporting(E_ALL & ~E_NOTICE); + /* * Testing strcspn() : with unexpected values of start argument */ @@ -41,8 +43,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e8, + 10.7654321E-8, .5, // array data @@ -99,10 +101,6 @@ echo "Done" --EXPECTF-- *** Testing strcspn() : with unexpected values of start argument *** -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - -- Iteration with start value as "10.5" -- int(0) int(0) @@ -111,11 +109,11 @@ int(0) int(0) int(0) --- Iteration with start value as "105000000000" -- +-- Iteration with start value as "1012345670" -- bool(false) bool(false) --- Iteration with start value as "1.06E-9" -- +-- Iteration with start value as "1.07654321E-7" -- int(0) int(0) @@ -242,4 +240,4 @@ NULL Warning: strcspn() expects parameter 3 to be long, resource given in %s on line %d NULL -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strcspn_variation4.phpt b/ext/standard/tests/strings/strcspn_variation4.phpt index 6ea48219c..eabc0696e 100644 --- a/ext/standard/tests/strings/strcspn_variation4.phpt +++ b/ext/standard/tests/strings/strcspn_variation4.phpt @@ -1,198 +1,196 @@ ---TEST-- -Test strcspn() function : usage variations - unexpected values of len argument ---FILE-- -<?php -/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]]) - * Description: Finds length of initial segment consisting entirely of characters not found in mask. - If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars) - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -/* -* Testing strcspn() : with unexpected values of len argument -*/ - -echo "*** Testing strcspn() : with unexpected values of len argument ***\n"; - -// initialing required variables -$str = 'string_val'; -$mask = 'soibtFTf1234567890'; -$start = 0; - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -// declaring class -class sample { - public function __toString() { - return "object"; - } -} - -// creating a file resource -$file_handle = fopen(__FILE__, 'r'); - - -//array of values to iterate over -$values = array( - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // string data - "string", - 'string', - - // object data - new sample(), - - // undefined data - $undefined_var, - - // unset data - $unset_var, - - // resource - $file_handle -); - -// loop through each element of the array for start - -foreach($values as $value) { - echo "\n-- Iteration with len value as \"$value\" --\n"; - var_dump( strcspn($str,$mask,$start,$value) ); // with all args -}; - -// closing the resource -fclose($file_handle); - -echo "Done" -?> ---EXPECTF-- -*** Testing strcspn() : with unexpected values of len argument *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration with len value as "10.5" -- -int(0) - --- Iteration with len value as "-10.5" -- -int(0) - --- Iteration with len value as "105000000000" -- -int(0) - --- Iteration with len value as "1.06E-9" -- -int(0) - --- Iteration with len value as "0.5" -- -int(0) - --- Iteration with len value as "Array" -- - -Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d -NULL - --- Iteration with len value as "Array" -- - -Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d -NULL - --- Iteration with len value as "Array" -- - -Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d -NULL - --- Iteration with len value as "Array" -- - -Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d -NULL - --- Iteration with len value as "Array" -- - -Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d -NULL - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "1" -- -int(0) - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "1" -- -int(0) - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "" -- - -Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d -NULL - --- Iteration with len value as "" -- - -Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d -NULL - --- Iteration with len value as "string" -- - -Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d -NULL - --- Iteration with len value as "string" -- - -Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d -NULL - --- Iteration with len value as "object" -- - -Warning: strcspn() expects parameter 4 to be long, object given in %s on line %d -NULL - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "" -- -int(0) - --- Iteration with len value as "Resource id #%d" -- - -Warning: strcspn() expects parameter 4 to be long, resource given in %s on line %d -NULL -Done +--TEST--
+Test strcspn() function : usage variations - unexpected values of len argument
+--FILE--
+<?php
+/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
+ * Description: Finds length of initial segment consisting entirely of characters not found in mask.
+ If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+error_reporting(E_ALL & ~E_NOTICE);
+
+/*
+* Testing strcspn() : with unexpected values of len argument
+*/
+
+echo "*** Testing strcspn() : with unexpected values of len argument ***\n";
+
+// initialing required variables
+$str = 'string_val';
+$mask = 'soibtFTf1234567890';
+$start = 0;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+
+//array of values to iterate over
+$values = array(
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // string data
+ "string",
+ 'string',
+
+ // object data
+ new sample(),
+
+ // undefined data
+ $undefined_var,
+
+ // unset data
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+// loop through each element of the array for start
+
+foreach($values as $value) {
+ echo "\n-- Iteration with len value as \"$value\" --\n";
+ var_dump( strcspn($str,$mask,$start,$value) ); // with all args
+};
+
+// closing the resource
+fclose($file_handle);
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing strcspn() : with unexpected values of len argument ***
+
+-- Iteration with len value as "10.5" --
+int(0)
+
+-- Iteration with len value as "-10.5" --
+int(0)
+
+-- Iteration with len value as "101234567000" --
+int(0)
+
+-- Iteration with len value as "1.07654321E-9" --
+int(0)
+
+-- Iteration with len value as "0.5" --
+int(0)
+
+-- Iteration with len value as "Array" --
+
+Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d
+NULL
+
+-- Iteration with len value as "Array" --
+
+Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d
+NULL
+
+-- Iteration with len value as "Array" --
+
+Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d
+NULL
+
+-- Iteration with len value as "Array" --
+
+Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d
+NULL
+
+-- Iteration with len value as "Array" --
+
+Warning: strcspn() expects parameter 4 to be long, array given in %s on line %d
+NULL
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "1" --
+int(0)
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "1" --
+int(0)
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "" --
+
+Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d
+NULL
+
+-- Iteration with len value as "" --
+
+Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d
+NULL
+
+-- Iteration with len value as "string" --
+
+Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d
+NULL
+
+-- Iteration with len value as "string" --
+
+Warning: strcspn() expects parameter 4 to be long, string given in %s on line %d
+NULL
+
+-- Iteration with len value as "object" --
+
+Warning: strcspn() expects parameter 4 to be long, object given in %s on line %d
+NULL
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "" --
+int(0)
+
+-- Iteration with len value as "Resource id #%d" --
+
+Warning: strcspn() expects parameter 4 to be long, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/stripos_variation10.phpt b/ext/standard/tests/strings/stripos_variation10.phpt index efdbb5238..963545cf2 100644 --- a/ext/standard/tests/strings/stripos_variation10.phpt +++ b/ext/standard/tests/strings/stripos_variation10.phpt @@ -41,8 +41,8 @@ $needles = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -182,7 +182,7 @@ bool(false) -- Iteration 24 -- Warning: stripos(): needle is not a string or an integer in %s on line %d -bool(false) +%s -- Iteration 25 -- diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt Binary files differindex e64468135..566ef6c75 100644 --- a/ext/standard/tests/strings/strpos.phpt +++ b/ext/standard/tests/strings/strpos.phpt diff --git a/ext/standard/tests/strings/strpos_number.phpt b/ext/standard/tests/strings/strpos_number.phpt new file mode 100644 index 000000000..73da09500 --- /dev/null +++ b/ext/standard/tests/strings/strpos_number.phpt @@ -0,0 +1,15 @@ +--TEST-- +strpos() matching numbers +--FILE-- +<?php +// Integer is handles as an octal representation, so nothing to match +var_dump(strpos("foo 11", 11)); +// int(111) is string("o") in octal. Match expected +var_dump(strpos("foo bar", 111)); +// string("11") is contained +var_dump(strpos("foo 11", "11")); +?> +--EXPECT-- +bool(false) +int(1) +int(4) diff --git a/ext/standard/tests/strings/strrchr_variation10.phpt b/ext/standard/tests/strings/strrchr_variation10.phpt index 5de3b22ff..c807dd449 100644 --- a/ext/standard/tests/strings/strrchr_variation10.phpt +++ b/ext/standard/tests/strings/strrchr_variation10.phpt @@ -79,8 +79,8 @@ $needles = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -180,7 +180,7 @@ bool(false) -- Iteration 23 -- bool(false) -- Iteration 24 -- -bool(false) +%s -- Iteration 25 -- bool(false) -- Iteration 26 -- diff --git a/ext/standard/tests/strings/strrchr_variation11.phpt b/ext/standard/tests/strings/strrchr_variation11.phpt index d04710d7d..a179c4089 100644 --- a/ext/standard/tests/strings/strrchr_variation11.phpt +++ b/ext/standard/tests/strings/strrchr_variation11.phpt @@ -37,8 +37,8 @@ $values = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -80,8 +80,6 @@ $values = array ( $counter = 1; for($index = 0; $index < count($values); $index ++) { echo "-- Iteration $counter --\n"; - $haystack = $values[$index]; - var_dump( strrchr($values[$index], $values[$index]) ); $counter ++; } @@ -151,7 +149,7 @@ bool(false) -- Iteration 23 -- bool(false) -- Iteration 24 -- -bool(false) +%s -- Iteration 25 -- bool(false) -- Iteration 26 -- diff --git a/ext/standard/tests/strings/strrpos_variation10.phpt b/ext/standard/tests/strings/strrpos_variation10.phpt index abdc5e2f4..f3adb3ee9 100644 --- a/ext/standard/tests/strings/strrpos_variation10.phpt +++ b/ext/standard/tests/strings/strrpos_variation10.phpt @@ -41,8 +41,8 @@ $needles = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -142,7 +142,7 @@ bool(false) -- Iteration 23 -- bool(false) -- Iteration 24 -- -bool(false) +%s -- Iteration 25 -- bool(false) -- Iteration 26 -- diff --git a/ext/standard/tests/strings/strspn_variation1.phpt b/ext/standard/tests/strings/strspn_variation1.phpt index 513046b62..e8fd9d3ac 100644 --- a/ext/standard/tests/strings/strspn_variation1.phpt +++ b/ext/standard/tests/strings/strspn_variation1.phpt @@ -1,275 +1,273 @@ ---TEST-- -Test strspn() function : usage variations - unexpected values for str argument ---FILE-- -<?php -/* Prototype : proto int strspn(string str, string mask [, int start [, int len]]) - * Description: Finds length of initial segment consisting entirely of characters found in mask. - If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) - * Source code: ext/standard/string.c - * Alias to functions: none -*/ - -/* -* Testing strspn() : with different unexpected values for str argument -*/ - -echo "*** Testing strspn() : with unexpected values for str argument ***\n"; - -// Initialise function arguments not being substititued (if any) -$mask = 'abons1234567890'; -$start = 1; -$len = 10; - - -//get an unset variable -$unset_var = 10; -unset ($unset_var); - -// declaring class -class sample { - public function __toString() { - return "object"; - } -} - -// creating a file resource -$file_handle = fopen(__FILE__, 'r'); - - -//array of values to iterate over -$values = array( - - // int data - 0, - 1, - 12345, - -2345, - - // float data - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array data - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red', 'item' => 'pen'), - - // null data - NULL, - null, - - // boolean data - true, - false, - TRUE, - FALSE, - - // empty data - "", - '', - - // object data - new sample, - - // undefined data - $undefined_var, - - // unset data - $unset_var, - - // resource - $file_handle -); - -// loop through each element of the array for str - -foreach($values as $value) { - echo "\n-- Iteration with str value as \"$value\" \n"; - var_dump( strspn($value,$mask) ); // with default args - var_dump( strspn($value,$mask,$start) ); // with default len value - var_dump( strspn($value,$mask,$start,$len) ); // with all args -}; - -// closing the resource -fclose($file_handle); - -echo "Done" -?> ---EXPECTF-- -*** Testing strspn() : with unexpected values for str argument *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration with str value as "0" -int(1) -int(0) -int(0) - --- Iteration with str value as "1" -int(1) -int(0) -int(0) - --- Iteration with str value as "12345" -int(5) -int(4) -int(4) - --- Iteration with str value as "-2345" -int(0) -int(4) -int(4) - --- Iteration with str value as "10.5" -int(2) -int(1) -int(1) - --- Iteration with str value as "-10.5" -int(0) -int(2) -int(2) - --- Iteration with str value as "105000000000" -int(12) -int(11) -int(10) - --- Iteration with str value as "1.06E-9" -int(1) -int(0) -int(0) - --- Iteration with str value as "0.5" -int(1) -int(0) -int(0) - --- Iteration with str value as "Array" - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "Array" - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, array given in %s on line %d -NULL - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "1" -int(1) -int(0) -int(0) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "1" -int(1) -int(0) -int(0) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "object" -int(2) -int(1) -int(1) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "" -int(0) -bool(false) -bool(false) - --- Iteration with str value as "Resource id #%d" - -Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d -NULL - -Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d -NULL -Done +--TEST--
+Test strspn() function : usage variations - unexpected values for str argument
+--FILE--
+<?php
+/* Prototype : proto int strspn(string str, string mask [, int start [, int len]])
+ * Description: Finds length of initial segment consisting entirely of characters found in mask.
+ If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars)
+ * Source code: ext/standard/string.c
+ * Alias to functions: none
+*/
+
+error_reporting(E_ALL & ~E_NOTICE);
+
+/*
+* Testing strspn() : with different unexpected values for str argument
+*/
+
+echo "*** Testing strspn() : with unexpected values for str argument ***\n";
+
+// Initialise function arguments not being substititued (if any)
+$mask = 'abons1234567890';
+$start = 1;
+$len = 10;
+
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// declaring class
+class sample {
+ public function __toString() {
+ return "object";
+ }
+}
+
+// creating a file resource
+$file_handle = fopen(__FILE__, 'r');
+
+
+//array of values to iterate over
+$values = array(
+
+ // int data
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array data
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red', 'item' => 'pen'),
+
+ // null data
+ NULL,
+ null,
+
+ // boolean data
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+ "",
+ '',
+
+ // object data
+ new sample,
+
+ // undefined data
+ $undefined_var,
+
+ // unset data
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+// loop through each element of the array for str
+
+foreach($values as $value) {
+ echo "\n-- Iteration with str value as \"$value\"\n";
+ var_dump( strspn($value,$mask) ); // with default args
+ var_dump( strspn($value,$mask,$start) ); // with default len value
+ var_dump( strspn($value,$mask,$start,$len) ); // with all args
+};
+
+// closing the resource
+fclose($file_handle);
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing strspn() : with unexpected values for str argument ***
+
+-- Iteration with str value as "0"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "1"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "12345"
+int(5)
+int(4)
+int(4)
+
+-- Iteration with str value as "-2345"
+int(0)
+int(4)
+int(4)
+
+-- Iteration with str value as "10.5"
+int(2)
+int(1)
+int(1)
+
+-- Iteration with str value as "-10.5"
+int(0)
+int(2)
+int(2)
+
+-- Iteration with str value as "101234567000"
+int(12)
+int(11)
+int(10)
+
+-- Iteration with str value as "1.07654321E-9"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "0.5"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as "Array"
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as "Array"
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "1"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "1"
+int(1)
+int(0)
+int(0)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "object"
+int(2)
+int(1)
+int(1)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as ""
+int(0)
+bool(false)
+bool(false)
+
+-- Iteration with str value as "Resource id #%d"
+
+Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+
+Warning: strspn() expects parameter 1 to be string, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strspn_variation2.phpt b/ext/standard/tests/strings/strspn_variation2.phpt index b8891a590..7af61e559 100644 --- a/ext/standard/tests/strings/strspn_variation2.phpt +++ b/ext/standard/tests/strings/strspn_variation2.phpt @@ -9,6 +9,8 @@ Test strspn() function : usage variations - unexpected values for mask argument * Alias to functions: none */ +error_reporting(E_ALL & ~E_NOTICE); + /* * Testing strspn() : with different unexpected values for mask argument */ @@ -47,8 +49,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array data @@ -88,7 +90,7 @@ $values = array( // loop through each element of the array for mask foreach($values as $value) { - echo "\n-- Iteration with mask value as \"$value\" -- \n"; + echo "\n-- Iteration with mask value as \"$value\" --\n"; var_dump( strspn($str,$value) ); // with defalut args var_dump( strspn($str,$value,$start) ); // with default len value var_dump( strspn($str,$value,$start,$len) ); // with all args @@ -102,56 +104,52 @@ echo "Done" --EXPECTF-- *** Testing strspn() : with diferent unexpected values of mask argument *** -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - --- Iteration with mask value as "0" -- +-- Iteration with mask value as "0" -- int(0) int(0) int(0) --- Iteration with mask value as "1" -- +-- Iteration with mask value as "1" -- int(0) int(0) int(0) --- Iteration with mask value as "12345" -- +-- Iteration with mask value as "12345" -- int(0) int(0) int(0) --- Iteration with mask value as "-2345" -- +-- Iteration with mask value as "-2345" -- int(0) int(0) int(0) --- Iteration with mask value as "10.5" -- +-- Iteration with mask value as "10.5" -- int(0) int(0) int(0) --- Iteration with mask value as "-10.5" -- +-- Iteration with mask value as "-10.5" -- int(0) int(0) int(0) --- Iteration with mask value as "105000000000" -- +-- Iteration with mask value as "101234567000" -- int(0) int(0) int(0) --- Iteration with mask value as "1.06E-9" -- +-- Iteration with mask value as "1.07654321E-9" -- int(0) int(0) int(0) --- Iteration with mask value as "0.5" -- +-- Iteration with mask value as "0.5" -- int(0) int(0) int(0) --- Iteration with mask value as "Array" -- +-- Iteration with mask value as "Array" -- Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL @@ -162,7 +160,7 @@ NULL Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL --- Iteration with mask value as "Array" -- +-- Iteration with mask value as "Array" -- Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL @@ -173,7 +171,7 @@ NULL Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL --- Iteration with mask value as "Array" -- +-- Iteration with mask value as "Array" -- Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL @@ -184,7 +182,7 @@ NULL Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL --- Iteration with mask value as "Array" -- +-- Iteration with mask value as "Array" -- Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL @@ -195,7 +193,7 @@ NULL Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL --- Iteration with mask value as "Array" -- +-- Iteration with mask value as "Array" -- Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL @@ -206,62 +204,62 @@ NULL Warning: strspn() expects parameter 2 to be string, array given in %s on line %d NULL --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "1" -- +-- Iteration with mask value as "1" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "1" -- +-- Iteration with mask value as "1" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "object" -- +-- Iteration with mask value as "object" -- int(0) int(1) int(1) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "" -- +-- Iteration with mask value as "" -- int(0) int(0) int(0) --- Iteration with mask value as "Resource id #%d" -- +-- Iteration with mask value as "Resource id #%d" -- Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d NULL @@ -271,4 +269,4 @@ NULL Warning: strspn() expects parameter 2 to be string, resource given in %s on line %d NULL -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strspn_variation3.phpt b/ext/standard/tests/strings/strspn_variation3.phpt index 0773bd3ad..3195220de 100644 --- a/ext/standard/tests/strings/strspn_variation3.phpt +++ b/ext/standard/tests/strings/strspn_variation3.phpt @@ -9,6 +9,8 @@ Test strspn() function : usage variations - unexpected values of start argument * Alias to functions: none */ +error_reporting(E_ALL & ~E_NOTICE); + /* * Testing strspn() : with unexpected values of start argument */ @@ -41,8 +43,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e8, + 10.7654321E-8, .5, // array data @@ -99,10 +101,6 @@ echo "Done" --EXPECTF-- *** Testing strspn() : with unexpected values of start argument *** -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - -- Iteration with start value as "10.5" -- int(0) int(0) @@ -111,11 +109,11 @@ int(0) int(2) int(2) --- Iteration with start value as "105000000000" -- +-- Iteration with start value as "1012345670" -- bool(false) bool(false) --- Iteration with start value as "1.06E-9" -- +-- Iteration with start value as "1.07654321E-7" -- int(2) int(2) @@ -242,4 +240,4 @@ NULL Warning: strspn() expects parameter 3 to be long, resource given in %s on line %d NULL -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strspn_variation4.phpt b/ext/standard/tests/strings/strspn_variation4.phpt index dd21a1d0f..87dceac3b 100644 --- a/ext/standard/tests/strings/strspn_variation4.phpt +++ b/ext/standard/tests/strings/strspn_variation4.phpt @@ -9,6 +9,8 @@ Test strspn() function : usage variations - unexpected values of len argument * Alias to functions: none */ +error_reporting(E_ALL & ~E_NOTICE); + /* * Testing strspn() : with unexpected values of len argument */ @@ -41,8 +43,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e8, + 10.7654321E-8, .5, // array data @@ -98,20 +100,16 @@ echo "Done" --EXPECTF-- *** Testing strspn() : with unexpected values of len argument *** -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - -- Iteration with len value as "10.5" -- int(2) -- Iteration with len value as "-10.5" -- int(0) --- Iteration with len value as "105000000000" -- +-- Iteration with len value as "1012345670" -- int(2) --- Iteration with len value as "1.06E-9" -- +-- Iteration with len value as "1.07654321E-7" -- int(0) -- Iteration with len value as "0.5" -- @@ -195,4 +193,4 @@ int(0) Warning: strspn() expects parameter 4 to be long, resource given in %s on line %d NULL -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt Binary files differindex ab10c9efb..8c76c65d7 100644 --- a/ext/standard/tests/strings/strstr.phpt +++ b/ext/standard/tests/strings/strstr.phpt diff --git a/ext/standard/tests/strings/strtok_variation1.phpt b/ext/standard/tests/strings/strtok_variation1.phpt index 3c754c88a..426ab535b 100644 --- a/ext/standard/tests/strings/strtok_variation1.phpt +++ b/ext/standard/tests/strings/strtok_variation1.phpt @@ -1,172 +1,172 @@ ---TEST-- -Test strtok() function : usage variations - first argument as non-string ---FILE-- -<?php -/* Prototype : string strtok ( string $str, string $token ) - * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token - * Source code: ext/standard/string.c -*/ - -/* - * Testing strtok() : with first argument as non-string -*/ - -echo "*** Testing strtok() : with first argument as non-string ***\n"; -// initialize all required variables -$token = '-'; - -// get an unset variable -$unset_var = 'string_val'; -unset($unset_var); - -// declaring a class -class sample { - public function __toString() { - return "obj-ect"; - } -} - -// Defining resource -$file_handle = fopen(__FILE__, 'r'); - -// array with different values -$values = array ( - - // integer values - 0, - 1, - 12345, - -2345, - - // float values - 10.5, - -10.5, - 10.5e10, - 10.6E-10, - .5, - - // array values - array(), - array(0), - array(1), - array(1, 2), - array('color' => 'red-color', 'item' => 'pen-color'), - - // boolean values - true, - false, - TRUE, - FALSE, - - // objects - new sample(), - - // empty string - "", - '', - - // null vlaues - NULL, - null, - - // undefined variable - $undefined_var, - - // unset variable - $unset_var, - - // resource - $file_handle -); - - -// loop through each element of the array and check the working of strtok() -// when $str arugment is supplied with different values - -echo "\n--- Testing strtok() by supplying different values for 'str' argument ---\n"; -$counter = 1; -for($index = 0; $index < count($values); $index ++) { - echo "-- Iteration $counter --\n"; - $str = $values [$index]; - - var_dump( strtok($str, $token) ); - - $counter ++; -} - -//closing the resource -fclose($file_handle); - -echo "Done\n"; -?> ---EXPECTF-- -*** Testing strtok() : with first argument as non-string *** - -Notice: Undefined variable: undefined_var in %s on line %d - -Notice: Undefined variable: unset_var in %s on line %d - ---- Testing strtok() by supplying different values for 'str' argument --- --- Iteration 1 -- -string(1) "0" --- Iteration 2 -- -string(1) "1" --- Iteration 3 -- -string(5) "12345" --- Iteration 4 -- -string(4) "2345" --- Iteration 5 -- -string(4) "10.5" --- Iteration 6 -- -string(4) "10.5" --- Iteration 7 -- -string(12) "105000000000" --- Iteration 8 -- -string(5) "1.06E" --- Iteration 9 -- -string(3) "0.5" --- Iteration 10 -- - -Notice: Array to string conversion in %s on line %d -string(5) "Array" --- Iteration 11 -- - -Notice: Array to string conversion in %s on line %d -string(5) "Array" --- Iteration 12 -- - -Notice: Array to string conversion in %s on line %d -string(5) "Array" --- Iteration 13 -- - -Notice: Array to string conversion in %s on line %d -string(5) "Array" --- Iteration 14 -- - -Notice: Array to string conversion in %s on line %d -string(5) "Array" --- Iteration 15 -- -string(1) "1" --- Iteration 16 -- -bool(false) --- Iteration 17 -- -string(1) "1" --- Iteration 18 -- -bool(false) --- Iteration 19 -- -string(3) "obj" --- Iteration 20 -- -bool(false) --- Iteration 21 -- -bool(false) --- Iteration 22 -- -bool(false) --- Iteration 23 -- -bool(false) --- Iteration 24 -- -bool(false) --- Iteration 25 -- -bool(false) --- Iteration 26 -- -string(%d) "Resource id #%d" -Done +--TEST--
+Test strtok() function : usage variations - first argument as non-string
+--FILE--
+<?php
+/* Prototype : string strtok ( string $str, string $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with first argument as non-string
+*/
+
+echo "*** Testing strtok() : with first argument as non-string ***\n";
+// initialize all required variables
+$token = '-';
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring a class
+class sample {
+ public function __toString() {
+ return "obj-ect";
+ }
+}
+
+// Defining resource
+$file_handle = fopen(__FILE__, 'r');
+
+// array with different values
+$values = array (
+
+ // integer values
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float values
+ 10.5,
+ -10.5,
+ 10.1234567e10,
+ 10.7654321E-10,
+ .5,
+
+ // array values
+ array(),
+ array(0),
+ array(1),
+ array(1, 2),
+ array('color' => 'red-color', 'item' => 'pen-color'),
+
+ // boolean values
+ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // objects
+ new sample(),
+
+ // empty string
+ "",
+ '',
+
+ // null vlaues
+ NULL,
+ null,
+
+ // undefined variable
+ $undefined_var,
+
+ // unset variable
+ $unset_var,
+
+ // resource
+ $file_handle
+);
+
+
+// loop through each element of the array and check the working of strtok()
+// when $str arugment is supplied with different values
+
+echo "\n--- Testing strtok() by supplying different values for 'str' argument ---\n";
+$counter = 1;
+for($index = 0; $index < count($values); $index ++) {
+ echo "-- Iteration $counter --\n";
+ $str = $values [$index];
+
+ var_dump( strtok($str, $token) );
+
+ $counter ++;
+}
+
+//closing the resource
+fclose($file_handle);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing strtok() : with first argument as non-string ***
+
+Notice: Undefined variable: undefined_var in %s on line %d
+
+Notice: Undefined variable: unset_var in %s on line %d
+
+--- Testing strtok() by supplying different values for 'str' argument ---
+-- Iteration 1 --
+string(1) "0"
+-- Iteration 2 --
+string(1) "1"
+-- Iteration 3 --
+string(5) "12345"
+-- Iteration 4 --
+string(4) "2345"
+-- Iteration 5 --
+string(4) "10.5"
+-- Iteration 6 --
+string(4) "10.5"
+-- Iteration 7 --
+string(12) "101234567000"
+-- Iteration 8 --
+string(11) "1.07654321E"
+-- Iteration 9 --
+string(3) "0.5"
+-- Iteration 10 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 11 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 12 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 13 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 14 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 15 --
+string(1) "1"
+-- Iteration 16 --
+bool(false)
+-- Iteration 17 --
+string(1) "1"
+-- Iteration 18 --
+bool(false)
+-- Iteration 19 --
+string(3) "obj"
+-- Iteration 20 --
+bool(false)
+-- Iteration 21 --
+bool(false)
+-- Iteration 22 --
+bool(false)
+-- Iteration 23 --
+bool(false)
+-- Iteration 24 --
+bool(false)
+-- Iteration 25 --
+bool(false)
+-- Iteration 26 --
+string(%d) "Resource id #%d"
+Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/ucwords_variation1.phpt b/ext/standard/tests/strings/ucwords_variation1.phpt index 2a3ceeeb8..b7d61ab5d 100644 --- a/ext/standard/tests/strings/ucwords_variation1.phpt +++ b/ext/standard/tests/strings/ucwords_variation1.phpt @@ -49,8 +49,8 @@ $values = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -139,9 +139,9 @@ string(4) "10.5" -- Iteration 12 -- string(5) "-10.5" -- Iteration 13 -- -string(12) "105000000000" +string(12) "101234567000" -- Iteration 14 -- -string(7) "1.06E-9" +string(13) "1.07654321E-9" -- Iteration 15 -- string(3) "0.5" -- Iteration 16 -- @@ -162,7 +162,7 @@ Notice: Array to string conversion in %s on line %d string(5) "Array" -- Iteration 20 -- -Notice: Array to string conversion in %s on line %d +Notice: Array to string conversion in %s on line 101 string(5) "Array" -- Iteration 21 -- string(1) "1" @@ -196,4 +196,4 @@ string(0) "" string(0) "" -- Iteration 36 -- string(%d) "Resource Id #%d" -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/vsprintf_variation1.phpt b/ext/standard/tests/strings/vsprintf_variation1.phpt index eb0284540..391158762 100644 --- a/ext/standard/tests/strings/vsprintf_variation1.phpt +++ b/ext/standard/tests/strings/vsprintf_variation1.phpt @@ -45,8 +45,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array data @@ -120,10 +120,10 @@ string(4) "10.5" string(5) "-10.5" -- Iteration 7 -- -string(12) "105000000000" +string(12) "101234567000" -- Iteration 8 -- -string(7) "1.06E-9" +string(13) "1.07654321E-9" -- Iteration 9 -- string(3) "0.5" diff --git a/ext/standard/tests/strings/vsprintf_variation2.phpt b/ext/standard/tests/strings/vsprintf_variation2.phpt index fbc1e8634..acf4bea9e 100644 --- a/ext/standard/tests/strings/vsprintf_variation2.phpt +++ b/ext/standard/tests/strings/vsprintf_variation2.phpt @@ -45,8 +45,8 @@ $values = array( // float data 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // null data @@ -115,10 +115,10 @@ string(4) "10.5" string(5) "-10.5" -- Iteration 7 -- -string(12) "105000000000" +string(12) "101234567000" -- Iteration 8 -- -string(7) "1.06E-9" +string(13) "1.07654321E-9" -- Iteration 9 -- string(3) "0.5" @@ -174,4 +174,4 @@ bool(false) -- Iteration 23 -- string(%d) "Resource id #%d" -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/wordwrap_variation1.phpt b/ext/standard/tests/strings/wordwrap_variation1.phpt index f5a172e9a..d13e7dee2 100644 --- a/ext/standard/tests/strings/wordwrap_variation1.phpt +++ b/ext/standard/tests/strings/wordwrap_variation1.phpt @@ -36,8 +36,8 @@ $values = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -143,17 +143,17 @@ string(5) "-10.5" string(5) "-10.5" string(13) "-10<br />\n.5" -- Iteration 7 -- -string(12) "105000000000" -string(12) "105000000000" -string(12) "105000000000" -string(12) "105000000000" -string(36) "105<br />\n000<br />\n000<br />\n000" +string(12) "101234567000" +string(12) "101234567000" +string(12) "101234567000" +string(12) "101234567000" +string(36) "101<br />\n234<br />\n567<br />\n000" -- Iteration 8 -- -string(7) "1.06E-9" -string(7) "1.06E-9" -string(7) "1.06E-9" -string(7) "1.06E-9" -string(23) "1.0<br />\n6E-<br />\n9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" +string(13) "1.07654321E-9" +string(45) "1.0<br />\n765<br />\n432<br />\n1E-<br />\n9" -- Iteration 9 -- string(3) "0.5" string(3) "0.5" @@ -332,4 +332,4 @@ string(0) "" string(0) "" string(0) "" string(0) "" -Done +Done
\ No newline at end of file diff --git a/ext/standard/tests/strings/wordwrap_variation3.phpt b/ext/standard/tests/strings/wordwrap_variation3.phpt index 0a71944b4..2f83add7b 100644 --- a/ext/standard/tests/strings/wordwrap_variation3.phpt +++ b/ext/standard/tests/strings/wordwrap_variation3.phpt @@ -37,8 +37,8 @@ $values = array ( // float values 10.5, -10.5, - 10.5e10, - 10.6E-10, + 10.1234567e10, + 10.7654321E-10, .5, // array values @@ -130,13 +130,13 @@ string(33) "testing-10.5wordwrap-10.5function" string(33) "testing-10.5wordwrap-10.5function" string(33) "testing-10.5wordwrap-10.5function" -- Iteration 7 -- -string(47) "testing105000000000wordwrap105000000000function" -string(47) "testing105000000000wordwrap105000000000function" -string(47) "testing105000000000wordwrap105000000000function" +string(47) "testing101234567000wordwrap101234567000function" +string(47) "testing101234567000wordwrap101234567000function" +string(47) "testing101234567000wordwrap101234567000function" -- Iteration 8 -- -string(37) "testing1.06E-9wordwrap1.06E-9function" -string(37) "testing1.06E-9wordwrap1.06E-9function" -string(37) "testing1.06E-9wordwrap1.06E-9function" +string(49) "testing1.07654321E-9wordwrap1.07654321E-9function" +string(49) "testing1.07654321E-9wordwrap1.07654321E-9function" +string(49) "testing1.07654321E-9wordwrap1.07654321E-9function" -- Iteration 9 -- string(29) "testing0.5wordwrap0.5function" string(29) "testing0.5wordwrap0.5function" diff --git a/ext/standard/tests/url/base64_decode_basic_001.phpt b/ext/standard/tests/url/base64_decode_basic_001.phpt new file mode 100644 index 000000000..7aba807e1 --- /dev/null +++ b/ext/standard/tests/url/base64_decode_basic_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test base64_decode() function : basic functionality - ensure all base64 alphabet is supported. +--FILE-- +<?php +/* Prototype : proto string base64_decode(string str[, bool strict]) + * Description: Decodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +echo "Decode an input string containing the whole base64 alphabet:\n"; +$allbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +var_dump(bin2hex(base64_decode($allbase64))); +var_dump(bin2hex(base64_decode($allbase64, false))); +var_dump(bin2hex(base64_decode($allbase64, true))); + +echo "Done"; +?> +--EXPECTF-- +Decode an input string containing the whole base64 alphabet: +string(96) "00108310518720928b30d38f41149351559761969b71d79f8218a39259a7a29aabb2dbafc31cb3d35db7e39ebbf3dfbf" +string(96) "00108310518720928b30d38f41149351559761969b71d79f8218a39259a7a29aabb2dbafc31cb3d35db7e39ebbf3dfbf" +string(96) "00108310518720928b30d38f41149351559761969b71d79f8218a39259a7a29aabb2dbafc31cb3d35db7e39ebbf3dfbf" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/base64_decode_basic_002.phpt b/ext/standard/tests/url/base64_decode_basic_002.phpt new file mode 100644 index 000000000..1289894f4 --- /dev/null +++ b/ext/standard/tests/url/base64_decode_basic_002.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test base64_decode() function : basic functionality - strict vs non-strict with non-base64 chars. +--FILE-- +<?php +/* Prototype : proto string base64_decode(string str[, bool strict]) + * Description: Decodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +echo "Decode 'hello world!':\n"; +$noWhiteSpace = "aGVsbG8gd29ybGQh"; +var_dump(base64_decode($noWhiteSpace)); +var_dump(base64_decode($noWhiteSpace, false)); +var_dump(base64_decode($noWhiteSpace, true)); + +echo "\nWhitespace does not affect base64_decode, even with \$strict===true:\n"; +$withWhiteSpace = "a GVs bG8gd2 + 9ybGQh"; +var_dump(base64_decode($withWhiteSpace)); +var_dump(base64_decode($withWhiteSpace, false)); +var_dump(base64_decode($withWhiteSpace, true)); + +echo "\nOther chars outside the base64 alphabet are ignored when \$strict===false, but cause failure with \$strict===true:\n"; +$badChars = $noWhiteSpace . '*'; +var_dump(base64_decode($badChars)); +var_dump(base64_decode($badChars, false)); +var_dump(base64_decode($badChars, true)); + +echo "Done"; +?> +--EXPECTF-- +Decode 'hello world!': +string(12) "hello world!" +string(12) "hello world!" +string(12) "hello world!" + +Whitespace does not affect base64_decode, even with $strict===true: +string(12) "hello world!" +string(12) "hello world!" +string(12) "hello world!" + +Other chars outside the base64 alphabet are ignored when $strict===false, but cause failure with $strict===true: +string(12) "hello world!" +string(12) "hello world!" +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/base64_decode_error_001.phpt b/ext/standard/tests/url/base64_decode_error_001.phpt new file mode 100644 index 000000000..272516446 --- /dev/null +++ b/ext/standard/tests/url/base64_decode_error_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test base64_decode() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto string base64_decode(string str[, bool strict]) + * Description: Decodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +echo "*** Testing base64_decode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing base64_decode() function with Zero arguments --\n"; +var_dump( base64_decode() ); + +//Test base64_decode with one more than the expected number of arguments +echo "\n-- Testing base64_decode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$strict = true; +$extra_arg = 10; +var_dump( base64_decode($str, $strict, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_decode() : error conditions *** + +-- Testing base64_decode() function with Zero arguments -- + +Warning: base64_decode() expects at least 1 parameter, 0 given in %s on line 12 +NULL + +-- Testing base64_decode() function with more than expected no. of arguments -- + +Warning: base64_decode() expects at most 2 parameters, 3 given in %s on line 19 +NULL +Done diff --git a/ext/standard/tests/url/base64_decode_variation_001.phpt b/ext/standard/tests/url/base64_decode_variation_001.phpt new file mode 100644 index 000000000..b01cd23e5 --- /dev/null +++ b/ext/standard/tests/url/base64_decode_variation_001.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test base64_decode() function : usage variations - unexpected types for arg 1 +--FILE-- +<?php +/* Prototype : proto string base64_decode(string str[, bool strict]) + * Description: Decodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing base64_decode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$strict = true; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( base64_decode($value, $strict) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_decode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(63) +Error: 8 - Undefined variable: unset_var, %s(66) + +Arg value 0 +string(0) "" + +Arg value 1 +string(0) "" + +Arg value 12345 +string(3) "×mø" + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +string(9) "×MvߎzïM4" + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(72) + +Arg value +Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(73) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done diff --git a/ext/standard/tests/url/base64_decode_variation_002.phpt b/ext/standard/tests/url/base64_decode_variation_002.phpt new file mode 100644 index 000000000..145784a4e --- /dev/null +++ b/ext/standard/tests/url/base64_decode_variation_002.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test base64_decode() function : usage variations - unexpected types for arg 2 +--FILE-- +<?php +/* Prototype : proto string base64_decode(string str[, bool strict]) + * Description: Decodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing base64_decode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$str = 'aGVsbG8gd29ybGQh!'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for strict + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( base64_decode($str, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_decode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(67) +Error: 8 - Undefined variable: unset_var, %s(70) + +Arg value 0 +string(12) "hello world!" + +Arg value 1 +bool(false) + +Arg value 12345 +bool(false) + +Arg value -2345 +bool(false) + +Arg value 10.5 +bool(false) + +Arg value -10.5 +bool(false) + +Arg value 101234567000 +bool(false) + +Arg value 1.07654321E-9 +bool(false) + +Arg value 0.5 +bool(false) + +Arg value Array +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +NULL + +Arg value Array +Error: 2 - base64_decode() expects parameter 2 to be boolean, array given, %s(77) +NULL + +Arg value +string(12) "hello world!" + +Arg value +string(12) "hello world!" + +Arg value 1 +bool(false) + +Arg value +string(12) "hello world!" + +Arg value 1 +bool(false) + +Arg value +string(12) "hello world!" + +Arg value +string(12) "hello world!" + +Arg value +string(12) "hello world!" + +Arg value string +bool(false) + +Arg value string +bool(false) +Error: 4096 - Object of class stdClass could not be converted to string, %s(76) + +Arg value +Error: 2 - base64_decode() expects parameter 2 to be boolean, object given, %s(77) +NULL + +Arg value +string(12) "hello world!" + +Arg value +string(12) "hello world!" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/base64_encode_basic_001.phpt b/ext/standard/tests/url/base64_encode_basic_001.phpt new file mode 100644 index 000000000..6ab57f4c5 --- /dev/null +++ b/ext/standard/tests/url/base64_encode_basic_001.phpt @@ -0,0 +1,283 @@ +--TEST-- +Test base64_encode() function : basic functionality +--FILE-- +<?php +/* Prototype : proto string base64_encode(string str) + * Description: Encodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +/* + * Test base64_encode with single byte values. + */ + +echo "*** Testing base64_encode() : basic functionality ***\n"; + +for ($i=0; $i<256; $i++) { + $str = pack("c", $i); + $enc = base64_encode($str); + printf("0x%X: %s\n", $i, $enc); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_encode() : basic functionality *** +0x0: AA== +0x1: AQ== +0x2: Ag== +0x3: Aw== +0x4: BA== +0x5: BQ== +0x6: Bg== +0x7: Bw== +0x8: CA== +0x9: CQ== +0xA: Cg== +0xB: Cw== +0xC: DA== +0xD: DQ== +0xE: Dg== +0xF: Dw== +0x10: EA== +0x11: EQ== +0x12: Eg== +0x13: Ew== +0x14: FA== +0x15: FQ== +0x16: Fg== +0x17: Fw== +0x18: GA== +0x19: GQ== +0x1A: Gg== +0x1B: Gw== +0x1C: HA== +0x1D: HQ== +0x1E: Hg== +0x1F: Hw== +0x20: IA== +0x21: IQ== +0x22: Ig== +0x23: Iw== +0x24: JA== +0x25: JQ== +0x26: Jg== +0x27: Jw== +0x28: KA== +0x29: KQ== +0x2A: Kg== +0x2B: Kw== +0x2C: LA== +0x2D: LQ== +0x2E: Lg== +0x2F: Lw== +0x30: MA== +0x31: MQ== +0x32: Mg== +0x33: Mw== +0x34: NA== +0x35: NQ== +0x36: Ng== +0x37: Nw== +0x38: OA== +0x39: OQ== +0x3A: Og== +0x3B: Ow== +0x3C: PA== +0x3D: PQ== +0x3E: Pg== +0x3F: Pw== +0x40: QA== +0x41: QQ== +0x42: Qg== +0x43: Qw== +0x44: RA== +0x45: RQ== +0x46: Rg== +0x47: Rw== +0x48: SA== +0x49: SQ== +0x4A: Sg== +0x4B: Sw== +0x4C: TA== +0x4D: TQ== +0x4E: Tg== +0x4F: Tw== +0x50: UA== +0x51: UQ== +0x52: Ug== +0x53: Uw== +0x54: VA== +0x55: VQ== +0x56: Vg== +0x57: Vw== +0x58: WA== +0x59: WQ== +0x5A: Wg== +0x5B: Ww== +0x5C: XA== +0x5D: XQ== +0x5E: Xg== +0x5F: Xw== +0x60: YA== +0x61: YQ== +0x62: Yg== +0x63: Yw== +0x64: ZA== +0x65: ZQ== +0x66: Zg== +0x67: Zw== +0x68: aA== +0x69: aQ== +0x6A: ag== +0x6B: aw== +0x6C: bA== +0x6D: bQ== +0x6E: bg== +0x6F: bw== +0x70: cA== +0x71: cQ== +0x72: cg== +0x73: cw== +0x74: dA== +0x75: dQ== +0x76: dg== +0x77: dw== +0x78: eA== +0x79: eQ== +0x7A: eg== +0x7B: ew== +0x7C: fA== +0x7D: fQ== +0x7E: fg== +0x7F: fw== +0x80: gA== +0x81: gQ== +0x82: gg== +0x83: gw== +0x84: hA== +0x85: hQ== +0x86: hg== +0x87: hw== +0x88: iA== +0x89: iQ== +0x8A: ig== +0x8B: iw== +0x8C: jA== +0x8D: jQ== +0x8E: jg== +0x8F: jw== +0x90: kA== +0x91: kQ== +0x92: kg== +0x93: kw== +0x94: lA== +0x95: lQ== +0x96: lg== +0x97: lw== +0x98: mA== +0x99: mQ== +0x9A: mg== +0x9B: mw== +0x9C: nA== +0x9D: nQ== +0x9E: ng== +0x9F: nw== +0xA0: oA== +0xA1: oQ== +0xA2: og== +0xA3: ow== +0xA4: pA== +0xA5: pQ== +0xA6: pg== +0xA7: pw== +0xA8: qA== +0xA9: qQ== +0xAA: qg== +0xAB: qw== +0xAC: rA== +0xAD: rQ== +0xAE: rg== +0xAF: rw== +0xB0: sA== +0xB1: sQ== +0xB2: sg== +0xB3: sw== +0xB4: tA== +0xB5: tQ== +0xB6: tg== +0xB7: tw== +0xB8: uA== +0xB9: uQ== +0xBA: ug== +0xBB: uw== +0xBC: vA== +0xBD: vQ== +0xBE: vg== +0xBF: vw== +0xC0: wA== +0xC1: wQ== +0xC2: wg== +0xC3: ww== +0xC4: xA== +0xC5: xQ== +0xC6: xg== +0xC7: xw== +0xC8: yA== +0xC9: yQ== +0xCA: yg== +0xCB: yw== +0xCC: zA== +0xCD: zQ== +0xCE: zg== +0xCF: zw== +0xD0: 0A== +0xD1: 0Q== +0xD2: 0g== +0xD3: 0w== +0xD4: 1A== +0xD5: 1Q== +0xD6: 1g== +0xD7: 1w== +0xD8: 2A== +0xD9: 2Q== +0xDA: 2g== +0xDB: 2w== +0xDC: 3A== +0xDD: 3Q== +0xDE: 3g== +0xDF: 3w== +0xE0: 4A== +0xE1: 4Q== +0xE2: 4g== +0xE3: 4w== +0xE4: 5A== +0xE5: 5Q== +0xE6: 5g== +0xE7: 5w== +0xE8: 6A== +0xE9: 6Q== +0xEA: 6g== +0xEB: 6w== +0xEC: 7A== +0xED: 7Q== +0xEE: 7g== +0xEF: 7w== +0xF0: 8A== +0xF1: 8Q== +0xF2: 8g== +0xF3: 8w== +0xF4: 9A== +0xF5: 9Q== +0xF6: 9g== +0xF7: 9w== +0xF8: +A== +0xF9: +Q== +0xFA: +g== +0xFB: +w== +0xFC: /A== +0xFD: /Q== +0xFE: /g== +0xFF: /w== +Done diff --git a/ext/standard/tests/url/base64_encode_error_001.phpt b/ext/standard/tests/url/base64_encode_error_001.phpt new file mode 100644 index 000000000..a8883ac8f --- /dev/null +++ b/ext/standard/tests/url/base64_encode_error_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test base64_encode() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto string base64_encode(string str) + * Description: Encodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +echo "*** Testing base64_encode() : error conditions - wrong number of args ***\n"; + +// Zero arguments +echo "\n-- Testing base64_encode() function with Zero arguments --\n"; +var_dump( base64_encode() ); + +//Test base64_encode with one more than the expected number of arguments +echo "\n-- Testing base64_encode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( base64_encode($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_encode() : error conditions - wrong number of args *** + +-- Testing base64_encode() function with Zero arguments -- + +Warning: base64_encode() expects exactly 1 parameter, 0 given in %s on line 12 +NULL + +-- Testing base64_encode() function with more than expected no. of arguments -- + +Warning: base64_encode() expects exactly 1 parameter, 2 given in %s on line 18 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/base64_encode_variation_001.phpt b/ext/standard/tests/url/base64_encode_variation_001.phpt new file mode 100644 index 000000000..30da145a8 --- /dev/null +++ b/ext/standard/tests/url/base64_encode_variation_001.phpt @@ -0,0 +1,167 @@ +--TEST-- +Test base64_encode() function : usage variations - unexpected types for argument 1 +--FILE-- +<?php +/* Prototype : proto string base64_encode(string str) + * Description: Encodes string using MIME base64 algorithm + * Source code: ext/standard/base64.c + * Alias to functions: + */ + +echo "*** Testing base64_encode() : usage variations ***\n"; + + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( base64_encode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing base64_encode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(63) +Error: 8 - Undefined variable: unset_var, %s(66) + +Arg value 0 +string(4) "MA==" + +Arg value 1 +string(4) "MQ==" + +Arg value 12345 +string(8) "MTIzNDU=" + +Arg value -2345 +string(8) "LTIzNDU=" + +Arg value 10.5 +string(8) "MTAuNQ==" + +Arg value -10.5 +string(8) "LTEwLjU=" + +Arg value 101234567000 +string(16) "MTAxMjM0NTY3MDAw" + +Arg value 1.07654321E-9 +string(20) "MS4wNzY1NDMyMUUtOQ==" + +Arg value 0.5 +string(4) "MC41" + +Arg value Array +Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value Array +Error: 2 - base64_encode() expects parameter 1 to be string, array given, %s(73) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(4) "MQ==" + +Arg value +string(0) "" + +Arg value 1 +string(4) "MQ==" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(72) + +Arg value +Error: 2 - base64_encode() expects parameter 1 to be string, object given, %s(73) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done diff --git a/ext/standard/tests/url/parse_url_basic_001.phpt b/ext/standard/tests/url/parse_url_basic_001.phpt new file mode 100644 index 000000000..3d50689a4 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_001.phpt @@ -0,0 +1,899 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying the component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying the component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "\n--> $url: "; + var_dump(parse_url($url)); +} + +echo "Done"; +?> +--EXPECTF-- + +--> 64.246.30.37: array(1) { + ["path"]=> + string(12) "64.246.30.37" +} + +--> http://64.246.30.37: array(2) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(12) "64.246.30.37" +} + +--> http://64.246.30.37/: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(12) "64.246.30.37" + ["path"]=> + string(1) "/" +} + +--> 64.246.30.37/: array(1) { + ["path"]=> + string(13) "64.246.30.37/" +} + +--> 64.246.30.37:80/: array(3) { + ["host"]=> + string(12) "64.246.30.37" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" +} + +--> php.net: array(1) { + ["path"]=> + string(7) "php.net" +} + +--> php.net/: array(1) { + ["path"]=> + string(8) "php.net/" +} + +--> http://php.net: array(2) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(7) "php.net" +} + +--> http://php.net/: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(7) "php.net" + ["path"]=> + string(1) "/" +} + +--> www.php.net: array(1) { + ["path"]=> + string(11) "www.php.net" +} + +--> www.php.net/: array(1) { + ["path"]=> + string(12) "www.php.net/" +} + +--> http://www.php.net: array(2) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" +} + +--> http://www.php.net/: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(1) "/" +} + +--> www.php.net:80: array(2) { + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) +} + +--> http://www.php.net:80: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) +} + +--> http://www.php.net:80/: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" +} + +--> http://www.php.net/index.php: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(10) "/index.php" +} + +--> www.php.net/?: array(1) { + ["path"]=> + string(12) "www.php.net/" +} + +--> www.php.net:80/?: array(3) { + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" +} + +--> http://www.php.net/?: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(1) "/" +} + +--> http://www.php.net:80/?: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" +} + +--> http://www.php.net:80/index.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" +} + +--> http://www.php.net:80/foo/bar/index.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(18) "/foo/bar/index.php" +} + +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(53) "/this/is/a/very/deep/directory/structure/and/file.php" +} + +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(53) "/this/is/a/very/deep/directory/structure/and/file.php" + ["query"]=> + string(37) "lots=1&of=2¶meters=3&too=4&here=5" +} + +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(45) "/this/is/a/very/deep/directory/structure/and/" +} + +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(53) "/this/is/a/very/deep/directory/structure/and/file.php" +} + +--> http://www.php.net:80/this/../a/../deep/directory: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(28) "/this/../a/../deep/directory" +} + +--> http://www.php.net:80/this/../a/../deep/directory/: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(29) "/this/../a/../deep/directory/" +} + +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(42) "/this/is/a/very/deep/directory/../file.php" +} + +--> http://www.php.net:80/index.php: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" +} + +--> http://www.php.net:80/index.php?: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" +} + +--> http://www.php.net:80/#foo: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" + ["fragment"]=> + string(3) "foo" +} + +--> http://www.php.net:80/?#: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" +} + +--> http://www.php.net:80/?test=1: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" + ["query"]=> + string(6) "test=1" +} + +--> http://www.php.net/?test=1&: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(1) "/" + ["query"]=> + string(7) "test=1&" +} + +--> http://www.php.net:80/?&: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(1) "/" + ["query"]=> + string(1) "&" +} + +--> http://www.php.net:80/index.php?test=1&: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(7) "test=1&" +} + +--> http://www.php.net/index.php?&: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(1) "&" +} + +--> http://www.php.net:80/index.php?foo&: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(4) "foo&" +} + +--> http://www.php.net/index.php?&foo: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(4) "&foo" +} + +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI: array(5) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" +} + +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(5) { + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(6) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["user"]=> + string(6) "secret" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(14) "secret@hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hid:out" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +--> nntp://news.php.net: array(2) { + ["scheme"]=> + string(4) "nntp" + ["host"]=> + string(12) "news.php.net" +} + +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz: array(3) { + ["scheme"]=> + string(3) "ftp" + ["host"]=> + string(11) "ftp.gnu.org" + ["path"]=> + string(22) "/gnu/glic/glibc.tar.gz" +} + +--> zlib:http://foo@bar: array(2) { + ["scheme"]=> + string(4) "zlib" + ["path"]=> + string(14) "http://foo@bar" +} + +--> zlib:filename.txt: array(2) { + ["scheme"]=> + string(4) "zlib" + ["path"]=> + string(12) "filename.txt" +} + +--> zlib:/path/to/my/file/file.txt: array(2) { + ["scheme"]=> + string(4) "zlib" + ["path"]=> + string(25) "/path/to/my/file/file.txt" +} + +--> foo://foo@bar: array(3) { + ["scheme"]=> + string(3) "foo" + ["host"]=> + string(3) "bar" + ["user"]=> + string(3) "foo" +} + +--> mailto:me@mydomain.com: array(2) { + ["scheme"]=> + string(6) "mailto" + ["path"]=> + string(15) "me@mydomain.com" +} + +--> /foo.php?a=b&c=d: array(2) { + ["path"]=> + string(8) "/foo.php" + ["query"]=> + string(7) "a=b&c=d" +} + +--> foo.php?a=b&c=d: array(2) { + ["path"]=> + string(7) "foo.php" + ["query"]=> + string(7) "a=b&c=d" +} + +--> http://user:passwd@www.example.com:8080?bar=1&boom=0: array(6) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(15) "www.example.com" + ["port"]=> + int(8080) + ["user"]=> + string(4) "user" + ["pass"]=> + string(6) "passwd" + ["query"]=> + string(12) "bar=1&boom=0" +} + +--> file:///path/to/file: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(13) "/path/to/file" +} + +--> file://path/to/file: array(3) { + ["scheme"]=> + string(4) "file" + ["host"]=> + string(4) "path" + ["path"]=> + string(8) "/to/file" +} + +--> file:/path/to/file: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(13) "/path/to/file" +} + +--> http://1.2.3.4:/abc.asp?a=1&b=2: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(7) "1.2.3.4" + ["path"]=> + string(8) "/abc.asp" + ["query"]=> + string(7) "a=1&b=2" +} + +--> http://foo.com#bar: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(7) "foo.com" + ["fragment"]=> + string(3) "bar" +} + +--> scheme:: array(1) { + ["scheme"]=> + string(6) "scheme" +} + +--> foo+bar://baz@bang/bla: array(4) { + ["scheme"]=> + string(7) "foo+bar" + ["host"]=> + string(4) "bang" + ["user"]=> + string(3) "baz" + ["path"]=> + string(4) "/bla" +} + +--> gg:9130731: array(2) { + ["scheme"]=> + string(2) "gg" + ["path"]=> + string(7) "9130731" +} + +--> http://user:@pass@host/path?argument?value#etc: array(7) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(4) "host" + ["user"]=> + string(4) "user" + ["pass"]=> + string(5) "@pass" + ["path"]=> + string(5) "/path" + ["query"]=> + string(14) "argument?value" + ["fragment"]=> + string(3) "etc" +} + +--> http://10.10.10.10/:80: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "10.10.10.10" + ["path"]=> + string(4) "/:80" +} + +--> http://x:?: array(2) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(1) "x" +} + +--> x:blah.com: array(2) { + ["scheme"]=> + string(1) "x" + ["path"]=> + string(8) "blah.com" +} + +--> x:/blah.com: array(2) { + ["scheme"]=> + string(1) "x" + ["path"]=> + string(9) "/blah.com" +} + +--> x://::abc/?: array(3) { + ["scheme"]=> + string(1) "x" + ["host"]=> + string(1) ":" + ["path"]=> + string(1) "/" +} + +--> http://::?: array(2) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(1) ":" +} + +--> x://::6.5: array(3) { + ["scheme"]=> + string(1) "x" + ["host"]=> + string(1) ":" + ["port"]=> + int(6) +} + +--> http://?:/: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(1) "?" + ["path"]=> + string(1) "/" +} + +--> http://@?:/: array(4) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(1) "?" + ["user"]=> + string(0) "" + ["path"]=> + string(1) "/" +} + +--> file:///:: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(2) "/:" +} + +--> file:///a:/: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(3) "a:/" +} + +--> file:///ab:/: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(5) "/ab:/" +} + +--> file:///a:/: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(3) "a:/" +} + +--> file:///@:/: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(3) "@:/" +} + +--> file:///:80/: array(2) { + ["scheme"]=> + string(4) "file" + ["path"]=> + string(5) "/:80/" +} + +--> []: array(1) { + ["path"]=> + string(2) "[]" +} + +--> http://[x:80]/: array(3) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(6) "[x:80]" + ["path"]=> + string(1) "/" +} + +--> : array(1) { + ["path"]=> + string(0) "" +} + +--> /: array(1) { + ["path"]=> + string(1) "/" +} + +--> http:///blah.com: +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) + +--> http://:80: +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) + +--> http://user@:80: +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) + +--> http://user:pass@:80: +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) + +--> http://:: +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) + +--> http://@/: +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) + +--> http://@:/: +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) + +--> http://:/: +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) + +--> http://?: +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) + +--> http://?:: +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) + +--> http://:?: +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) + +--> http://blah.com:123456: +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) + +--> http://blah.com:abcdef: +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_002.phpt b/ext/standard/tests/url/parse_url_basic_002.phpt new file mode 100644 index 000000000..e25ab8dcd --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_002.phpt @@ -0,0 +1,151 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_SCHEME as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_SCHEME as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_SCHEME)); + +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : string(4) "http" +--> http://64.246.30.37/ : string(4) "http" +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : NULL +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : string(4) "http" +--> http://php.net/ : string(4) "http" +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : string(4) "http" +--> http://www.php.net/ : string(4) "http" +--> www.php.net:80 : NULL +--> http://www.php.net:80 : string(4) "http" +--> http://www.php.net:80/ : string(4) "http" +--> http://www.php.net/index.php : string(4) "http" +--> www.php.net/? : NULL +--> www.php.net:80/? : NULL +--> http://www.php.net/? : string(4) "http" +--> http://www.php.net:80/? : string(4) "http" +--> http://www.php.net:80/index.php : string(4) "http" +--> http://www.php.net:80/foo/bar/index.php : string(4) "http" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(4) "http" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : string(4) "http" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : string(4) "http" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(4) "http" +--> http://www.php.net:80/this/../a/../deep/directory : string(4) "http" +--> http://www.php.net:80/this/../a/../deep/directory/ : string(4) "http" +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : string(4) "http" +--> http://www.php.net:80/index.php : string(4) "http" +--> http://www.php.net:80/index.php? : string(4) "http" +--> http://www.php.net:80/#foo : string(4) "http" +--> http://www.php.net:80/?# : string(4) "http" +--> http://www.php.net:80/?test=1 : string(4) "http" +--> http://www.php.net/?test=1& : string(4) "http" +--> http://www.php.net:80/?& : string(4) "http" +--> http://www.php.net:80/index.php?test=1& : string(4) "http" +--> http://www.php.net/index.php?& : string(4) "http" +--> http://www.php.net:80/index.php?foo& : string(4) "http" +--> http://www.php.net/index.php?&foo : string(4) "http" +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : string(4) "http" +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(4) "http" +--> nntp://news.php.net : string(4) "nntp" +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : string(3) "ftp" +--> zlib:http://foo@bar : string(4) "zlib" +--> zlib:filename.txt : string(4) "zlib" +--> zlib:/path/to/my/file/file.txt : string(4) "zlib" +--> foo://foo@bar : string(3) "foo" +--> mailto:me@mydomain.com : string(6) "mailto" +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(4) "http" +--> file:///path/to/file : string(4) "file" +--> file://path/to/file : string(4) "file" +--> file:/path/to/file : string(4) "file" +--> http://1.2.3.4:/abc.asp?a=1&b=2 : string(4) "http" +--> http://foo.com#bar : string(4) "http" +--> scheme: : string(6) "scheme" +--> foo+bar://baz@bang/bla : string(7) "foo+bar" +--> gg:9130731 : string(2) "gg" +--> http://user:@pass@host/path?argument?value#etc : string(4) "http" +--> http://10.10.10.10/:80 : string(4) "http" +--> http://x:? : string(4) "http" +--> x:blah.com : string(1) "x" +--> x:/blah.com : string(1) "x" +--> x://::abc/? : string(1) "x" +--> http://::? : string(4) "http" +--> x://::6.5 : string(1) "x" +--> http://?:/ : string(4) "http" +--> http://@?:/ : string(4) "http" +--> file:///: : string(4) "file" +--> file:///a:/ : string(4) "file" +--> file:///ab:/ : string(4) "file" +--> file:///a:/ : string(4) "file" +--> file:///@:/ : string(4) "file" +--> file:///:80/ : string(4) "file" +--> [] : NULL +--> http://[x:80]/ : string(4) "http" +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_003.phpt b/ext/standard/tests/url/parse_url_basic_003.phpt new file mode 100644 index 000000000..e34dc2d19 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_003.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_HOST as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_HOST as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_HOST)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : string(12) "64.246.30.37" +--> http://64.246.30.37/ : string(12) "64.246.30.37" +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : string(12) "64.246.30.37" +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : string(7) "php.net" +--> http://php.net/ : string(7) "php.net" +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : string(11) "www.php.net" +--> http://www.php.net/ : string(11) "www.php.net" +--> www.php.net:80 : string(11) "www.php.net" +--> http://www.php.net:80 : string(11) "www.php.net" +--> http://www.php.net:80/ : string(11) "www.php.net" +--> http://www.php.net/index.php : string(11) "www.php.net" +--> www.php.net/? : NULL +--> www.php.net:80/? : string(11) "www.php.net" +--> http://www.php.net/? : string(11) "www.php.net" +--> http://www.php.net:80/? : string(11) "www.php.net" +--> http://www.php.net:80/index.php : string(11) "www.php.net" +--> http://www.php.net:80/foo/bar/index.php : string(11) "www.php.net" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(11) "www.php.net" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : string(11) "www.php.net" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : string(11) "www.php.net" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(11) "www.php.net" +--> http://www.php.net:80/this/../a/../deep/directory : string(11) "www.php.net" +--> http://www.php.net:80/this/../a/../deep/directory/ : string(11) "www.php.net" +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : string(11) "www.php.net" +--> http://www.php.net:80/index.php : string(11) "www.php.net" +--> http://www.php.net:80/index.php? : string(11) "www.php.net" +--> http://www.php.net:80/#foo : string(11) "www.php.net" +--> http://www.php.net:80/?# : string(11) "www.php.net" +--> http://www.php.net:80/?test=1 : string(11) "www.php.net" +--> http://www.php.net/?test=1& : string(11) "www.php.net" +--> http://www.php.net:80/?& : string(11) "www.php.net" +--> http://www.php.net:80/index.php?test=1& : string(11) "www.php.net" +--> http://www.php.net/index.php?& : string(11) "www.php.net" +--> http://www.php.net:80/index.php?foo& : string(11) "www.php.net" +--> http://www.php.net/index.php?&foo : string(11) "www.php.net" +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : string(11) "www.php.net" +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(11) "www.php.net" +--> nntp://news.php.net : string(12) "news.php.net" +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : string(11) "ftp.gnu.org" +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : string(3) "bar" +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(15) "www.example.com" +--> file:///path/to/file : NULL +--> file://path/to/file : string(4) "path" +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : string(7) "1.2.3.4" +--> http://foo.com#bar : string(7) "foo.com" +--> scheme: : NULL +--> foo+bar://baz@bang/bla : string(4) "bang" +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : string(4) "host" +--> http://10.10.10.10/:80 : string(11) "10.10.10.10" +--> http://x:? : string(1) "x" +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : string(1) ":" +--> http://::? : string(1) ":" +--> x://::6.5 : string(1) ":" +--> http://?:/ : string(1) "?" +--> http://@?:/ : string(1) "?" +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : string(6) "[x:80]" +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_004.phpt b/ext/standard/tests/url/parse_url_basic_004.phpt new file mode 100644 index 000000000..af3279547 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_004.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_PORT as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_PORT as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_PORT)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : NULL +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : int(80) +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : NULL +--> http://php.net/ : NULL +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : NULL +--> http://www.php.net/ : NULL +--> www.php.net:80 : int(80) +--> http://www.php.net:80 : int(80) +--> http://www.php.net:80/ : int(80) +--> http://www.php.net/index.php : NULL +--> www.php.net/? : NULL +--> www.php.net:80/? : int(80) +--> http://www.php.net/? : NULL +--> http://www.php.net:80/? : int(80) +--> http://www.php.net:80/index.php : int(80) +--> http://www.php.net:80/foo/bar/index.php : int(80) +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : int(80) +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : int(80) +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : int(80) +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : int(80) +--> http://www.php.net:80/this/../a/../deep/directory : int(80) +--> http://www.php.net:80/this/../a/../deep/directory/ : int(80) +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : int(80) +--> http://www.php.net:80/index.php : int(80) +--> http://www.php.net:80/index.php? : int(80) +--> http://www.php.net:80/#foo : int(80) +--> http://www.php.net:80/?# : int(80) +--> http://www.php.net:80/?test=1 : int(80) +--> http://www.php.net/?test=1& : NULL +--> http://www.php.net:80/?& : int(80) +--> http://www.php.net:80/index.php?test=1& : int(80) +--> http://www.php.net/index.php?& : NULL +--> http://www.php.net:80/index.php?foo& : int(80) +--> http://www.php.net/index.php?&foo : NULL +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : int(80) +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : int(80) +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : int(80) +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : int(80) +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : int(80) +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : int(80) +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : NULL +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : int(8080) +--> file:///path/to/file : NULL +--> file://path/to/file : NULL +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : NULL +--> http://foo.com#bar : NULL +--> scheme: : NULL +--> foo+bar://baz@bang/bla : NULL +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : NULL +--> http://10.10.10.10/:80 : NULL +--> http://x:? : NULL +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : NULL +--> http://::? : NULL +--> x://::6.5 : int(6) +--> http://?:/ : NULL +--> http://@?:/ : NULL +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : NULL +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_005.phpt b/ext/standard/tests/url/parse_url_basic_005.phpt new file mode 100644 index 000000000..5eb2541c1 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_005.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_USER as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_USER as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_USER)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : NULL +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : NULL +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : NULL +--> http://php.net/ : NULL +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : NULL +--> http://www.php.net/ : NULL +--> www.php.net:80 : NULL +--> http://www.php.net:80 : NULL +--> http://www.php.net:80/ : NULL +--> http://www.php.net/index.php : NULL +--> www.php.net/? : NULL +--> www.php.net:80/? : NULL +--> http://www.php.net/? : NULL +--> http://www.php.net:80/? : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/foo/bar/index.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/../a/../deep/directory : NULL +--> http://www.php.net:80/this/../a/../deep/directory/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/index.php? : NULL +--> http://www.php.net:80/#foo : NULL +--> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?test=1 : NULL +--> http://www.php.net/?test=1& : NULL +--> http://www.php.net:80/?& : NULL +--> http://www.php.net:80/index.php?test=1& : NULL +--> http://www.php.net/index.php?& : NULL +--> http://www.php.net:80/index.php?foo& : NULL +--> http://www.php.net/index.php?&foo : NULL +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : NULL +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(14) "secret@hideout" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(6) "secret" +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : string(3) "foo" +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(4) "user" +--> file:///path/to/file : NULL +--> file://path/to/file : NULL +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : NULL +--> http://foo.com#bar : NULL +--> scheme: : NULL +--> foo+bar://baz@bang/bla : string(3) "baz" +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : string(4) "user" +--> http://10.10.10.10/:80 : NULL +--> http://x:? : NULL +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : NULL +--> http://::? : NULL +--> x://::6.5 : NULL +--> http://?:/ : NULL +--> http://@?:/ : string(0) "" +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : NULL +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_006.phpt b/ext/standard/tests/url/parse_url_basic_006.phpt new file mode 100644 index 000000000..926200a1a --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_006.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_PASS as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_PASS as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_PASS)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : NULL +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : NULL +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : NULL +--> http://php.net/ : NULL +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : NULL +--> http://www.php.net/ : NULL +--> www.php.net:80 : NULL +--> http://www.php.net:80 : NULL +--> http://www.php.net:80/ : NULL +--> http://www.php.net/index.php : NULL +--> www.php.net/? : NULL +--> www.php.net:80/? : NULL +--> http://www.php.net/? : NULL +--> http://www.php.net:80/? : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/foo/bar/index.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/../a/../deep/directory : NULL +--> http://www.php.net:80/this/../a/../deep/directory/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/index.php? : NULL +--> http://www.php.net:80/#foo : NULL +--> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?test=1 : NULL +--> http://www.php.net/?test=1& : NULL +--> http://www.php.net:80/?& : NULL +--> http://www.php.net:80/index.php?test=1& : NULL +--> http://www.php.net/index.php?& : NULL +--> http://www.php.net:80/index.php?foo& : NULL +--> http://www.php.net/index.php?&foo : NULL +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : NULL +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(7) "hideout" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(7) "hideout" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : NULL +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(7) "hid:out" +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : NULL +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(6) "passwd" +--> file:///path/to/file : NULL +--> file://path/to/file : NULL +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : NULL +--> http://foo.com#bar : NULL +--> scheme: : NULL +--> foo+bar://baz@bang/bla : NULL +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : string(5) "@pass" +--> http://10.10.10.10/:80 : NULL +--> http://x:? : NULL +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : NULL +--> http://::? : NULL +--> x://::6.5 : NULL +--> http://?:/ : NULL +--> http://@?:/ : NULL +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : NULL +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_007.phpt b/ext/standard/tests/url/parse_url_basic_007.phpt new file mode 100644 index 000000000..d99ccb667 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_007.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_PATH as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_PATH as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_PATH)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : string(12) "64.246.30.37" +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : string(1) "/" +--> 64.246.30.37/ : string(13) "64.246.30.37/" +--> 64.246.30.37:80/ : string(1) "/" +--> php.net : string(7) "php.net" +--> php.net/ : string(8) "php.net/" +--> http://php.net : NULL +--> http://php.net/ : string(1) "/" +--> www.php.net : string(11) "www.php.net" +--> www.php.net/ : string(12) "www.php.net/" +--> http://www.php.net : NULL +--> http://www.php.net/ : string(1) "/" +--> www.php.net:80 : NULL +--> http://www.php.net:80 : NULL +--> http://www.php.net:80/ : string(1) "/" +--> http://www.php.net/index.php : string(10) "/index.php" +--> www.php.net/? : string(12) "www.php.net/" +--> www.php.net:80/? : string(1) "/" +--> http://www.php.net/? : string(1) "/" +--> http://www.php.net:80/? : string(1) "/" +--> http://www.php.net:80/index.php : string(10) "/index.php" +--> http://www.php.net:80/foo/bar/index.php : string(18) "/foo/bar/index.php" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(53) "/this/is/a/very/deep/directory/structure/and/file.php" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : string(53) "/this/is/a/very/deep/directory/structure/and/file.php" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : string(45) "/this/is/a/very/deep/directory/structure/and/" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : string(53) "/this/is/a/very/deep/directory/structure/and/file.php" +--> http://www.php.net:80/this/../a/../deep/directory : string(28) "/this/../a/../deep/directory" +--> http://www.php.net:80/this/../a/../deep/directory/ : string(29) "/this/../a/../deep/directory/" +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : string(42) "/this/is/a/very/deep/directory/../file.php" +--> http://www.php.net:80/index.php : string(10) "/index.php" +--> http://www.php.net:80/index.php? : string(10) "/index.php" +--> http://www.php.net:80/#foo : string(1) "/" +--> http://www.php.net:80/?# : string(1) "/" +--> http://www.php.net:80/?test=1 : string(1) "/" +--> http://www.php.net/?test=1& : string(1) "/" +--> http://www.php.net:80/?& : string(1) "/" +--> http://www.php.net:80/index.php?test=1& : string(10) "/index.php" +--> http://www.php.net/index.php?& : string(10) "/index.php" +--> http://www.php.net:80/index.php?foo& : string(10) "/index.php" +--> http://www.php.net/index.php?&foo : string(10) "/index.php" +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : string(10) "/index.php" +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(10) "/index.php" +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : string(22) "/gnu/glic/glibc.tar.gz" +--> zlib:http://foo@bar : string(14) "http://foo@bar" +--> zlib:filename.txt : string(12) "filename.txt" +--> zlib:/path/to/my/file/file.txt : string(25) "/path/to/my/file/file.txt" +--> foo://foo@bar : NULL +--> mailto:me@mydomain.com : string(15) "me@mydomain.com" +--> /foo.php?a=b&c=d : string(8) "/foo.php" +--> foo.php?a=b&c=d : string(7) "foo.php" +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : NULL +--> file:///path/to/file : string(13) "/path/to/file" +--> file://path/to/file : string(8) "/to/file" +--> file:/path/to/file : string(13) "/path/to/file" +--> http://1.2.3.4:/abc.asp?a=1&b=2 : string(8) "/abc.asp" +--> http://foo.com#bar : NULL +--> scheme: : NULL +--> foo+bar://baz@bang/bla : string(4) "/bla" +--> gg:9130731 : string(7) "9130731" +--> http://user:@pass@host/path?argument?value#etc : string(5) "/path" +--> http://10.10.10.10/:80 : string(4) "/:80" +--> http://x:? : NULL +--> x:blah.com : string(8) "blah.com" +--> x:/blah.com : string(9) "/blah.com" +--> x://::abc/? : string(1) "/" +--> http://::? : NULL +--> x://::6.5 : NULL +--> http://?:/ : string(1) "/" +--> http://@?:/ : string(1) "/" +--> file:///: : string(2) "/:" +--> file:///a:/ : string(3) "a:/" +--> file:///ab:/ : string(5) "/ab:/" +--> file:///a:/ : string(3) "a:/" +--> file:///@:/ : string(3) "@:/" +--> file:///:80/ : string(5) "/:80/" +--> [] : string(2) "[]" +--> http://[x:80]/ : string(1) "/" +--> : string(0) "" +--> / : string(1) "/" +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_008.phpt b/ext/standard/tests/url/parse_url_basic_008.phpt new file mode 100644 index 000000000..d2d2ebb59 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_008.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_QUERY as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_QUERY as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_QUERY)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : NULL +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : NULL +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : NULL +--> http://php.net/ : NULL +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : NULL +--> http://www.php.net/ : NULL +--> www.php.net:80 : NULL +--> http://www.php.net:80 : NULL +--> http://www.php.net:80/ : NULL +--> http://www.php.net/index.php : NULL +--> www.php.net/? : NULL +--> www.php.net:80/? : NULL +--> http://www.php.net/? : NULL +--> http://www.php.net:80/? : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/foo/bar/index.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : string(37) "lots=1&of=2¶meters=3&too=4&here=5" +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/../a/../deep/directory : NULL +--> http://www.php.net:80/this/../a/../deep/directory/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/index.php? : NULL +--> http://www.php.net:80/#foo : NULL +--> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?test=1 : string(6) "test=1" +--> http://www.php.net/?test=1& : string(7) "test=1&" +--> http://www.php.net:80/?& : string(1) "&" +--> http://www.php.net:80/index.php?test=1& : string(7) "test=1&" +--> http://www.php.net/index.php?& : string(1) "&" +--> http://www.php.net:80/index.php?foo& : string(4) "foo&" +--> http://www.php.net/index.php?&foo : string(4) "&foo" +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : string(31) "test=1&test2=char&test3=mixesCI" +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(31) "test=1&test2=char&test3=mixesCI" +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : NULL +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : string(7) "a=b&c=d" +--> foo.php?a=b&c=d : string(7) "a=b&c=d" +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : string(12) "bar=1&boom=0" +--> file:///path/to/file : NULL +--> file://path/to/file : NULL +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : string(7) "a=1&b=2" +--> http://foo.com#bar : NULL +--> scheme: : NULL +--> foo+bar://baz@bang/bla : NULL +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : string(14) "argument?value" +--> http://10.10.10.10/:80 : NULL +--> http://x:? : NULL +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : NULL +--> http://::? : NULL +--> x://::6.5 : NULL +--> http://?:/ : NULL +--> http://@?:/ : NULL +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : NULL +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_009.phpt b/ext/standard/tests/url/parse_url_basic_009.phpt new file mode 100644 index 000000000..b23a30edf --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_009.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test parse_url() function: Parse a load of URLs without specifying PHP_URL_FRAGMENT as the URL component +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * Parse a load of URLs without specifying PHP_URL_FRAGMENT as the URL component + */ +include_once(dirname(__FILE__) . '/urls.inc'); + +foreach ($urls as $url) { + echo "--> $url : "; + var_dump(parse_url($url, PHP_URL_FRAGMENT)); +} + +echo "Done"; +?> +--EXPECTF-- +--> 64.246.30.37 : NULL +--> http://64.246.30.37 : NULL +--> http://64.246.30.37/ : NULL +--> 64.246.30.37/ : NULL +--> 64.246.30.37:80/ : NULL +--> php.net : NULL +--> php.net/ : NULL +--> http://php.net : NULL +--> http://php.net/ : NULL +--> www.php.net : NULL +--> www.php.net/ : NULL +--> http://www.php.net : NULL +--> http://www.php.net/ : NULL +--> www.php.net:80 : NULL +--> http://www.php.net:80 : NULL +--> http://www.php.net:80/ : NULL +--> http://www.php.net/index.php : NULL +--> www.php.net/? : NULL +--> www.php.net:80/? : NULL +--> http://www.php.net/? : NULL +--> http://www.php.net:80/? : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/foo/bar/index.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5 : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL +--> http://www.php.net:80/this/../a/../deep/directory : NULL +--> http://www.php.net:80/this/../a/../deep/directory/ : NULL +--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL +--> http://www.php.net:80/index.php : NULL +--> http://www.php.net:80/index.php? : NULL +--> http://www.php.net:80/#foo : string(3) "foo" +--> http://www.php.net:80/?# : NULL +--> http://www.php.net:80/?test=1 : NULL +--> http://www.php.net/?test=1& : NULL +--> http://www.php.net:80/?& : NULL +--> http://www.php.net:80/index.php?test=1& : NULL +--> http://www.php.net/index.php?& : NULL +--> http://www.php.net:80/index.php?foo& : NULL +--> http://www.php.net/index.php?&foo : NULL +--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI : NULL +--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123 : string(16) "some_page_ref123" +--> nntp://news.php.net : NULL +--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz : NULL +--> zlib:http://foo@bar : NULL +--> zlib:filename.txt : NULL +--> zlib:/path/to/my/file/file.txt : NULL +--> foo://foo@bar : NULL +--> mailto:me@mydomain.com : NULL +--> /foo.php?a=b&c=d : NULL +--> foo.php?a=b&c=d : NULL +--> http://user:passwd@www.example.com:8080?bar=1&boom=0 : NULL +--> file:///path/to/file : NULL +--> file://path/to/file : NULL +--> file:/path/to/file : NULL +--> http://1.2.3.4:/abc.asp?a=1&b=2 : NULL +--> http://foo.com#bar : string(3) "bar" +--> scheme: : NULL +--> foo+bar://baz@bang/bla : NULL +--> gg:9130731 : NULL +--> http://user:@pass@host/path?argument?value#etc : string(3) "etc" +--> http://10.10.10.10/:80 : NULL +--> http://x:? : NULL +--> x:blah.com : NULL +--> x:/blah.com : NULL +--> x://::abc/? : NULL +--> http://::? : NULL +--> x://::6.5 : NULL +--> http://?:/ : NULL +--> http://@?:/ : NULL +--> file:///: : NULL +--> file:///a:/ : NULL +--> file:///ab:/ : NULL +--> file:///a:/ : NULL +--> file:///@:/ : NULL +--> file:///:80/ : NULL +--> [] : NULL +--> http://[x:80]/ : NULL +--> : NULL +--> / : NULL +--> http:///blah.com : +Warning: parse_url(http:///blah.com): Unable to parse URL in %s on line 15 +bool(false) +--> http://:80 : +Warning: parse_url(http://:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user@:80 : +Warning: parse_url(http://user@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://user:pass@:80 : +Warning: parse_url(http://user:pass@:80): Unable to parse URL in %s on line 15 +bool(false) +--> http://: : +Warning: parse_url(http://:): Unable to parse URL in %s on line 15 +bool(false) +--> http://@/ : +Warning: parse_url(http://@/): Unable to parse URL in %s on line 15 +bool(false) +--> http://@:/ : +Warning: parse_url(http://@:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://:/ : +Warning: parse_url(http://:/): Unable to parse URL in %s on line 15 +bool(false) +--> http://? : +Warning: parse_url(http://?): Unable to parse URL in %s on line 15 +bool(false) +--> http://?: : +Warning: parse_url(http://?:): Unable to parse URL in %s on line 15 +bool(false) +--> http://:? : +Warning: parse_url(http://:?): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:123456 : +Warning: parse_url(http://blah.com:123456): Unable to parse URL in %s on line 15 +bool(false) +--> http://blah.com:abcdef : +Warning: parse_url(http://blah.com:abcdef): Unable to parse URL in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_basic_010.phpt b/ext/standard/tests/url/parse_url_basic_010.phpt new file mode 100644 index 000000000..3bb2dba14 --- /dev/null +++ b/ext/standard/tests/url/parse_url_basic_010.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test parse_url() function : check values of URL related constants +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +/* + * check values of URL related constants + */ +foreach(get_defined_constants() as $constantName => $constantValue) { + if (strpos($constantName, 'PHP_URL')===0) { + echo "$constantName: $constantValue \n"; + } +} + +echo "Done"; +?> +--EXPECTF-- +PHP_URL_SCHEME: 0 +PHP_URL_HOST: 1 +PHP_URL_PORT: 2 +PHP_URL_USER: 3 +PHP_URL_PASS: 4 +PHP_URL_PATH: 5 +PHP_URL_QUERY: 6 +PHP_URL_FRAGMENT: 7 +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_error_001.phpt b/ext/standard/tests/url/parse_url_error_001.phpt new file mode 100644 index 000000000..0280a87cb --- /dev/null +++ b/ext/standard/tests/url/parse_url_error_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test parse_url() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +echo "*** Testing parse_url() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing parse_url() function with Zero arguments --\n"; +var_dump( parse_url() ); + +//Test parse_url with one more than the expected number of arguments +echo "\n-- Testing parse_url() function with more than expected no. of arguments --\n"; +$url = 'string_val'; +$url_component = 10; +$extra_arg = 10; +var_dump( parse_url($url, $url_component, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_url() : error conditions *** + +-- Testing parse_url() function with Zero arguments -- + +Warning: parse_url() expects at least 1 parameter, 0 given in %s on line 12 +NULL + +-- Testing parse_url() function with more than expected no. of arguments -- + +Warning: parse_url() expects at most 2 parameters, 3 given in %s on line 19 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_error_002.phpt b/ext/standard/tests/url/parse_url_error_002.phpt new file mode 100644 index 000000000..45c20f410 --- /dev/null +++ b/ext/standard/tests/url/parse_url_error_002.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test parse_url() function: url component specifier out of range +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +echo "*** Testing parse_url() : error conditions: url component specifier out of range ***\n"; +$url = 'http://secret:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123'; + +echo "--> Below range:"; +var_dump(parse_url($url, -1)); + +echo "\n\n--> Above range:"; +var_dump(parse_url($url, 99)); + +echo "Done" +?> +--EXPECTF-- +*** Testing parse_url() : error conditions: url component specifier out of range *** +--> Below range:array(8) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + + +--> Above range: +Warning: parse_url(): Invalid URL component identifier 99 in %s on line 15 +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_variation_001.phpt b/ext/standard/tests/url/parse_url_variation_001.phpt new file mode 100644 index 000000000..18ef0a547 --- /dev/null +++ b/ext/standard/tests/url/parse_url_variation_001.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test parse_url() function : usage variations - unexpected type for arg 1. +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing parse_url() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for url + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( parse_url($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_url() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(60) +Error: 8 - Undefined variable: unset_var, %s(63) + +Arg value 0 +array(1) { + ["path"]=> + string(1) "0" +} + +Arg value 1 +array(1) { + ["path"]=> + string(1) "1" +} + +Arg value 12345 +array(1) { + ["path"]=> + string(5) "12345" +} + +Arg value -2345 +array(1) { + ["path"]=> + string(5) "-2345" +} + +Arg value 10.5 +array(1) { + ["path"]=> + string(4) "10.5" +} + +Arg value -10.5 +array(1) { + ["path"]=> + string(5) "-10.5" +} + +Arg value 101234567000 +array(1) { + ["path"]=> + string(12) "101234567000" +} + +Arg value 1.07654321E-9 +array(1) { + ["path"]=> + string(13) "1.07654321E-9" +} + +Arg value 0.5 +array(1) { + ["path"]=> + string(3) "0.5" +} + +Arg value Array +Error: 2 - parse_url() expects parameter 1 to be string, array given, %s(70) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 1 to be string, array given, %s(70) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 1 to be string, array given, %s(70) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 1 to be string, array given, %s(70) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 1 to be string, array given, %s(70) +NULL + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value 1 +array(1) { + ["path"]=> + string(1) "1" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value 1 +array(1) { + ["path"]=> + string(1) "1" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} +Error: 4096 - Object of class stdClass could not be converted to string, %s(69) + +Arg value +Error: 2 - parse_url() expects parameter 1 to be string, object given, %s(70) +NULL + +Arg value +array(1) { + ["path"]=> + string(0) "" +} + +Arg value +array(1) { + ["path"]=> + string(0) "" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_variation_002_32bit.phpt b/ext/standard/tests/url/parse_url_variation_002_32bit.phpt new file mode 100644 index 000000000..88971e964 --- /dev/null +++ b/ext/standard/tests/url/parse_url_variation_002_32bit.phpt @@ -0,0 +1,200 @@ +--TEST-- +Test parse_url() function : usage variations - unexpected type for arg 2. +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); ?> +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing parse_url() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$url = 'http://secret:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for url_component + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( parse_url($url, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_url() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(61) +Error: 8 - Undefined variable: unset_var, %s(64) + +Arg value 10.5 +Error: 2 - parse_url(): Invalid URL component identifier 10, %s(71) +bool(false) + +Arg value -10.5 +array(8) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +Arg value 101234567000 +array(8) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +Arg value 1.07654321E-9 +string(4) "http" + +Arg value 0.5 +string(4) "http" + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value +string(4) "http" + +Arg value +string(4) "http" + +Arg value 1 +string(11) "www.php.net" + +Arg value +string(4) "http" + +Arg value 1 +string(11) "www.php.net" + +Arg value +string(4) "http" + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value string +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value string +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL +Error: 4096 - Object of class stdClass could not be converted to string, %s(70) + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, object given, %s(71) +NULL + +Arg value +string(4) "http" + +Arg value +string(4) "http" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/parse_url_variation_002_64bit.phpt b/ext/standard/tests/url/parse_url_variation_002_64bit.phpt new file mode 100644 index 000000000..561a43353 --- /dev/null +++ b/ext/standard/tests/url/parse_url_variation_002_64bit.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test parse_url() function : usage variations - unexpected type for arg 2. +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only"); ?> +--FILE-- +<?php +/* Prototype : proto mixed parse_url(string url, [int url_component]) + * Description: Parse a URL and return its components + * Source code: ext/standard/url.c + * Alias to functions: + */ + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing parse_url() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$url = 'http://secret:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for url_component + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( parse_url($url, $value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing parse_url() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(61) +Error: 8 - Undefined variable: unset_var, %s(64) + +Arg value 10.5 +Error: 2 - parse_url(): Invalid URL component identifier 10, %s(71) +bool(false) + +Arg value -10.5 +array(8) { + ["scheme"]=> + string(4) "http" + ["host"]=> + string(11) "www.php.net" + ["port"]=> + int(80) + ["user"]=> + string(6) "secret" + ["pass"]=> + string(7) "hideout" + ["path"]=> + string(10) "/index.php" + ["query"]=> + string(31) "test=1&test2=char&test3=mixesCI" + ["fragment"]=> + string(16) "some_page_ref123" +} + +Arg value 101234567000 +Error: 2 - parse_url(): Invalid URL component identifier 101234567000, %s(71) +bool(false) + +Arg value 1.07654321E-9 +string(4) "http" + +Arg value 0.5 +string(4) "http" + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value Array +Error: 2 - parse_url() expects parameter 2 to be long, array given, %s(71) +NULL + +Arg value +string(4) "http" + +Arg value +string(4) "http" + +Arg value 1 +string(11) "www.php.net" + +Arg value +string(4) "http" + +Arg value 1 +string(11) "www.php.net" + +Arg value +string(4) "http" + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value string +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL + +Arg value string +Error: 2 - parse_url() expects parameter 2 to be long, string given, %s(71) +NULL +Error: 4096 - Object of class stdClass could not be converted to string, %s(70) + +Arg value +Error: 2 - parse_url() expects parameter 2 to be long, object given, %s(71) +NULL + +Arg value +string(4) "http" + +Arg value +string(4) "http" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/rawurldecode_error_001.phpt b/ext/standard/tests/url/rawurldecode_error_001.phpt new file mode 100644 index 000000000..1dcaf40fd --- /dev/null +++ b/ext/standard/tests/url/rawurldecode_error_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test rawurldecode() function : error conditions - wrong number of args +--FILE-- +<?php +/* Prototype : proto string rawurldecode(string str) + * Description: Decodes URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +echo "*** Testing rawurldecode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing rawurldecode() function with Zero arguments --\n"; +var_dump( rawurldecode() ); + +//Test rawurldecode with one more than the expected number of arguments +echo "\n-- Testing rawurldecode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( rawurldecode($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing rawurldecode() : error conditions *** + +-- Testing rawurldecode() function with Zero arguments -- + +Warning: rawurldecode() expects exactly 1 parameter, 0 given in %s on line 14 +NULL + +-- Testing rawurldecode() function with more than expected no. of arguments -- + +Warning: rawurldecode() expects exactly 1 parameter, 2 given in %s on line 20 +NULL +Done diff --git a/ext/standard/tests/url/rawurldecode_variation_001.phpt b/ext/standard/tests/url/rawurldecode_variation_001.phpt new file mode 100644 index 000000000..4942e8b35 --- /dev/null +++ b/ext/standard/tests/url/rawurldecode_variation_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test rawurldecode() function : usage variations - unexpected type for arg 1. +--FILE-- +<?php +/* Prototype : proto string rawurldecode(string str) + * Description: Decodes URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing rawurldecode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( rawurldecode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing rawurldecode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 2 - rawurldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 2 - rawurldecode() expects parameter 1 to be string, object given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/rawurlencode_error_001.phpt b/ext/standard/tests/url/rawurlencode_error_001.phpt new file mode 100644 index 000000000..7acce9e0c --- /dev/null +++ b/ext/standard/tests/url/rawurlencode_error_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test rawurlencode() function : error conditions +--FILE-- +<?php +/* Prototype : proto string rawurlencode(string str) + * Description: URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +echo "*** Testing rawurlencode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing rawurlencode() function with Zero arguments --\n"; +var_dump( rawurlencode() ); + +//Test rawurlencode with one more than the expected number of arguments +echo "\n-- Testing rawurlencode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( rawurlencode($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing rawurlencode() : error conditions *** + +-- Testing rawurlencode() function with Zero arguments -- + +Warning: rawurlencode() expects exactly 1 parameter, 0 given in %s on line 14 +NULL + +-- Testing rawurlencode() function with more than expected no. of arguments -- + +Warning: rawurlencode() expects exactly 1 parameter, 2 given in %s on line 20 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/rawurlencode_variation_001.phpt b/ext/standard/tests/url/rawurlencode_variation_001.phpt new file mode 100644 index 000000000..d90825ba7 --- /dev/null +++ b/ext/standard/tests/url/rawurlencode_variation_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test rawurlencode() function : usage variations - unexpected type for arg 1. +--FILE-- +<?php +/* Prototype : proto string rawurlencode(string str) + * Description: URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing rawurlencode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( rawurlencode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing rawurlencode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 2 - rawurlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - rawurlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 2 - rawurlencode() expects parameter 1 to be string, object given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/urldecode_error_001.phpt b/ext/standard/tests/url/urldecode_error_001.phpt new file mode 100644 index 000000000..f0e5ae083 --- /dev/null +++ b/ext/standard/tests/url/urldecode_error_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test urldecode() function : error conditions +--FILE-- +<?php +/* Prototype : proto string urldecode(string str) + * Description: Decodes URL-encoded string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +echo "*** Testing urldecode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing urldecode() function with Zero arguments --\n"; +var_dump( urldecode() ); + +//Test urldecode with one more than the expected number of arguments +echo "\n-- Testing urldecode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( urldecode($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing urldecode() : error conditions *** + +-- Testing urldecode() function with Zero arguments -- + +Warning: urldecode() expects exactly 1 parameter, 0 given in %s on line 14 +NULL + +-- Testing urldecode() function with more than expected no. of arguments -- + +Warning: urldecode() expects exactly 1 parameter, 2 given in %s on line 20 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/urldecode_variation_001.phpt b/ext/standard/tests/url/urldecode_variation_001.phpt new file mode 100644 index 000000000..7ebc7bdbe --- /dev/null +++ b/ext/standard/tests/url/urldecode_variation_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test urldecode() function : usage variations - <type here specifics of this variation> +--FILE-- +<?php +/* Prototype : proto string urldecode(string str) + * Description: Decodes URL-encoded string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing urldecode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( urldecode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing urldecode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 2 - urldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urldecode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 2 - urldecode() expects parameter 1 to be string, object given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/urlencode_error_001.phpt b/ext/standard/tests/url/urlencode_error_001.phpt new file mode 100644 index 000000000..fc00b057d --- /dev/null +++ b/ext/standard/tests/url/urlencode_error_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test urlencode() function : error conditions +--FILE-- +<?php +/* Prototype : proto string urlencode(string str) + * Description: URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +echo "*** Testing urlencode() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing urlencode() function with Zero arguments --\n"; +var_dump( urlencode() ); + +//Test urlencode with one more than the expected number of arguments +echo "\n-- Testing urlencode() function with more than expected no. of arguments --\n"; +$str = 'string_val'; +$extra_arg = 10; +var_dump( urlencode($str, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing urlencode() : error conditions *** + +-- Testing urlencode() function with Zero arguments -- + +Warning: urlencode() expects exactly 1 parameter, 0 given in %s on line 14 +NULL + +-- Testing urlencode() function with more than expected no. of arguments -- + +Warning: urlencode() expects exactly 1 parameter, 2 given in %s on line 20 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/urlencode_variation_001.phpt b/ext/standard/tests/url/urlencode_variation_001.phpt new file mode 100644 index 000000000..1f82b65f3 --- /dev/null +++ b/ext/standard/tests/url/urlencode_variation_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test urlencode() function : usage variations - <type here specifics of this variation> +--FILE-- +<?php +/* Prototype : proto string urlencode(string str) + * Description: URL-encodes string + * Source code: ext/standard/url.c + * Alias to functions: + */ + +// NB: basic functionality tested in tests/strings/001.phpt + +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; +} +set_error_handler('test_error_handler'); + +echo "*** Testing urlencode() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data + 0, + 1, + 12345, + -2345, + + // float data + 10.5, + -10.5, + 10.1234567e10, + 10.7654321E-10, + .5, + + // array data + array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data + NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data + "", + '', + + // object data + new stdclass(), + + // undefined data + $undefined_var, + + // unset data + $unset_var, +); + +// loop through each element of the array for str + +foreach($values as $value) { + echo "\nArg value $value \n"; + var_dump( urlencode($value) ); +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing urlencode() : usage variations *** +Error: 8 - Undefined variable: undefined_var, %s(64) +Error: 8 - Undefined variable: unset_var, %s(67) + +Arg value 0 +string(1) "0" + +Arg value 1 +string(1) "1" + +Arg value 12345 +string(5) "12345" + +Arg value -2345 +string(5) "-2345" + +Arg value 10.5 +string(4) "10.5" + +Arg value -10.5 +string(5) "-10.5" + +Arg value 101234567000 +string(12) "101234567000" + +Arg value 1.07654321E-9 +string(13) "1.07654321E-9" + +Arg value 0.5 +string(3) "0.5" + +Arg value Array +Error: 2 - urlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value Array +Error: 2 - urlencode() expects parameter 1 to be string, array given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value 1 +string(1) "1" + +Arg value +string(0) "" + +Arg value +string(0) "" + +Arg value +string(0) "" +Error: 4096 - Object of class stdClass could not be converted to string, %s(73) + +Arg value +Error: 2 - urlencode() expects parameter 1 to be string, object given, %s(74) +NULL + +Arg value +string(0) "" + +Arg value +string(0) "" +Done
\ No newline at end of file diff --git a/ext/standard/tests/url/urls.inc b/ext/standard/tests/url/urls.inc new file mode 100644 index 000000000..27521c852 --- /dev/null +++ b/ext/standard/tests/url/urls.inc @@ -0,0 +1,109 @@ +<?php +$urls = array( +// Parsable URLs: +'64.246.30.37', +'http://64.246.30.37', +'http://64.246.30.37/', +'64.246.30.37/', +'64.246.30.37:80/', +'php.net', +'php.net/', +'http://php.net', +'http://php.net/', +'www.php.net', +'www.php.net/', +'http://www.php.net', +'http://www.php.net/', +'www.php.net:80', +'http://www.php.net:80', +'http://www.php.net:80/', +'http://www.php.net/index.php', +'www.php.net/?', +'www.php.net:80/?', +'http://www.php.net/?', +'http://www.php.net:80/?', +'http://www.php.net:80/index.php', +'http://www.php.net:80/foo/bar/index.php', +'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php', +'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5', +'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/', +'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php', +'http://www.php.net:80/this/../a/../deep/directory', +'http://www.php.net:80/this/../a/../deep/directory/', +'http://www.php.net:80/this/is/a/very/deep/directory/../file.php', +'http://www.php.net:80/index.php', +'http://www.php.net:80/index.php?', +'http://www.php.net:80/#foo', +'http://www.php.net:80/?#', +'http://www.php.net:80/?test=1', +'http://www.php.net/?test=1&', +'http://www.php.net:80/?&', +'http://www.php.net:80/index.php?test=1&', +'http://www.php.net/index.php?&', +'http://www.php.net:80/index.php?foo&', +'http://www.php.net/index.php?&foo', +'http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI', +'www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', +'nntp://news.php.net', +'ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz', +'zlib:http://foo@bar', +'zlib:filename.txt', +'zlib:/path/to/my/file/file.txt', +'foo://foo@bar', +'mailto:me@mydomain.com', +'/foo.php?a=b&c=d', +'foo.php?a=b&c=d', +'http://user:passwd@www.example.com:8080?bar=1&boom=0', +'file:///path/to/file', +'file://path/to/file', +'file:/path/to/file', +'http://1.2.3.4:/abc.asp?a=1&b=2', +'http://foo.com#bar', +'scheme:', +'foo+bar://baz@bang/bla', +'gg:9130731', +'http://user:@pass@host/path?argument?value#etc', +'http://10.10.10.10/:80', +'http://x:?', +'x:blah.com', +'x:/blah.com', +'x://::abc/?', +'http://::?', +'x://::6.5', +'http://?:/', +'http://@?:/', +'file:///:', +'file:///a:/', +'file:///ab:/', +'file:///a:/', +'file:///@:/', +'file:///:80/', +'[]', +'http://[x:80]/', +'', +'/', + +// Severely malformed URLs that do not parse: +'http:///blah.com', +'http://:80', +'http://user@:80', +'http://user:pass@:80', +'http://:', +'http://@/', +'http://@:/', +'http://:/', +'http://?', +'http://?:', +'http://:?', +'http://blah.com:123456', +'http://blah.com:abcdef', +); + + +?>
\ No newline at end of file diff --git a/ext/standard/type.c b/ext/standard/type.c index 536f0a673..9ee4fd18b 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: type.c,v 1.30.2.2.2.3 2007/02/24 02:17:27 helly Exp $ */ +/* $Id: type.c,v 1.30.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" #include "php_incomplete_class.h" diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c index ff5b9b2c9..2e72ba3d5 100644 --- a/ext/standard/uniqid.c +++ b/ext/standard/uniqid.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: uniqid.c,v 1.41.2.2.2.3 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: uniqid.c,v 1.41.2.2.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/uniqid.h b/ext/standard/uniqid.h index c2ed14fcf..bbba9a1b0 100644 --- a/ext/standard/uniqid.h +++ b/ext/standard/uniqid.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: uniqid.h,v 1.13.2.1.2.1 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: uniqid.h,v 1.13.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef UNIQID_H #define UNIQID_H diff --git a/ext/standard/url.c b/ext/standard/url.c index 13a6aa592..ae95a785f 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: url.c,v 1.86.2.5.2.8 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: url.c,v 1.86.2.5.2.9 2007/12/31 07:20:13 sebastian Exp $ */ #include <stdlib.h> #include <string.h> diff --git a/ext/standard/url.h b/ext/standard/url.h index 7e52d68d8..4bb00f7c7 100644 --- a/ext/standard/url.h +++ b/ext/standard/url.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: url.h,v 1.20.2.2.2.1 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: url.h,v 1.20.2.2.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef URL_H #define URL_H diff --git a/ext/standard/url_scanner.c b/ext/standard/url_scanner.c index 0b402c45d..da712b5ae 100644 --- a/ext/standard/url_scanner.c +++ b/ext/standard/url_scanner.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: url_scanner.c,v 1.44.2.1.2.3 2007/02/22 00:44:08 iliaa Exp $ */ +/* $Id: url_scanner.c,v 1.44.2.1.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" diff --git a/ext/standard/url_scanner.h b/ext/standard/url_scanner.h index 86cca80e6..fc7baa01a 100644 --- a/ext/standard/url_scanner.h +++ b/ext/standard/url_scanner.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -15,7 +15,7 @@ | Author: Sascha Schumann <sascha@schumann.cx> | +----------------------------------------------------------------------+ */ -/* $Id: url_scanner.h,v 1.16.2.1.2.1 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: url_scanner.h,v 1.16.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef URI_SCANNER_H #define URI_SCANNER_H diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index a32429531..9edf4c2f9 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: url_scanner_ex.c,v 1.95.2.4.2.5 2007/10/10 09:28:51 jani Exp $ */ +/* $Id: url_scanner_ex.c,v 1.95.2.4.2.6 2008/03/12 11:27:42 felipe Exp $ */ #include "php.h" @@ -951,7 +951,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * size_t len; if (BG(url_adapt_state_ex).url_app.len != 0) { - *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); + *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT) ? 1 : 0) TSRMLS_CC); if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; diff --git a/ext/standard/url_scanner_ex.c.orig b/ext/standard/url_scanner_ex.c.orig index f6e388fb2..4d337d74f 100644 --- a/ext/standard/url_scanner_ex.c.orig +++ b/ext/standard/url_scanner_ex.c.orig @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: url_scanner_ex.c,v 1.95.2.4.2.5 2007/10/10 09:28:51 jani Exp $ */ +/* $Id: url_scanner_ex.c,v 1.95.2.4.2.6 2008/03/12 11:27:42 felipe Exp $ */ #include "php.h" @@ -1007,7 +1007,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * size_t len; if (BG(url_adapt_state_ex).url_app.len != 0) { - *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); + *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT) ? 1 : 0) TSRMLS_CC); if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; diff --git a/ext/standard/url_scanner_ex.h b/ext/standard/url_scanner_ex.h index 020c04078..9f17558e3 100644 --- a/ext/standard/url_scanner_ex.h +++ b/ext/standard/url_scanner_ex.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: url_scanner_ex.h,v 1.26.2.1.2.1 2007/01/01 09:36:09 sebastian Exp $ */ +/* $Id: url_scanner_ex.h,v 1.26.2.1.2.2 2007/12/31 07:20:13 sebastian Exp $ */ #ifndef URL_SCANNER_EX_H #define URL_SCANNER_EX_H diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index a1bfdc027..3dc635501 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: url_scanner_ex.re,v 1.76.2.2.2.2 2007/10/10 00:35:52 iliaa Exp $ */ +/* $Id: url_scanner_ex.re,v 1.76.2.2.2.3 2008/03/12 19:33:46 felipe Exp $ */ #include "php.h" @@ -431,7 +431,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char * size_t len; if (BG(url_adapt_state_ex).url_app.len != 0) { - *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); + *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT) ? 1 : 0) TSRMLS_CC); if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 3397f2f23..70e479450 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: user_filters.c,v 1.31.2.4.2.9 2007/08/04 07:53:00 pollita Exp $ */ +/* $Id: user_filters.c,v 1.31.2.4.2.10 2007/12/31 07:20:13 sebastian Exp $ */ #include "php.h" #include "php_globals.h" diff --git a/ext/standard/uuencode.c b/ext/standard/uuencode.c index 0290c1329..c0df1e0d9 100644 --- a/ext/standard/uuencode.c +++ b/ext/standard/uuencode.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: uuencode.c,v 1.5.2.1.2.5 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: uuencode.c,v 1.5.2.1.2.6 2007/12/31 07:20:13 sebastian Exp $ */ /* * Portions of this code are based on Berkeley's uuencode/uudecode diff --git a/ext/standard/var.c b/ext/standard/var.c index d250957b9..efbc887f6 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: var.c,v 1.203.2.7.2.19 2007/10/04 13:31:11 jani Exp $ */ +/* $Id: var.c,v 1.203.2.7.2.22 2007/12/31 07:20:13 sebastian Exp $ */ @@ -355,13 +355,15 @@ static int php_array_element_export(zval **zv, int num_args, va_list args, zend_ if (hash_key->nKeyLength==0) { /* numeric key */ php_printf("%*c%ld => ", level + 1, ' ', hash_key->h); } else { /* string key */ - char *key; - int key_len; + char *key, *tmp_str; + int key_len, tmp_len; key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC); + tmp_str = php_str_to_str_ex(key, key_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL); php_printf("%*c'", level + 1, ' '); - PHPWRITE(key, key_len); + PHPWRITE(tmp_str, tmp_len); php_printf("' => "); efree(key); + efree(tmp_str); } php_var_export(zv, level + 2 TSRMLS_CC); PUTS (",\n"); @@ -389,8 +391,8 @@ static int php_object_element_export(zval **zv, int num_args, va_list args, zend PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) { HashTable *myht; - char* tmp_str; - int tmp_len; + char *tmp_str, *tmp_str2; + int tmp_len, tmp_len2; char *class_name; zend_uint class_name_len; @@ -408,11 +410,13 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) php_printf("%.*H", (int) EG(precision), Z_DVAL_PP(struc)); break; case IS_STRING: - tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\\0", 3 TSRMLS_CC); + tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\", 2 TSRMLS_CC); + tmp_str2 = php_str_to_str_ex(tmp_str, tmp_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len2, 0, NULL); PUTS ("'"); - PHPWRITE(tmp_str, tmp_len); + PHPWRITE(tmp_str2, tmp_len2); PUTS ("'"); - efree (tmp_str); + efree(tmp_str2); + efree(tmp_str); break; case IS_ARRAY: myht = Z_ARRVAL_PP(struc); diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c index f044da455..89181b8ce 100644 --- a/ext/standard/var_unserializer.c +++ b/ext/standard/var_unserializer.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: var_unserializer.c,v 1.70.2.4.2.7 2007/08/06 18:33:29 jani Exp $ */ +/* $Id: var_unserializer.c,v 1.70.2.4.2.8 2008/03/19 03:00:40 felipe Exp $ */ #include "php.h" #include "ext/standard/php_var.h" @@ -288,10 +288,10 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); break; case IS_STRING: - if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { + if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { var_push_dtor(var_hash, old_data); } - zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); + zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); break; } diff --git a/ext/standard/var_unserializer.c.orig b/ext/standard/var_unserializer.c.orig index e3e6c25af..3d4fcb77d 100644 --- a/ext/standard/var_unserializer.c.orig +++ b/ext/standard/var_unserializer.c.orig @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: var_unserializer.c,v 1.70.2.4.2.7 2007/08/06 18:33:29 jani Exp $ */ +/* $Id: var_unserializer.c,v 1.70.2.4.2.8 2008/03/19 03:00:40 felipe Exp $ */ #include "php.h" #include "ext/standard/php_var.h" @@ -290,10 +290,10 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); break; case IS_STRING: - if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { + if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { var_push_dtor(var_hash, old_data); } - zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); + zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); break; } diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re index 97fd3be89..ea8ce20d3 100644 --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: var_unserializer.re,v 1.52.2.2.2.6 2007/08/06 18:23:16 jani Exp $ */ +/* $Id: var_unserializer.re,v 1.52.2.2.2.7 2008/03/19 03:00:40 felipe Exp $ */ #include "php.h" #include "ext/standard/php_var.h" @@ -294,10 +294,10 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); break; case IS_STRING: - if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { + if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { var_push_dtor(var_hash, old_data); } - zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); + zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); break; } diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index 7764b0230..7775e0249 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | + | Copyright (c) 1997-2008 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: versioning.c,v 1.19.2.1.2.3 2007/08/23 18:38:42 derick Exp $ */ +/* $Id: versioning.c,v 1.19.2.1.2.4 2007/12/31 07:20:13 sebastian Exp $ */ #include <stdio.h> #include <sys/types.h> |