Req #60355 [Opn->Nab]: namespace wide and specific constant

From: Date: Fri, 10 Aug 2012 18:53:12 +0000
Subject: Req #60355 [Opn->Nab]: namespace wide and specific constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-172572@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60355&edit=1 ID: 60355 Updated by: nikic@php.net Reported by: matty023 at gmail dot com Summary: namespace wide and specific constant -Status: Open +Status: Not a bug Type: Feature/Change Request Package: *General Issues PHP Version: Irrelevant Block user comment: N Private report: N New Comment: There is already a language construct to define constants in a namespace: namespace Bar; const FOO = 'bar'; Yes, const also works outside a class ;) define() is a function taking a constant name, so it (just like all other functions accepting constant/function/class names) needs a fully-qualified name. So if you want to define a namespace constant with define() (instead of const) you have to provide the full name: define('Bar\FOO', 'bar'); Previous Comments: ------------------------------------------------------------------------ [2011-11-22 07:54:45] matty023 at gmail dot com Description: ------------ It would be great if define() wasn't global throughout the whole app and contained inside the namespace to prevent collisions. It could also be feasible to create a new type of constant that is available throughout an entire namespace; define : Defines a named constant = Global constant throughout execution const  : Class Constants = It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don't use the $ symbol to declare or use them. ?? : namespace wide global nsdefine nsconst also accessible via \my\namespace\MYCONSTANT = It is possible to define constant values on a per-namespace basis remaining the same and unchangeable. Namespace Constants differ from normal variables in that you don't use the $ symbol to declare or use them. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60355&edit=1

« previous php.bugs (#172572) next »