Bug #80945 [Opn->Csd]: "Notice: Undefined index" on unset() ArrayObject non-existing key
Edit report at https://bugs.php.net/bug.php?id=80945&edit=1
ID: 80945
Updated by: git@php.net
Reported by: php at yopmail dot com
Summary: "Notice: Undefined index" on unset() ArrayObject
non-existing key
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
PHP Version: 7.4.16
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/71fb83567f3a3f3b176e18894d7ba7bef0aba5c1
Log: Fix bug #80945: Don't throw undefined array key warning in ArrayObject unset()
Previous Comments:
------------------------------------------------------------------------
[2021-05-05 15:13:08] nikic@php.net
I think we do try to match behavior between array and ArrayObject, so I'd personally drop the
warning in the implementation.
------------------------------------------------------------------------
[2021-05-05 14:35:52] cmb@php.net
These notices/warnings look intentional[1]. Changing to doc
issue.
[1] <https://github.com/php/php-src/blob/php-7.4.19/ext/spl/spl_array.c#L544-L602>
------------------------------------------------------------------------
[2021-04-09 14:04:38] php at yopmail dot com
Description:
------------
Unsetting a non-existing key on an ArrayObject triggers a notice (even a warning in PHP 8),
while it doesn't on an array.
More complete example: https://3v4l.org/WVJnf
Test script:
---------------
<?php
$arr = array();
unset($arr['nonexisting_1']);
$obj = new ArrayObject();
unset($obj['nonexisting_2']);
Expected result:
----------------
(nothing)
Actual result:
--------------
Notice: Undefined index: nonexisting_2 in [...] on line 7
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80945&edit=1
Thread (3 messages)