php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80945 "Notice: Undefined index" on unset() ArrayObject non-existing key
Submitted: 2021-04-09 14:04 UTC Modified: 2021-05-05 15:13 UTC
From: php at yopmail dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 7.4.16 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 + 35 = ?
Subscribe to this entry?

 
 [2021-04-09 14:04 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-05 14:35 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-05-05 14:35 UTC] 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-05-05 15:13 UTC] nikic@php.net
-Type: Documentation Problem +Type: Bug
 [2021-05-05 15:13 UTC] 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-06-14 08:15 UTC] git@php.net
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()
 [2021-06-14 08:15 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 11:01:32 2024 UTC