php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74188 Null coalescing operator fails for undeclared static class properties
Submitted: 2017-03-01 07:42 UTC Modified: 2017-04-11 07:08 UTC
From: pandenitz at mail dot ru Assigned: tpunt (profile)
Status: Closed Package: Variables related
PHP Version: 7.0.16 OS: Win 7 64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pandenitz at mail dot ru
New email:
PHP Version: OS:

 

 [2017-03-01 07:42 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-01 13:39 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2017-03-01 17:05 UTC] pandenitz at mail dot ru
I guess it's same in PHP 7.1
 [2017-03-26 16:37 UTC] tpunt@php.net
-Assigned To: +Assigned To: tpunt
 [2017-03-27 08:10 UTC] pandenitz at mail dot ru
-Summary: Null coalescing operator issue with undeclared static class properties +Summary: Null coalescing operator fails for undeclared static class properties & constant
 [2017-03-27 08:10 UTC] pandenitz at mail dot ru
Same for class constants.
 [2017-03-27 19:11 UTC] tpunt@php.net
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-28 06:08 UTC] pandenitz at mail dot ru
We can use isset() for variables as well :) Why not to make it work with constants? Anyway, static class properties are more important.
 [2017-04-09 13:31 UTC] nikic@php.net
-Summary: Null coalescing operator fails for undeclared static class properties & constant +Summary: Null coalescing operator fails for undeclared static class properties
 [2017-04-10 21:21 UTC] tpunt@php.net
-Status: Verified +Status: Closed
 [2017-04-11 07:08 UTC] pandenitz at mail dot ru
Why the issue was closed?
 [2017-04-11 13:26 UTC] tpunt@php.net
This issue was fixed in the 7.0, 7.1, and master branches. It should therefore be in the 7.0.19 and 7.1.5 releases next month.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 05:01:27 2024 UTC