Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 8888

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Magic constants</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.constants.syntax.html">Syntax</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.expressions.html">Expressions</a></div>
 <div class="up"><a href="language.constants.html">Constants</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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.html" 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 eight magical constants that change depending on
    where they are used.  For example, the value of
    <strong><code>__LINE__</code></strong> 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">
    <table class="doctable table">
     <caption><strong>A few &quot;magical&quot; PHP constants</strong></caption>
     
      <thead>
       <tr>
        <th>Name</th>
        <th>Description</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr id="constant.line">
        <td><strong><code>__LINE__</code></strong></td>
        <td>
         The current line number of the file.
        </td>
       </tr>

       <tr id="constant.file">
        <td><strong><code>__FILE__</code></strong></td>
        <td>
         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, <strong><code>__FILE__</code></strong> always contains an
         absolute path with symlinks resolved whereas in older versions it contained relative path
         under some circumstances.
        </td>
       </tr>

       <tr id="constant.dir">
        <td><strong><code>__DIR__</code></strong></td>
        <td>
         The directory of the file.  If used inside an include,
         the directory of the included file is returned. This is equivalent
         to <em>dirname(__FILE__)</em>. This directory name
         does not have a trailing slash unless it is the root directory.
         (Added in PHP 5.3.0.)
        </td>
       </tr>

       <tr id="constant.function">
        <td><strong><code>__FUNCTION__</code></strong></td>
        <td>
         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 id="constant.class">
        <td><strong><code>__CLASS__</code></strong></td>
        <td>
         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.  The class name includes the namespace
         it was declared in (e.g. <em>Foo\Bar</em>).
         Note that as of PHP 5.4 __CLASS__ works also in traits. When used
         in a trait method, __CLASS__ is the name of the class the trait
         is used in.
        </td>
       </tr>

       <tr id="constant.trait">
        <td><strong><code>__TRAIT__</code></strong></td>
        <td>
         The trait name. (Added in PHP 5.4.0)  As of PHP 5.4 this constant 
         returns the trait as it was declared (case-sensitive).  The trait name includes the namespace
         it was declared in (e.g. <em>Foo\Bar</em>).
        </td>
       </tr>

       
       <tr id="constant.method">
        <td><strong><code>__METHOD__</code></strong></td>
        <td>
         The class method name. (Added in PHP 5.0.0)  The method name is
         returned as it was declared (case-sensitive).
        </td>
       </tr>

       <tr id="constant.namespace">
        <td><strong><code>__NAMESPACE__</code></strong></td>
        <td>
         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 class="para">
    See also 
     <span class="function"><a href="function.get-class.html" class="function">get_class()</a></span>,
     <span class="function"><a href="function.get-object-vars.html" class="function">get_object_vars()</a></span>,
     <span class="function"><a href="function.file-exists.html" class="function">file_exists()</a></span> and
     <span class="function"><a href="function.function-exists.html" class="function">function_exists()</a></span>.
   </p>
  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.constants.syntax.html">Syntax</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="language.expressions.html">Expressions</a></div>
 <div class="up"><a href="language.constants.html">Constants</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>