From 7a4b594c6f040d012f7606ddd8fe378d4b01bc37 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 3 Aug 2020 11:16:59 +0200 Subject: [PATCH] Convert SPL illegal offset type into TypeError Make this consistent with the corresponding engine behavior. Also adjust the messages to match. --- ext/spl/spl_array.c | 8 ++-- ext/spl/tests/ArrayObject_illegal_offset.phpt | 39 +++++++++++++++++++ .../ArrayObject_illegal_offset_leak.phpt | 11 ------ 3 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 ext/spl/tests/ArrayObject_illegal_offset.phpt delete mode 100644 ext/spl/tests/ArrayObject_illegal_offset_leak.phpt 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-- +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-- - ---EXPECTF-- -Warning: Illegal offset type in %s on line %d -- 2.40.0