Req #67347 [Com]: Access to static class properties inconsistent

From: Date: Thu, 29 May 2014 09:32:31 +0000
Subject: Req #67347 [Com]: Access to static class properties inconsistent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185966@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67347&edit=1 ID: 67347 Comment by: fleshgrinder at gmx dot at Reported by: fleshgrinder at gmx dot at Summary: Access to static class properties inconsistent Status: Not a bug Type: Feature/Change Request Package: *General Issues Operating System: Debian Wheezy PHP Version: 5.6.0beta3 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-05-28 15:00:30] 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-27 19:45:40] fleshgrinder at gmx dot at Note that the following works: $bar = new Bar(); $foo = $bar->foo; echo $foo::$foo; // Prints 'foo' ------------------------------------------------------------------------ [2014-05-27 19:42:53] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67347&edit=1

« previous php.bugs (#185966) next »