|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-11-22 07:54 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 21:00:02 2025 UTC |
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');