Doc #80040 [Csd->Nab]: Null coalescing operator ignores notices and warnings
| From: | requinix@php.net | Date: | Mon, 31 Aug 2020 14:11:25 +0000 |
| Subject: | Doc #80040 [Csd->Nab]: Null coalescing operator ignores notices and warnings | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17845@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80040&edit=1
ID: 80040
Updated by: requinix@php.net
Reported by: skeeman at inbox dot ru
Summary: Null coalescing operator ignores notices and
warnings
-Status: Closed
+Status: Not a bug
Type: Documentation Problem
-Package: Compile Warning
+Package: *General Issues
Operating System: Ubuntu 18.04
PHP Version: 7.4.9
Block user comment: N
Private report: N
New Comment:
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
Previous Comments:
------------------------------------------------------------------------
[2020-08-31 13:47:14] skeeman at inbox dot ru
figured out
------------------------------------------------------------------------
[2020-08-31 13:25:32] skeeman at inbox dot ru
PHP Notice: Undefined offset: 0 in /directory/file on line 14*
------------------------------------------------------------------------
[2020-08-31 13:20:05] skeeman at inbox dot ru
Description:
------------
---
From manual page: https://php.net/migration70.new-features
---
I really don't know - is this a bug or a feature? Is this a safe behavior? Can I count on this
behavior and use it in the future?
Thank you for your answer!
Test script:
---------------
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
class A {
public function test()
{
return [];
}
}
$obj = new A();
$result = $obj->test()[0] ?? null;
var_dump($result);
Expected result:
----------------
PHP Notice: Undefined offset: 0 in /directory/file on line 15
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80040&edit=1