php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78960 Const Privacy on static:: doesn't match func privacy on static::
Submitted: 2019-12-13 20:29 UTC Modified: 2020-04-07 10:56 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: donatj at gmail dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.4.0 OS: All
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: donatj at gmail dot com
New email:
PHP Version: OS:

 

 [2019-12-13 20:29 UTC] donatj at gmail dot com
Description:
------------
Calls to private static methods and members from the same class via static:: work in the same class extended by another class.

Calls to private constants from the same class via static:: do not work.

Test script:
---------------
https://3v4l.org/HiPuc

Expected result:
----------------
Expect uniform behaviour in one way or the other.

Actual result:
--------------
Private methods and members are accessible. Constants are not.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-13 20:31 UTC] stas@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2020-02-07 22:39 UTC] googleguy@php.net
Including test script in report since link may vanish

Test script:
------------

<?php

class A {
	
	private static function VALUE1(){
	    return 'func';
	}
	
	private static $VALUE2 = 'var';
	
	private const VALUE3 = 'cost';

	public static function func_value(){
		return static::VALUE1();
	}
	
	public static function member_value(){
	    return static::$VALUE2;
	}
	
	public static function const_value(){
	    return static::VALUE3;
	}

}

class B extends A { }

echo A::func_value();
echo "\n";
echo B::func_value();

echo "\n---\n";

echo A::member_value();
echo "\n";
echo B::member_value();

echo "\n---\n";

echo A::const_value();
echo "\n";
echo B::const_value();
 [2020-04-07 10:47 UTC] riikka dot kalliomaki at gmail dot com
Also ran into this problem in the context of using isset(). Would be nice to know whether this is considered a bug or a feature going forward so that I would know whether to wait for a fix or not before upgrade. The following test script can also illustrate the issue:

https://3v4l.org/3cJ5N


Test script:
---------------
<?php

class foo {
    private static $foo = true;
    
    public static function test() {
        var_dump(isset(static::$foo));
    }
}

class none extends foo {
   
}

class overmethod extends foo {
    public static function test() {
        var_dump(isset(static::$foo));
    }
}

class overprop extends foo {
    private static $foo = null;
}

none::test();
overmethod::test();
overprop::test();

Expected result:
----------------
bool(false)
bool(false)
bool(false)

Actual result:
--------------
bool(true)
bool(false)
bool(false)
 [2020-04-07 10:56 UTC] nikic@php.net
@riikka dot kalliomaki at gmail dot com: The behavior for static properties was fixed in 7.4 already, this bug is about the remaining issue for class constants.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 12:01:29 2025 UTC