Class constants on object references have variable-inconsistent accessibility

From: Date: Wed, 17 Feb 2016 17:46:41 +0000
Subject: Class constants on object references have variable-inconsistent accessibility
Groups: php.internals 
Request: Send a blank email to internals+get-91253@lists.php.net to get a copy of this message
Dear internals! I have encountered an inconsistence, or rather a bug, in PHP's syntax. The thing is, in PHP you can access constants defined on a class using reference to an instance of this class, stored in variable. So we have a code: <?php class B { const C = 4; } $b = new B; var_dump($b::C === B::C); // bool(true) ?> Which will nicely pass. But things will go wrong having a code trying to access the same constant on an object of B stored in member variable of class A -- let's see below: <?php class A { /** @var B */ public $b; } $a = new A; $a->b = new B; var_dump($a->b::C === B::C); // Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in... ?> Let me conclude that if there's access to class' constant using a reference to an instance of the class, it should be possible with any type of value-holder (so-called variable). -- Cheers, Kubis

« previous php.internals (#91253) next »