Php import constants from another file
I have a small piece of code that was written in previous version of PHP (not 5.3) and I find it odd for the interpreter to catch a cross use of a constant as a notice message then finally cough up a fatal error when the constant is defined in a file that is different from the one the notice is being reported. That is, for example, I define my constant in file A which is initialized when the program starts
and in file B.php
File B is reported with notice message and a fatal error. The fatal error can be roughly described as
in which "...." stands for a long line of included paths that may or maynot be related to the current file B at all. I am grateful for any help or advice you offer. Is this caused by my use of new PHP version while my code was written in old one ? How can I fix these messages without reinstalling the PHP ? Edit: The only reason I would not want to reinstalling the PHP is that because I don't want to always change the PHP whenever I have to work with a new project. Now it may be old, what if later I need to use the latest version, re-downloading the new one and deleting the old one psss? (PHP 5 >= 5.3.0, PHP 7, PHP 8) The ability to refer to an external fully qualified name with an alias, or importing, is an important feature of namespaces. This is similar to the ability of unix-based filesystems to create symbolic links to a file or to a directory. PHP can alias(/import) constants, functions, classes, interfaces, traits, enums and namespaces. Aliasing is accomplished with the Example #1 importing/aliasing with the use operator
Note that for namespaced names (fully qualified namespace names containing namespace separator, such as PHP additionally supports a convenience shortcut to place multiple use statements on the same line Example #2 importing/aliasing with the use operator, multiple use statements combined
Importing is performed at compile-time, and so does not affect dynamic class, function or constant names. Example #3 Importing and dynamic names
In addition, importing only affects unqualified and qualified names. Fully qualified names are absolute, and unaffected by imports. Example #4 Importing and fully qualified names
Scoping rules for importing The Example #5 Illegal importing rule
toGreenlandic()
Group |