Bug #73495 [Opn->Nab]: Class name As Const

From: Date: Fri, 11 Nov 2016 10:28:33 +0000
Subject: Bug #73495 [Opn->Nab]: Class name As Const
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205302@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73495&edit=1 ID: 73495 Updated by: cmb@php.net Reported by: takeo dot tanha at live dot com Summary: Class name As Const -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related PHP Version: 7.0.13 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This syntax is not suppossed to work. Check the chapter on passing callables[1] in the PHP manual for working alternatives; for instance, you could do it like <https://3v4l.org/dt2VO>. Also consider to use bar::class instead of hardcoding the class name as string (see <https://3v4l.org/4jB0Z>). [1] <http://php.net/manual/en/language.types.callable.php> Previous Comments: ------------------------------------------------------------------------ [2016-11-11 08:38:47] takeo dot tanha at live dot com Description: ------------ in example we have a class (bar) that have a static function that do somthing. when in other class (foo) we Define bar class name as Const and when we want use it to run static function we have an error : Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in index.php on line 7 Test script: --------------- class foo { const MY_CONST = "bar"; public function __construct() { self::MY_CONST::message(); } } class bar { public static function message() { echo "hello"; } } new foo(); Expected result: ---------------- Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in index.php on line 7 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73495&edit=1

« previous php.bugs (#205302) next »