downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/language.constants.predefined.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/language.constants.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'language.constants.predefined.php',
   
1 => 'Magic constants',
  ),
 
'up' =>
  array (
   
0 => 'language.constants.php',
   
1 => 'Constants',
  ),
 
'prev' =>
  array (
   
0 => 'language.constants.syntax.php',
   
1 => 'Syntax',
  ),
 
'next' =>
  array (
   
0 => 'language.expressions.php',
   
1 => 'Expressions',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="language.constants.predefined" class="sect1">
   <h2 class="title">Magic constants</h2>

   <p class="simpara">
    PHP provides a large number of <a href="reserved.constants.php" class="link">predefined constants</a> to any script
    which it runs. Many of these constants, however, are created by
    various extensions, and will only be present when those extensions
    are available, either via dynamic loading or because they have
    been compiled in.
   </p>
  
   <p class="para">
    There are seven magical constants that change depending on
    where they are used.  For example, the value of
    <b><tt class="constant">__LINE__</tt></b> depends on the line that it&#039;s
    used on in your script. These special constants are
    case-insensitive and are as follows:
   </p>
   <p class="para">
    </p><table class="doctable table">
     <caption><b>A few &quot;magical&quot; PHP constants</b></caption>
    
      <thead valign="middle">
       <tr valign="middle">
        <th>Name</th>
        <th>Description</th>
       </tr>

      </thead>

      <tbody valign="middle" class="tbody">
       <tr valign="middle">
        <td align="left"><b><tt class="constant">__LINE__</tt></b></td>
        <td align="left">
         The current line number of the file.
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__FILE__</tt></b></td>
        <td align="left">
         The full path and filename of the file.  If used inside an include,
         the name of the included file is returned.
         Since PHP 4.0.2, <b><tt class="constant">__FILE__</tt></b> always contains an
         absolute path with symlinks resolved whereas in older versions it contained relative path
         under some circumstances.
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__DIR__</tt></b></td>
        <td align="left">
         The directory of the file.  If used inside an include,
         the directory of the included file is returned. This is equivalent
         to <i>dirname(__FILE__)</i>. This directory name
         does not have a trailing slash unless it is the root directory.
         (Added in PHP 5.3.0.)
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__FUNCTION__</tt></b></td>
        <td align="left">
         The function name. (Added in PHP 4.3.0)  As of PHP 5 this constant
         returns the function name as it was declared (case-sensitive).  In
         PHP 4 its value is always lowercased.
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__CLASS__</tt></b></td>
        <td align="left">
         The class name. (Added in PHP 4.3.0)  As of PHP 5 this constant
         returns the class name as it was declared (case-sensitive).  In PHP
         4 its value is always lowercased.
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__METHOD__</tt></b></td>
        <td align="left">
         The class method name. (Added in PHP 5.0.0)  The method name is
         returned as it was declared (case-sensitive).
        </td>
       </tr>

       <tr valign="middle">
        <td align="left"><b><tt class="constant">__NAMESPACE__</tt></b></td>
        <td align="left">
         The name of the current namespace (case-sensitive). This constant
         is defined in compile-time (Added in PHP 5.3.0).
        </td>
       </tr>

      </tbody>
    
    </table>
<p>
   </p>
   <p class="para">
    See also
    <a href="function.get-class.php" class="function">get_class()</a>,
    <a href="function.get-object-vars.php" class="function">get_object_vars()</a>,
    <a href="function.file-exists.php" class="function">file_exists()</a> and
    <a href="function.function-exists.php" class="function">function_exists()</a>.
   </p>
  </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites