summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-08-04 20:17:53 +0000
committerMarcus Boerger <helly@php.net>2003-08-04 20:17:53 +0000
commit91a882478f78d42ceaade980f71bb54279c633cf (patch)
tree216906dbc2ee444841e69018eaaee805115c6616
parentde32c1de56ea138220cae26e94326f166ce49947 (diff)
downloadphp-git-91a882478f78d42ceaade980f71bb54279c633cf.tar.gz
Unset support for spl_array
-rwxr-xr-xext/spl/spl_array.c41
-rwxr-xr-xext/spl/tests/array.phpt21
2 files changed, 58 insertions, 4 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index f7413f5b89..adf68cb050 100755
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -370,7 +370,7 @@ static zend_class_entry *spl_array_it_get_ce(zval *object TSRMLS_DC)
/* }}} */
/* {{{ spl_array_read_dimension */
-zval *spl_array_read_dimension(zval *object, zval *offset TSRMLS_DC)
+static zval *spl_array_read_dimension(zval *object, zval *offset TSRMLS_DC)
{
spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
zval **retval;
@@ -408,7 +408,7 @@ zval *spl_array_read_dimension(zval *object, zval *offset TSRMLS_DC)
/* }}} */
/* {{{ spl_array_write_dimension */
-void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
+static void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
{
spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
long index;
@@ -435,8 +435,40 @@ void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC
}
/* }}} */
-/* {{{*/
-HashTable *spl_array_get_properties(zval *object TSRMLS_DC)
+/* {{{ spl_array_unset_dimension */
+static void spl_array_unset_dimension(zval *object, zval *offset TSRMLS_DC)
+{
+ spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
+ long index;
+
+ switch(Z_TYPE_P(offset)) {
+ case IS_STRING:
+ if (zend_symtable_del(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) {
+ zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset));
+ }
+ return;
+ case IS_DOUBLE:
+ case IS_RESOURCE:
+ case IS_BOOL:
+ case IS_LONG:
+ if (offset->type == IS_DOUBLE) {
+ index = (long)Z_DVAL_P(offset);
+ } else {
+ index = Z_LVAL_P(offset);
+ }
+ if (zend_hash_index_del(HASH_OF(intern->array), index) == FAILURE) {
+ zend_error(E_NOTICE,"Undefined offset: %d", Z_LVAL_P(offset));
+ }
+ return;
+ default:
+ zend_error(E_WARNING, "Illegal offset type");
+ return;
+ }
+}
+/* }}} */
+
+/* {{{ spl_array_get_properties */
+static HashTable *spl_array_get_properties(zval *object TSRMLS_DC)
{
spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
@@ -454,6 +486,7 @@ PHP_MINIT_FUNCTION(spl_array)
spl_array_handlers.get_class_entry = spl_array_get_ce;
spl_array_handlers.read_dimension = spl_array_read_dimension;
spl_array_handlers.write_dimension = spl_array_write_dimension;
+ spl_array_handlers.unset_dimension = spl_array_unset_dimension;
spl_array_handlers.get_properties = spl_array_get_properties;
REGISTER_SPL_STD_CLASS_EX(array_it, spl_array_object_new, spl_array_it_class_functions);
diff --git a/ext/spl/tests/array.phpt b/ext/spl/tests/array.phpt
index 225a9f0bd1..448fc443fe 100755
--- a/ext/spl/tests/array.phpt
+++ b/ext/spl/tests/array.phpt
@@ -21,6 +21,14 @@ var_dump($ar["a"] = "a");
var_dump($ar);
var_dump($ar[0]);
var_dump($ar[6]);
+var_dump($ar["b"]);
+
+unset($ar[1]);
+unset($ar["3"]);
+unset($ar["a"]);
+unset($ar[7]);
+unset($ar["c"]);
+var_dump($ar);
echo "Done\n";
?>
@@ -64,4 +72,17 @@ int(0)
Notice: Undefined offset: 6 in %sarray.php on line %d
NULL
+
+Notice: Undefined index: b in %sarray.php on line %d
+NULL
+
+Notice: Undefined offset: 7 in %sarray.php on line %d
+
+Notice: Undefined index: c in %sarray.php on line %d
+object(spl_array)#1 (2) {
+ [0]=>
+ int(0)
+ [2]=>
+ &int(2)
+}
Done