diff options
Diffstat (limited to 'ext/spl')
32 files changed, 622 insertions, 78 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 8a7d6f32e..58bf883f0 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: php_spl.c 300176 2010-06-04 00:10:15Z felipe $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -231,6 +231,17 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension); +#if DEFAULT_SLASH != '\\' + { + char *ptr = class_file; + char *end = ptr + class_file_len; + + while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) { + *ptr = DEFAULT_SLASH; + } + } +#endif + ret = php_stream_open_for_zend_ex(class_file, &file_handle, ENFORCE_SAFE_MODE|USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); if (ret == SUCCESS) { diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index db3de0486..313e5a3d7 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_array.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: spl_array.c 299327 2010-05-13 08:09:54Z dmitry $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -320,6 +320,11 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object, return &EG(uninitialized_zval_ptr); } + if ((type == BP_VAR_W || type == BP_VAR_RW) && (ht->nApplyCount > 0)) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return &EG(uninitialized_zval_ptr);; + } + switch(Z_TYPE_P(offset)) { case IS_STRING: if (zend_symtable_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &retval) == FAILURE) { @@ -421,6 +426,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); long index; + HashTable *ht; if (check_inherited && intern->fptr_offset_set) { if (!offset) { @@ -434,30 +440,50 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval } if (!offset) { + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } Z_ADDREF_P(value); - zend_hash_next_index_insert(spl_array_get_hash_table(intern, 0 TSRMLS_CC), (void**)&value, sizeof(void*), NULL); + zend_hash_next_index_insert(ht, (void**)&value, sizeof(void*), NULL); return; } switch(Z_TYPE_P(offset)) { case IS_STRING: + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } Z_ADDREF_P(value); - zend_symtable_update(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), NULL); + zend_symtable_update(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), NULL); return; case IS_DOUBLE: case IS_RESOURCE: case IS_BOOL: case IS_LONG: + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } if (offset->type == IS_DOUBLE) { index = (long)Z_DVAL_P(offset); } else { index = Z_LVAL_P(offset); } Z_ADDREF_P(value); - zend_hash_index_update(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index, (void**)&value, sizeof(void*), NULL); + zend_hash_index_update(ht, index, (void**)&value, sizeof(void*), NULL); return; case IS_NULL: + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } Z_ADDREF_P(value); - zend_hash_next_index_insert(spl_array_get_hash_table(intern, 0 TSRMLS_CC), (void**)&value, sizeof(void*), NULL); + zend_hash_next_index_insert(ht, (void**)&value, sizeof(void*), NULL); return; default: zend_error(E_WARNING, "Illegal offset type"); @@ -474,6 +500,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); long index; + HashTable *ht; if (check_inherited && intern->fptr_offset_del) { SEPARATE_ARG_IF_REF(offset); @@ -484,12 +511,17 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval switch(Z_TYPE_P(offset)) { case IS_STRING: - if (spl_array_get_hash_table(intern, 0 TSRMLS_CC) == &EG(symbol_table)) { + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } + if (ht == &EG(symbol_table)) { if (zend_delete_global_variable(Z_STRVAL_P(offset), Z_STRLEN_P(offset) TSRMLS_CC)) { zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); } } else { - if (zend_symtable_del(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) { + if (zend_symtable_del(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) { zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); } } @@ -503,7 +535,12 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval } else { index = Z_LVAL_P(offset); } - if (zend_hash_index_del(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index) == FAILURE) { + ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (ht->nApplyCount > 0) { + zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited"); + return; + } + if (zend_hash_index_del(ht, index) == FAILURE) { zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); } break; @@ -746,7 +783,7 @@ static zval **spl_array_get_property_ptr_ptr(zval *object, zval *member TSRMLS_D if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - return spl_array_get_dimension_ptr_ptr(1, object, member, 0 TSRMLS_CC); + return spl_array_get_dimension_ptr_ptr(1, object, member, BP_VAR_RW TSRMLS_CC); } return std_object_handlers.get_property_ptr_ptr(object, member TSRMLS_CC); } /* }}} */ @@ -1303,9 +1340,13 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0 TSRMLS_CC); return; } + aht->nApplyCount++; zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval_ptr, 2, tmp, arg TSRMLS_CC); + aht->nApplyCount--; } else { + aht->nApplyCount++; zend_call_method(NULL, NULL, NULL, fname, fname_len, &retval_ptr, 1, tmp, NULL TSRMLS_CC); + aht->nApplyCount--; } Z_TYPE_P(tmp) = IS_NULL; /* we want to destroy the zval, not the hashtable */ zval_ptr_dtor(&tmp); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 5606062a7..92f89ffff 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_directory.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: spl_directory.c 298647 2010-04-27 08:56:01Z colder $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -397,6 +397,9 @@ static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC); ce = ce ? ce : source->info_class; + + zend_update_class_constants(ce TSRMLS_CC); + return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); Z_TYPE_P(return_value) = IS_OBJECT; @@ -437,6 +440,9 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil switch (type) { case SPL_FS_INFO: ce = ce ? ce : source->info_class; + + zend_update_class_constants(ce TSRMLS_CC); + return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); Z_TYPE_P(return_value) = IS_OBJECT; @@ -455,6 +461,9 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil break; case SPL_FS_FILE: ce = ce ? ce : source->file_class; + + zend_update_class_constants(ce TSRMLS_CC); + return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); Z_TYPE_P(return_value) = IS_OBJECT; @@ -1178,7 +1187,10 @@ SPL_METHOD(SplFileInfo, getPathInfo) int path_len; char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); if (path) { - spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC); + char *dpath = estrndup(path, path_len); + path_len = php_dirname(dpath, path_len); + spl_filesystem_object_create_info(intern, dpath, path_len, 1, ce, return_value TSRMLS_CC); + efree(dpath); } } @@ -2567,9 +2579,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0) ZEND_ARG_INFO(0, allowable_tags) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 1, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 0, 0, 1) ZEND_ARG_INFO(0, format) - ZEND_ARG_INFO(1, ...) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1) diff --git a/ext/spl/spl_dllist.h b/ext/spl/spl_dllist.h index 52b029c4e..08545b703 100644 --- a/ext/spl/spl_dllist.h +++ b/ext/spl/spl_dllist.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_dllist.h 294892 2010-02-11 17:24:43Z johannes $ */ +/* $Id: spl_dllist.h 293730 2010-01-19 13:24:02Z johannes $ */ #ifndef SPL_DLLIST_H #define SPL_DLLIST_H diff --git a/ext/spl/spl_fixedarray.h b/ext/spl/spl_fixedarray.h index 83e796acc..224103a85 100644 --- a/ext/spl/spl_fixedarray.h +++ b/ext/spl/spl_fixedarray.h @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_fixedarray.h 294892 2010-02-11 17:24:43Z johannes $ */ +/* $Id: spl_fixedarray.h 293721 2010-01-19 10:44:36Z johannes $ */ #ifndef SPL_FIXEDARRAY_H #define SPL_FIXEDARRAY_H diff --git a/ext/spl/spl_heap.h b/ext/spl/spl_heap.h index 0cc707d60..3a309ca35 100644 --- a/ext/spl/spl_heap.h +++ b/ext/spl/spl_heap.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_heap.h 294892 2010-02-11 17:24:43Z johannes $ */ +/* $Id: spl_heap.h 293721 2010-01-19 10:44:36Z johannes $ */ #ifndef SPL_HEAP_H #define SPL_HEAP_H diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index daf228496..f55a199fd 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_iterators.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: spl_iterators.c 301065 2010-07-07 22:46:54Z felipe $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -131,7 +131,7 @@ static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC) spl_recursive_it_object *object = (spl_recursive_it_object*)_iter->data; zend_object_iterator *sub_iter; - while (object->level) { + while (object->level > 0) { sub_iter = object->iterators[object->level].iterator; sub_iter->funcs->dtor(sub_iter TSRMLS_CC); zval_ptr_dtor(&object->iterators[object->level--].zobject); @@ -139,10 +139,10 @@ static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC) object->iterators = erealloc(object->iterators, sizeof(spl_sub_iterator)); object->level = 0; - zval_ptr_dtor(&iter->zobject); + zval_ptr_dtor(&iter->zobject); efree(iter); } - + static int spl_recursive_it_valid_ex(spl_recursive_it_object *object, zval *zthis TSRMLS_DC) { zend_object_iterator *sub_iter; @@ -536,6 +536,18 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla intern->iterators[0].state = RS_START; zend_restore_error_handling(&error_handling TSRMLS_CC); + + if (EG(exception)) { + zend_object_iterator *sub_iter; + + while (intern->level >= 0) { + sub_iter = intern->iterators[intern->level].iterator; + sub_iter->funcs->dtor(sub_iter TSRMLS_CC); + zval_ptr_dtor(&intern->iterators[intern->level--].zobject); + } + efree(intern->iterators); + intern->iterators = NULL; + } } /* {{{ proto void RecursiveIteratorIterator::__construct(RecursiveIterator|IteratorAggregate it [, int mode = RIT_LEAVES_ONLY [, int flags = 0]]) throws InvalidArgumentException @@ -778,11 +790,14 @@ static union _zend_function *spl_recursive_it_get_method(zval **object_ptr, char } /* {{{ spl_RecursiveIteratorIterator_dtor */ -static void spl_RecursiveIteratorIterator_free_storage(void *_object TSRMLS_DC) +static void spl_RecursiveIteratorIterator_dtor(zend_object *_object, zend_object_handle handle TSRMLS_DC) { spl_recursive_it_object *object = (spl_recursive_it_object *)_object; zend_object_iterator *sub_iter; + /* call standard dtor */ + zend_objects_destroy_object(_object, handle TSRMLS_CC); + if (object->iterators) { while (object->level >= 0) { sub_iter = object->iterators[object->level].iterator; @@ -792,6 +807,13 @@ static void spl_RecursiveIteratorIterator_free_storage(void *_object TSRMLS_DC) efree(object->iterators); object->iterators = NULL; } +} +/* }}} */ + +/* {{{ spl_RecursiveIteratorIterator_dtor */ +static void spl_RecursiveIteratorIterator_free_storage(void *_object TSRMLS_DC) +{ + spl_recursive_it_object *object = (spl_recursive_it_object *)_object; zend_object_std_dtor(&object->std TSRMLS_CC); smart_str_free(&object->prefix[0]); @@ -827,7 +849,7 @@ static zend_object_value spl_RecursiveIteratorIterator_new_ex(zend_class_entry * zend_object_std_init(&intern->std, class_type TSRMLS_CC); zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_RecursiveIteratorIterator_free_storage, NULL TSRMLS_CC); + retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)spl_RecursiveIteratorIterator_dtor, (zend_objects_free_object_storage_t) spl_RecursiveIteratorIterator_free_storage, NULL TSRMLS_CC); retval.handlers = &spl_handlers_rec_it_it; return retval; } @@ -1272,7 +1294,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z return NULL; } if (intern->u.limit.offset < 0) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be > 0", 0 TSRMLS_CC); + zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0 TSRMLS_CC); zend_restore_error_handling(&error_handling TSRMLS_CC); return NULL; } @@ -1909,16 +1931,26 @@ SPL_METHOD(RecursiveRegexIterator, getChildren) #endif -/* {{{ spl_dual_it_free_storage */ -static void spl_dual_it_free_storage(void *_object TSRMLS_DC) +/* {{{ spl_dual_it_dtor */ +static void spl_dual_it_dtor(zend_object *_object, zend_object_handle handle TSRMLS_DC) { spl_dual_it_object *object = (spl_dual_it_object *)_object; + /* call standard dtor */ + zend_objects_destroy_object(_object, handle TSRMLS_CC); + spl_dual_it_free(object TSRMLS_CC); if (object->inner.iterator) { object->inner.iterator->funcs->dtor(object->inner.iterator TSRMLS_CC); } +} +/* }}} */ + +/* {{{ spl_dual_it_free_storage */ +static void spl_dual_it_free_storage(void *_object TSRMLS_DC) +{ + spl_dual_it_object *object = (spl_dual_it_object *)_object; if (object->inner.zobject) { zval_ptr_dtor(&object->inner.zobject); @@ -1969,7 +2001,7 @@ static zend_object_value spl_dual_it_new(zend_class_entry *class_type TSRMLS_DC) zend_object_std_init(&intern->std, class_type TSRMLS_CC); zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_dual_it_free_storage, NULL TSRMLS_CC); + retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)spl_dual_it_dtor, (zend_objects_free_object_storage_t) spl_dual_it_free_storage, NULL TSRMLS_CC); retval.handlers = &spl_handlers_dual_it; return retval; } @@ -2080,7 +2112,7 @@ static inline void spl_limit_it_seek(spl_dual_it_object *intern, long pos TSRMLS zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Cannot seek to %ld which is behind offset %ld plus count %ld", pos, intern->u.limit.offset, intern->u.limit.count); return; } - if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator TSRMLS_CC)) { + if (pos != intern->current.pos && instanceof_function(intern->inner.ce, spl_ce_SeekableIterator TSRMLS_CC)) { MAKE_STD_ZVAL(zpos); ZVAL_LONG(zpos, pos); spl_dual_it_free(intern TSRMLS_CC); @@ -3035,7 +3067,9 @@ PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, v } done: - iter->funcs->dtor(iter TSRMLS_CC); + if (iter) { + iter->funcs->dtor(iter TSRMLS_CC); + } return EG(exception) ? FAILURE : SUCCESS; } /* }}} */ diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 75855ada4..290297290 100755 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_observer.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: spl_observer.c 300843 2010-06-29 00:58:31Z stas $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -115,6 +115,7 @@ static void spl_object_storage_dtor(spl_SplObjectStorageElement *element) /* {{{ zval_ptr_dtor(&element->inf); } /* }}} */ + spl_SplObjectStorageElement* spl_object_storage_get(spl_SplObjectStorage *intern, zval *obj TSRMLS_DC) /* {{{ */ { spl_SplObjectStorageElement *element; @@ -632,15 +633,24 @@ SPL_METHOD(SplObjectStorage, unserialize) zval_ptr_dtor(&pcount); while(count-- > 0) { + spl_SplObjectStorageElement *pelement; + if (*p != ';') { goto outexcept; } ++p; + if(*p != 'O' && *p != 'C' && *p != 'r') { + goto outexcept; + } ALLOC_INIT_ZVAL(pentry); if (!php_var_unserialize(&pentry, &p, s + buf_len, &var_hash TSRMLS_CC)) { zval_ptr_dtor(&pentry); goto outexcept; } + if(Z_TYPE_P(pentry) != IS_OBJECT) { + zval_ptr_dtor(&pentry); + goto outexcept; + } ALLOC_INIT_ZVAL(pinf); if (*p == ',') { /* new version has inf */ ++p; @@ -649,6 +659,16 @@ SPL_METHOD(SplObjectStorage, unserialize) goto outexcept; } } + + pelement = spl_object_storage_get(intern, pentry TSRMLS_CC); + if(pelement) { + if(pelement->inf) { + var_push_dtor(&var_hash, &pelement->inf); + } + if(pelement->obj) { + var_push_dtor(&var_hash, &pelement->obj); + } + } spl_object_storage_attach(intern, pentry, pinf TSRMLS_CC); zval_ptr_dtor(&pentry); zval_ptr_dtor(&pinf); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt new file mode 100644 index 000000000..ba53a1891 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +SplFileObject::fgetcsv default path +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fputcsv($fp, array( + 'field1', + 'field2', + 'field3', + 5 +)); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv()); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +array(4) { + [0]=> + string(6) "field1" + [1]=> + string(6) "field2" + [2]=> + string(6) "field3" + [3]=> + string(1) "5" +} diff --git a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt new file mode 100644 index 000000000..38b32c234 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fputcsv($fp, array( + 'field1', + 'field2', + 'field3', + 5 +), '|'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv('|')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +array(4) { + [0]=> + string(6) "field1" + [1]=> + string(6) "field2" + [2]=> + string(6) "field3" + [3]=> + string(1) "5" +} diff --git a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt new file mode 100644 index 000000000..42677cca4 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fputcsv($fp, array( + 'field1', + 'field2', + 'field3', + 5 +), '|'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv('invalid')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +Warning: SplFileObject::fgetcsv(): delimiter must be a character in %s on line %d +bool(false) diff --git a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt new file mode 100644 index 000000000..ab071acac --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fputcsv($fp, array( + 'field1', + 'field2', + 'field3', + 5 +), ',', '"'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv(',', '"')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +array(4) { + [0]=> + string(6) "field1" + [1]=> + string(6) "field2" + [2]=> + string(6) "field3" + [3]=> + string(1) "5" +} diff --git a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt new file mode 100644 index 000000000..afc8ad3f0 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fputcsv($fp, array( + 'field1', + 'field2', + 'field3', + 5 +), ',', '"'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv(',', 'invalid')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +Warning: SplFileObject::fgetcsv(): enclosure must be a character in %s on line %d +bool(false) diff --git a/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt new file mode 100644 index 000000000..1e2e273ae --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fwrite($fp, '"aaa","b""bb","ccc"'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv(',', '"', '"')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +array(3) { + [0]=> + string(3) "aaa" + [1]=> + string(4) "b"bb" + [2]=> + string(3) "ccc" +} diff --git a/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt new file mode 100644 index 000000000..8dcfc9220 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +SplFileObject::fgetcsv with alternative delimeter +--FILE-- +<?php +$fp = fopen('SplFileObject::fgetcsv.csv', 'w+'); +fwrite($fp, '"aaa","b""bb","ccc"'); +fclose($fp); + +$fo = new SplFileObject('SplFileObject::fgetcsv.csv'); +var_dump($fo->fgetcsv(',', '"', 'invalid')); +?> +--CLEAN-- +<?php +unlink('SplFileObject::fgetcsv.csv'); +?> +--EXPECTF-- +Warning: SplFileObject::fgetcsv(): escape must be a character in %s on line %d +bool(false) diff --git a/ext/spl/tests/SplObjectStorage_unserialize_bad.phpt b/ext/spl/tests/SplObjectStorage_unserialize_bad.phpt new file mode 100644 index 000000000..9e3f3605b --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_unserialize_bad.phpt @@ -0,0 +1,45 @@ +--TEST-- +SPL: Test that serialized blob contains unique elements (CVE-2010-2225) +--FILE-- +<?php + +$badblobs = array( +'x:i:2;i:0;,i:1;;i:0;,i:2;;m:a:0:{}', +'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};R:1;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}', +'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};r:1;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}', +); +foreach($badblobs as $blob) { +try { + $so = new SplObjectStorage(); + $so->unserialize($blob); + var_dump($so); +} catch(UnexpectedValueException $e) { + echo $e->getMessage()."\n"; +} +} +--EXPECTF-- +Error at offset 6 of 34 bytes +Error at offset 46 of 89 bytes +object(SplObjectStorage)#2 (1) { + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + array(2) { + ["obj"]=> + object(stdClass)#3 (0) { + } + ["inf"]=> + int(1) + } + ["%s"]=> + array(2) { + ["obj"]=> + object(stdClass)#1 (0) { + } + ["inf"]=> + object(stdClass)#4 (0) { + } + } + } +} + diff --git a/ext/spl/tests/SplObjectStorage_unserialize_nested.phpt b/ext/spl/tests/SplObjectStorage_unserialize_nested.phpt new file mode 100644 index 000000000..56e83f805 --- /dev/null +++ b/ext/spl/tests/SplObjectStorage_unserialize_nested.phpt @@ -0,0 +1,47 @@ +--TEST-- +SPL: Test unserializing tested & linked storage +--FILE-- +<?php +$o = new StdClass(); +$a = new StdClass(); + +$o->a = $a; + +$so = new SplObjectStorage(); + +$so[$o] = 1; +$so[$a] = 2; + +$s = serialize($so); +echo $s."\n"; + +$so1 = unserialize($s); +var_dump($so1); + +--EXPECTF-- +C:16:"SplObjectStorage":76:{x:i:2;O:8:"stdClass":1:{s:1:"a";O:8:"stdClass":0:{}},i:1;;r:2;,i:2;;m:a:0:{}} +object(SplObjectStorage)#4 (1) { + ["storage":"SplObjectStorage":private]=> + array(2) { + ["%s"]=> + array(2) { + ["obj"]=> + object(stdClass)#5 (1) { + ["a"]=> + object(stdClass)#6 (0) { + } + } + ["inf"]=> + int(1) + } + ["%s"]=> + array(2) { + ["obj"]=> + object(stdClass)#6 (0) { + } + ["inf"]=> + int(2) + } + } +} + diff --git a/ext/spl/tests/SplObjectStorage_var_dump.phpt b/ext/spl/tests/SplObjectStorage_var_dump.phpt index c1c7158ec..0439f465c 100644 --- a/ext/spl/tests/SplObjectStorage_var_dump.phpt +++ b/ext/spl/tests/SplObjectStorage_var_dump.phpt @@ -8,28 +8,16 @@ $o[new StdClass] = $o; var_dump($o); --EXPECTF-- -object(SplObjectStorage)#1 (1) { +object(SplObjectStorage)#%d (1) { ["storage":"SplObjectStorage":private]=> array(1) { ["%s"]=> array(2) { ["obj"]=> - object(stdClass)#2 (0) { + object(stdClass)#%d (0) { } ["inf"]=> - object(SplObjectStorage)#1 (1) { - ["storage":"SplObjectStorage":private]=> - array(1) { - ["%s"]=> - array(2) { - ["obj"]=> - object(stdClass)#2 (0) { - } - ["inf"]=> - *RECURSION* - } - } - } + *RECURSION* } } } diff --git a/ext/spl/tests/SplTempFileObject_constructor_basic.phpt b/ext/spl/tests/SplTempFileObject_constructor_basic.phpt new file mode 100644 index 000000000..b2e640c7a --- /dev/null +++ b/ext/spl/tests/SplTempFileObject_constructor_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL SplTempFileObject constructor sets correct defaults when pass 0 arguments +--FILE-- +<?php +var_dump(new SplTempFileObject()); +?> +--EXPECTF-- +object(SplTempFileObject)#1 (5) { + ["pathName":"SplFileInfo":private]=> + string(10) "php://temp" + ["fileName":"SplFileInfo":private]=> + string(10) "php://temp" + ["openMode":"SplFileObject":private]=> + string(1) "w" + ["delimiter":"SplFileObject":private]=> + string(1) "," + ["enclosure":"SplFileObject":private]=> + string(1) """ +} diff --git a/ext/spl/tests/SplTempFileObject_constructor_error.phpt b/ext/spl/tests/SplTempFileObject_constructor_error.phpt new file mode 100644 index 000000000..d2717ac5a --- /dev/null +++ b/ext/spl/tests/SplTempFileObject_constructor_error.phpt @@ -0,0 +1,12 @@ +--TEST-- +SPL SplTempFileObject constructor sets correct defaults when pass 0 arguments +--FILE-- +<?php +new SplTempFileObject('invalid'); +?> +--EXPECTF-- +Fatal error: Uncaught exception 'RuntimeException' with message 'SplTempFileObject::__construct() expects parameter 1 to be long, string given' in %s +Stack trace: +#0 %s: SplTempFileObject->__construct('invalid') +#1 {main} + thrown in %s diff --git a/ext/spl/tests/SplTempFileObject_constructor_maxmemory_basic.phpt b/ext/spl/tests/SplTempFileObject_constructor_maxmemory_basic.phpt new file mode 100644 index 000000000..2ef1b2cd1 --- /dev/null +++ b/ext/spl/tests/SplTempFileObject_constructor_maxmemory_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL SplTempFileObject constructor sets correct values when passed fixed memory size +--FILE-- +<?php +var_dump(new SplTempFileObject(1024)); +?> +--EXPECTF-- +object(SplTempFileObject)#1 (5) { + ["pathName":"SplFileInfo":private]=> + string(25) "php://temp/maxmemory:1024" + ["fileName":"SplFileInfo":private]=> + string(25) "php://temp/maxmemory:1024" + ["openMode":"SplFileObject":private]=> + string(1) "w" + ["delimiter":"SplFileObject":private]=> + string(1) "," + ["enclosure":"SplFileObject":private]=> + string(1) """ +} diff --git a/ext/spl/tests/SplTempFileObject_constructor_memory_lt1_variation.phpt b/ext/spl/tests/SplTempFileObject_constructor_memory_lt1_variation.phpt new file mode 100644 index 000000000..9fe589211 --- /dev/null +++ b/ext/spl/tests/SplTempFileObject_constructor_memory_lt1_variation.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL SplTempFileObject constructor sets correct defaults when passed a negative value +--FILE-- +<?php +var_dump(new SplTempFileObject(-1)); +?> +--EXPECTF-- +object(SplTempFileObject)#1 (5) { + ["pathName":"SplFileInfo":private]=> + string(12) "php://memory" + ["fileName":"SplFileInfo":private]=> + string(12) "php://memory" + ["openMode":"SplFileObject":private]=> + string(1) "w" + ["delimiter":"SplFileObject":private]=> + string(1) "," + ["enclosure":"SplFileObject":private]=> + string(1) """ +} diff --git a/ext/spl/tests/array_027.phpt b/ext/spl/tests/array_027.phpt index 791e76322..509b8f9ff 100644 --- a/ext/spl/tests/array_027.phpt +++ b/ext/spl/tests/array_027.phpt @@ -9,16 +9,10 @@ $o['plop'] = $o; var_dump($o); --EXPECTF-- -object(AO)#1 (1) { +object(AO)#%d (1) { ["storage":"ArrayObject":private]=> array(1) { ["plop"]=> - object(AO)#1 (1) { - ["storage":"ArrayObject":private]=> - array(1) { - ["plop"]=> - *RECURSION* - } - } + *RECURSION* } } diff --git a/ext/spl/tests/bug48361.phpt b/ext/spl/tests/bug48361.phpt new file mode 100644 index 000000000..44b05abba --- /dev/null +++ b/ext/spl/tests/bug48361.phpt @@ -0,0 +1,14 @@ +--TEST-- +SPL: Bug #48361 SpleFileInfo::getPathName should return the dirname's path +--FILE-- +<?php +$info = new SplFileInfo(__FILE__); +var_dump($info->getRealPath()); +var_dump($info->getPathInfo()->getRealPath()); +?> +===DONE=== +--EXPECTF-- +string(%d) "%stests%sbug48361.php" +string(%d) "%stests" +===DONE=== + diff --git a/ext/spl/tests/bug49723.phpt b/ext/spl/tests/bug49723.phpt new file mode 100644 index 000000000..221e80661 --- /dev/null +++ b/ext/spl/tests/bug49723.phpt @@ -0,0 +1,16 @@ +--TEST-- +LimitIterator: do not seek if not needed +--FILE-- +<?php + +$it = new ArrayIterator(array()); + +$lit = new LimitIterator($it, 0, 5); + +foreach ($lit as $v) { + echo $v; +} +?> +===DONE=== +--EXPECT-- +===DONE=== diff --git a/ext/spl/tests/bug51119.phpt b/ext/spl/tests/bug51119.phpt new file mode 100644 index 000000000..441aa1280 --- /dev/null +++ b/ext/spl/tests/bug51119.phpt @@ -0,0 +1,34 @@ +--TEST-- +SPL: LimitIterator zero is valid offset +--FILE-- +<?php + +$array = array('a', 'b', 'c'); +$arrayIterator = new ArrayIterator($array); + +try { + $limitIterator = new LimitIterator($arrayIterator, 0); + foreach ($limitIterator as $item) { + echo $item . "\n"; + } +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + +try { + $limitIterator = new LimitIterator($arrayIterator, -1); + foreach ($limitIterator as $item) { + echo $item . "\n"; + } +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + +?> +===DONE=== +--EXPECT-- +a +b +c +Parameter offset must be >= 0 +===DONE=== diff --git a/ext/spl/tests/bug51374.phpt b/ext/spl/tests/bug51374.phpt new file mode 100644 index 000000000..a4d285322 --- /dev/null +++ b/ext/spl/tests/bug51374.phpt @@ -0,0 +1,19 @@ +--TEST-- +SPL: SplFileObject wrongly initializes objects +--FILE-- +<?php +class Foo extends SplFileObject +{ + public $bam = array(); +} +$fileInfo = new SplFileInfo('php://temp'); +$fileInfo->setFileClass('Foo'); +$file = $fileInfo->openFile('r'); + +print var_dump($file->bam); // is null or UNKNOWN:0 +?> +===DONE=== +--EXPECT-- +array(0) { +} +===DONE=== diff --git a/ext/spl/tests/bug51532.phpt b/ext/spl/tests/bug51532.phpt new file mode 100644 index 000000000..3a0722b2a --- /dev/null +++ b/ext/spl/tests/bug51532.phpt @@ -0,0 +1,14 @@ +--TEST-- +SPL: Allow valid extension of SplFileObject::fscanf +--FILE-- +<?php + +class A extends SplFileObject { + public function fscanf($format) { + + } +} +?> +===DONE=== +--EXPECT-- +===DONE=== diff --git a/ext/spl/tests/bug52238.phpt b/ext/spl/tests/bug52238.phpt new file mode 100644 index 000000000..85410bdf1 --- /dev/null +++ b/ext/spl/tests/bug52238.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #52238 - Crash when an Exception occured in iterator_to_array +--FILE-- +<?php +class Foo implements IteratorAggregate +{ + public function bar() { + throw new Exception; + } + + public function getIterator() { + return new ArrayIterator($this->bar()); + } +} +var_dump(iterator_to_array(new Foo)); +?> +--EXPECTF-- +Fatal error: Uncaught exception 'Exception' in %s +Stack trace: +#0 %s: Foo->bar() +#1 [internal function]: Foo->getIterator() +#2 %s: iterator_to_array(Object(Foo)) +#3 {main} + thrown in %s on line %d diff --git a/ext/spl/tests/dllist_012.phpt b/ext/spl/tests/dllist_012.phpt index 75783fc8c..4eec9bda3 100644 --- a/ext/spl/tests/dllist_012.phpt +++ b/ext/spl/tests/dllist_012.phpt @@ -8,22 +8,14 @@ $a[] = $a; var_dump($a); ?> ===DONE=== ---EXPECT-- -object(SplDoublyLinkedList)#1 (2) { +--EXPECTF-- +object(SplDoublyLinkedList)#%d (2) { ["flags":"SplDoublyLinkedList":private]=> int(0) ["dllist":"SplDoublyLinkedList":private]=> array(1) { [0]=> - object(SplDoublyLinkedList)#1 (2) { - ["flags":"SplDoublyLinkedList":private]=> - int(0) - ["dllist":"SplDoublyLinkedList":private]=> - array(1) { - [0]=> - *RECURSION* - } - } + *RECURSION* } } ===DONE=== diff --git a/ext/spl/tests/heap_012.phpt b/ext/spl/tests/heap_012.phpt index bf00f50cc..f86f14f4d 100644 --- a/ext/spl/tests/heap_012.phpt +++ b/ext/spl/tests/heap_012.phpt @@ -7,8 +7,8 @@ $a->insert($a); var_dump($a) ?> ===DONE=== ---EXPECT-- -object(SplMaxHeap)#1 (3) { +--EXPECTF-- +object(SplMaxHeap)#%d (3) { ["flags":"SplHeap":private]=> int(0) ["isCorrupted":"SplHeap":private]=> @@ -16,17 +16,7 @@ object(SplMaxHeap)#1 (3) { ["heap":"SplHeap":private]=> array(1) { [0]=> - object(SplMaxHeap)#1 (3) { - ["flags":"SplHeap":private]=> - int(0) - ["isCorrupted":"SplHeap":private]=> - bool(false) - ["heap":"SplHeap":private]=> - array(1) { - [0]=> - *RECURSION* - } - } + *RECURSION* } } ===DONE=== diff --git a/ext/spl/tests/spl_limit_iterator_check_limits.phpt b/ext/spl/tests/spl_limit_iterator_check_limits.phpt index 01436a8fb..ae1bc85e8 100644 --- a/ext/spl/tests/spl_limit_iterator_check_limits.phpt +++ b/ext/spl/tests/spl_limit_iterator_check_limits.phpt @@ -32,6 +32,6 @@ try { ?> ===DONE=== --EXPECTF-- -Parameter offset must be > 0 +Parameter offset must be >= 0 Parameter count must either be -1 or a value greater than or equal 0 ===DONE=== |