Doc->Bug #80945 [Opn]: "Notice: Undefined index" on unset() ArrayObject non-existing key
| From: | nikic@php.net | Date: | Wed, 05 May 2021 15:13:08 +0000 |
| Subject: | Doc->Bug #80945 [Opn]: "Notice: Undefined index" on unset() ArrayObject non-existing key | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233696@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80945&edit=1
ID: 80945
Updated by: nikic@php.net
Reported by: php at yopmail dot com
Summary: "Notice: Undefined index" on unset() ArrayObject
non-existing key
Status: Open
-Type: Documentation Problem
+Type: Bug
Package: SPL related
PHP Version: 7.4.16
Block user comment: N
Private report: N
New Comment:
I think we do try to match behavior between array and ArrayObject, so I'd personally drop the
warning in the implementation.
Previous Comments:
------------------------------------------------------------------------
[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