Bug #77681 [Opn->Nab]: Typecasting with null coalescing operator and ArrayAccess
| From: | requinix@php.net | Date: | Thu, 28 Feb 2019 18:08:56 +0000 |
| Subject: | Bug #77681 [Opn->Nab]: Typecasting with null coalescing operator and ArrayAccess | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219769@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77681&edit=1
ID: 77681
Updated by: requinix@php.net
Reported by: palmer dot andy at gmail dot com
Summary: Typecasting with null coalescing operator and
ArrayAccess
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.3.2
Block user comment: N
Private report: N
New Comment:
http://php.net/manual/en/language.operators.precedence.php
Typecasts have higher precedence than ??
Previous Comments:
------------------------------------------------------------------------
[2019-02-28 16:36:05] palmer dot andy at gmail dot com
Description:
------------
This is very similar to https://bugs.php.net/bug.php?id=71731 - the only
difference being that I am typecasting.
It seems when typecasting is used, offsetExists is never called. It doesn't matter whether I
try to typecast to string or int.
Test script:
---------------
<?php
$data = new class implements \ArrayAccess
{
public function offsetExists($offset)
{
echo "offsetExists\n";
}
public function offsetGet($offset)
{
echo "offsetGet\n";
}
public function offsetSet($offset, $value)
{
}
public function offsetUnset($offset)
{
}
};
echo "null coalescing operator:\n";
$data['foo'] ?? null;
echo "null coalescing operator (typecast):\n";
(int)$data['foo'] ?? null;
Expected result:
----------------
null coalescing operator:
offsetExists
null coalescing operator (typecast):
offsetExists
Actual result:
--------------
null coalescing operator:
offsetExists
null coalescing operator (typecast):
offsetGet
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77681&edit=1