PHP __DIR__, __FILE__, __FUNCTION__, __CLASS__, __METHOD__, __LINE__, __NAMESPACE__ - Comment Page: 1

PHP has large number of predefined constants. This HOWTO will present the seven most important, most practical and most useful PHP Magic Constants. __FILE__ - The full path and filename of the file. __DIR__ - The directory of the file. __FUNCTION__ - The function name. __CLASS__ - The class name. __METHOD__ - The class method name. __LINE__ - The current line number of the file. __NAMESPACE__ - The name of the current namespace This is example PHP script with comments, which demonstrate howto use all previously mentioned PHP Magic Constants. [inttf_post_ad1] <?php // Set namespace (works only with PHP 5.3) namespace TestProject; // This...

8 comments on “PHP __DIR__, __FILE__, __FUNCTION__, __CLASS__, __METHOD__, __LINE__, __NAMESPACE__ - Comment Page: 1

    1. […] Message Magic and Skype VS Twitter Broadcasting Holiday Joy | Message Magic ProTwitter Bot: Magic 8 Ball « Matt's BlogThe Magic of Twitter | bitcolumnstech news that mattersTwitter Business Magic PLR « Web 2.0 « JEDsWEBHowto Use PHP Magic Constants: __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __LINE__, __N… […]

    2. You’ve got great insights about PHP, keep up the good work!

    3. this awesome tips and shorthand coding for php developers

    4. Just __DIR__ not work… u need define dirname(__DIR__)

      Example is correct:
      echo dirname(__FILE__);

    5. This is really great

    6. Thanks For the detailed article.

    7. good tutorial, thx.


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version