3/20/15

PHP Magic Constant



There are a number of predefined constants available to your scripts.
We will use these constants as we need them; there’s a sample:

PHP: Magic Constant

PHP Magic Constant
__LINE__The current line number of the file.
__FILE__The full path and filename of the file.
__FUNCTION__The function name
__CLASS__The class name
__METHOD__The class method name
PHP_VERSIONThe PHP version
PHP_INT_MAXThe PHP integer value limit

__LINE__

eg
<?php
   echo "The Line number : ". __LINE__;
?>
 Output : The Line number : 2

__FILE__

eg
<?php
echo  "Your file name :". __FILE__;

?>
 Output : Your file name : C:\xampplite\htdocs\magic_constant\file.php

__FUNCTION__

__CLASS__

__METHOD__

eg
<?php
class demo
{
      function test()
      {
            echo "Function of demo class : ". __FUNCTION__ ."<br/>";
      }
      function testme()
      {
                echo "Method of demo class : ". __METHOD__ ."<br/>";
    echo "Class : ". __CLASS__;
    
      }
}
$object=new demo();
$object->test();
$object->testme();
?>
 Output:
Function of demo class : test
Method of demo class : demo::testme
Class : demo

PHP_VERSION

eg
<?php
  echo "Current PHP Version you are using  : ".PHP_VERSION;
?>
 Output : Current PHP Version you are using : 5.3.1

PHP_INT_MAX

eg
<?php
  echo "Integer Maximum Value : ".PHP_INT_MAX;
?>
 Output : Integer Maximum Value : 2147483647

0 comments:

Post a Comment

FIND US ON FACEBOOK

FIND US ON Twitter