Req #70986 [Opn]: Constants in traits

From: Date: Fri, 27 Nov 2015 22:54:32 +0000
Subject: Req #70986 [Opn]: Constants in traits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197472@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70986&edit=1 ID: 70986 Updated by: bwoebi@php.net Reported by: owlet at avtovokzaly dot ru Summary: Constants in traits Status: Open Type: Feature/Change Request Package: Class/Object related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: The issue is that we don't have collision resolution for constants in case we use two different traits defining a constant with the same name… In general, that's related to the general limitedness of traits being pure compiler copy&paste directly into a class and not just sharing scope… Previous Comments: ------------------------------------------------------------------------ [2015-11-27 14:37:35] owlet at avtovokzaly dot ru Description: ------------ Sometimes we need to define constants directly in trait. Now it is impossible and can be done throw namespace constants, for example, But this replacement very uncomfortable. Test script: --------------- trait A { const CONST_A = 'value of A::A'; } class B { use A; public static function getA() { return self::CONST_A; } } echo B::getA(); Expected result: ---------------- value of A::A Actual result: -------------- PHP Fatal error: Traits cannot have constants in php shell code on line 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70986&edit=1

« previous php.bugs (#197472) next »