php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67347 Access to static class properties inconsistent
Submitted: 2014-05-27 19:42 UTC Modified: 2014-05-28 15:00 UTC
From: fleshgrinder at gmx dot at Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.0beta3 OS: Debian Wheezy
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: fleshgrinder at gmx dot at
New email:
PHP Version: OS:

 

 [2014-05-27 19:42 UTC] fleshgrinder at gmx dot at
Description:
------------
Accessing static properties is inconsistent and doesn't make much sense.

Test script:
---------------
class Foo {

  public static $foo = "foo";

}

class Bar {

  public $foo;

  public function __construct() {
    $this->foo = new Foo();
  }

}


Expected result:
----------------
Either $foo::$foo to result in some kind of ERROR or WARNING or $bar->foo::$foo has to work as well. Otherwise it's not consistent.

Actual result:
--------------
$foo = new Foo();

echo $foo::$foo; // Works and prints 'foo'
echo $foo->foo;  // STRICT WARNING
echo $foo->$foo; // FATAL ERROR

$bar = new Bar();

echo $bar->foo::$foo; // PARSE ERROR
echo $bar->foo->foo;  // STRICT WARNING
echo $bar->foo->$foo; // FATAL ERROR

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-27 19:45 UTC] fleshgrinder at gmx dot at
Note that the following works:

$bar = new Bar();
$foo = $bar->foo;
echo $foo::$foo;  // Prints 'foo'
 [2014-05-28 15:00 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2014-05-28 15:00 UTC] bwoebi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$foo::$foo is access of a static property on a dynamic class name. Pretty clear what it should mean.

But $bar->foo::$foo isn't implemented to avoid confusion:
is it now like $a = $bar->foo; $a::$foo; or like $a = foo::$foo; $bar->$a; ?

That's why it was preferred to not implement it in the first place.
 [2014-05-29 09:32 UTC] fleshgrinder at gmx dot at
Of course $foo::$foo access is clear, it's not the problem I'm reporting.

Very interesting decision, because me and everybody I asked thinks that it's confusing as it is now and it's counter productive as well because one has to assign the object to a variable first before accessing the static property. This makes methods longer than necessary.

$foo::$foo = "foo";
$bar->foo = $foo;
$bar->foo::$foo; // "foo"

In my humble opinion nothing is confusing about $bar->foo::$foo because I can $foo::$foo as well. These two are equivalent.

$a = foo::$foo;
$bar->$a;

This code doesn't make sense to me. Why would $bar contain $a just because I assigned foo::$foo to $a. Bar doesn't have an $a property in the first place.

Would be nice if you have a link to the original discussion about this. I'll try to find it myself as well.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 15:00:01 2026 UTC