note 70976 deleted from language.oop5.constants by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Aug 2011 13:29:59 +0000 |
| Subject: | note 70976 deleted from language.oop5.constants by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182180@lists.php.net to get a copy of this message | ||
Note Submitter: lucas dot s at ono dot com
----
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!