Bug #74188 [Com]: Null coalescing operator fails for undeclared static class properties & constant
[email protected] ("pandenitz at mail dot ru")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=74188&edit=1
ID: 74188
Comment by: pandenitz at mail dot ru
Reported by: pandenitz at mail dot ru
Summary: Null coalescing operator fails for undeclared static
class properties & constant
Status: Verified
Type: Bug
Package: Variables related
Operating System: Win 7 64
PHP Version: 7.0.16
Assigned To: tpunt
Block user comment: N
Private report: N
New Comment:
We can use isset() for variables as well :) Why not to make it work with constants? Anyway, static class properties are more important.
Previous Comments:
------------------------------------------------------------------------
[2017-03-27 19:11:58] [email protected]
The null coalescing operator should not be used to check whether a constant has been defined or not - that's what the defined() function is for.
------------------------------------------------------------------------
[2017-03-27 08:10:43] pandenitz at mail dot ru
Same for class constants.
------------------------------------------------------------------------
[2017-03-01 17:05:48] pandenitz at mail dot ru
I guess it's same in PHP 7.1
------------------------------------------------------------------------
[2017-03-01 07:42:17] pandenitz at mail dot ru
Description:
------------
Null coalescing operator doesn't check isset() for static properties
Test script:
---------------
abstract class Test
{
public static function get()
{
return static::$test ?? true;
}
public static function get2()
{
return isset(static::$test) ? static::$test : true;
}
}
// Access to undeclared static property
Test::get();
// Works
Test::get2();
Expected result:
----------------
No errors
Actual result:
--------------
Error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74188&edit=1