Ecco alcuni esempi di costanti “magiche” messe a disposizione da PHP!

 
< ?php
/**
* Script to demonstrate magic constants in php
*/

 
echo "\n" . "We are at line " . __LINE__;
echo "\n" . "The full path and filename of the file is " . __FILE__;
 
function myFunction(){
echo "\n" . "The function name is " . __FUNCTION__;
}
 
myFunction();
 
class myClass
{
public function __construct()
{
echo "\n" . "The class name is " . __CLASS__;
echo "\n" . "The method name is ". __METHOD__;
}
}
 
$object = new myClass();
echo "\n";
?>
Sample output of the script:
 
We are at line 6
The full path and filename of the file is /home/sudheer/workspace/php/cli/constant/magic.php
The function name is myFunction
The class name is myClass
The method name is myClass::__construct
 
?>
 

fonte: www.sastgroup.com