note 70976 added to language.oop5.constants
| From: | lucas dot s at ono dot com | Date: | Tue, 07 Nov 2006 02:09:33 +0000 |
| Subject: | note 70976 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119450@lists.php.net to get a copy of this message | ||
In the same way "define()" can be used to create a GLOBAL constant that can be assigned as
the value of a CLASS constant (like anonymous (31-May-2006 10:03) noted a few posts back), MAGIC
constants (__LINE__, __FILE__, etc.) can also be assigned to a CLASS constant :-) Note that an
instance of ReflectionClass can be used to obtain the exact same info that magic constants can offer
you...
<?php
class MyClass
{
const FILE_I_AM_IN = __FILE__;
}
echo MyClass::FILE_I_AM_IN;
?>
This outputs the file the class definition is located in, as expected.
Notes on the other magic constants:
__LINE__ = does output the correct line but... is of course completely useless...
__FUNCTION__ = does not output anything.
__METHOD__ = outputs the class name!
----
Server IP: 66.163.161.117
Probable Submitter: 81.202.169.167
----
Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php
Edit -- https://master.php.net/note/edit/70976
Del: integrated -- https://master.php.net/note/delete/70976/integrated
Del: useless -- https://master.php.net/note/delete/70976/useless
Del: bad code -- https://master.php.net/note/delete/70976/bad+code
Del: spam -- https://master.php.net/note/delete/70976/spam
Del: non-english -- https://master.php.net/note/delete/70976/non-english
Del: in docs -- https://master.php.net/note/delete/70976/in+docs
Del: other reasons-- https://master.php.net/note/delete/70976
Reject -- https://master.php.net/note/reject/70976
Search -- https://master.php.net/manage/user-notes.php