Req #70986 [Com]: Constants in traits

From: Date: Sun, 29 Nov 2015 11:51:55 +0000
Subject: Req #70986 [Com]: Constants in traits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197494@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 Comment by: owlet at avtovokzaly dot ru 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: Is it possible to disable in this case classified the same name in different traits constants used in the same class? And leave the behavior the same as in a regular class with a redefined constant: Fatal error, with message "Cannot redefine class constant"? Previous Comments: ------------------------------------------------------------------------ [2015-11-27 22:54:29] bwoebi@php.net 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… ------------------------------------------------------------------------ [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 (#197494) next »