Req #60202 [Opn->Bgs]: Please add __STATIC__ magic constant

From: Date: Wed, 02 Nov 2011 17:05:43 +0000
Subject: Req #60202 [Opn->Bgs]: Please add __STATIC__ magic constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-164819@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60202&edit=1 ID: 60202 Updated by: johannes@php.net Reported by: cmanley at office dot caiw dot nl Summary: Please add __STATIC__ magic constant -Status: Open +Status: Bogus Type: Feature/Change Request Package: *General Issues PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: You can use the static keyword for that. See http://php.net/lsb Previous Comments: ------------------------------------------------------------------------ [2011-11-02 14:20:58] cmanley at office dot caiw dot nl Description: ------------ Please add a __STATIC__ magic constant so that a static method can know the name of the class that it was called on. In other words: class A { static function bla() { print __STATIC__; } } class B extends A {} print B::bla() . "\n"; // I want this to print "B". See also: http://www.php.net/manual/en/language.constants.predefined.php#84050 Test script: --------------- // This is how it is currently done: php -r 'class A { static function bla() { print get_called_class(); }} class B extends A {} print B::bla() . "\n";' B // This would be more consistent and convenient: php -r 'class A { static function bla() { print __STATIC__; }} class B extends A {} print B::bla() . "\n";' B ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60202&edit=1

« previous php.bugs (#164819) next »