com php-src: Convert SPL illegal offset type into TypeError: ext/spl/spl_array.c ext/spl/tests/ArrayObject_illegal _offset.phpt
ext/spl/tests/ArrayObject_illegal_offset _leak.phpt

From: Date: Mon, 03 Aug 2020 09:17:49 +0000
Subject: com php-src: Convert SPL illegal offset type into TypeError: ext/spl/spl_array.c ext/spl/tests/ArrayObject_illegal _offset.phpt
ext/spl/tests/ArrayObject_illegal_offset _leak.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-112507@lists.php.net to get a copy of this message
Commit: 7a4b594c6f040d012f7606ddd8fe378d4b01bc37 Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 3 Aug 2020 11:16:59 +0200 Parents: e1f55de8b94d6f4fe1da3d88134414ab49eb43f8 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7a4b594c6f040d012f7606ddd8fe378d4b01bc37 Log: Convert SPL illegal offset type into TypeError Make this consistent with the corresponding engine behavior.. Also adjust the messages to match. Changed paths: M ext/spl/spl_array.c A ext/spl/tests/ArrayObject_illegal_offset.phpt D ext/spl/tests/ArrayObject_illegal_offset_leak.phpt Diff: diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 69d79a7501..67539b1745 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -375,7 +375,7 @@ num_index: ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Illegal offset type"); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -499,7 +499,7 @@ num_index: ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Illegal offset type"); zval_ptr_dtor(value); return; } @@ -585,7 +585,7 @@ num_index: ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Illegal offset type in unset"); return; } } /* }}} */ @@ -661,7 +661,7 @@ num_index: ZVAL_DEREF(offset); goto try_again; default: - zend_error(E_WARNING, "Illegal offset type"); + zend_type_error("Illegal offset type in isset or empty"); return 0; } diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt new file mode 100644 index 0000000000..df25e4fa5e --- /dev/null +++ b/ext/spl/tests/ArrayObject_illegal_offset.phpt @@ -0,0 +1,39 @@ +--TEST-- +ArrayObject illegal offset +--FILE-- +<?php + +$ao = new ArrayObject([1, 2, 3]); +try { + var_dump($ao[[]]); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + $ao[[]] = new stdClass; +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + $ref =& $ao[[]]; +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(isset($ao[[]])); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +try { + unset($ao[[]]); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Illegal offset type +Illegal offset type +Illegal offset type +Illegal offset type in isset or empty +Illegal offset type in unset diff --git a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt b/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt deleted file mode 100644 index 42c649db9f..0000000000 --- a/ext/spl/tests/ArrayObject_illegal_offset_leak.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Assignments to illegal ArrayObject offsets shouldn't leak ---FILE-- -<?php - -$ao = new ArrayObject([1, 2, 3]); -$ao[[]] = new stdClass; - -?> ---EXPECTF-- -Warning: Illegal offset type in %s on line %d

« previous php.cvs (#112507) next »