Wu Yuxiong - natural born PHP development of learning: Magic constants

<? PHP 
echo 'This is the first "' __LINE__.. '" OK'; 
?>

<? PHP 
echo 'The file is located "' __FILE__.. '"'; 
?>

<? PHP 
echo 'The file is located "' __DIR__.. '"'; 
?>

<? PHP 
function Test () { 
    echo 'function named:' __FUNCTION__;. 
} 
Test (); 
?>

? < PHP 
class Test { 
    function _print () { 
        echo 'class named:'.. __CLASS__ "<br>"; 
        echo 'function named:'. __FUNCTION__; 
    } 
} 
$ T = new new Test (); 
$ T- > _print (); 
?>

<?php
class Base {
    public function sayHello() {
        echo 'Hello ';
    }
}
 
trait SayWorld {
    public function sayHello() {
        parent::sayHello();
        echo 'World!';
    }
}
 
class MyHelloWorld extends Base {
    use SayWorld;
}
 
$o = new MyHelloWorld();
$o->sayHello();
?>

<? PHP 
function Test () { 
    echo 'function named:' __METHOD__;. 
} 
Test (); 
?>

<? PHP 
namespace MyProject; 
 
echo 'namespace: "', __NAMESPACE__, '" '; // output "MyProject" 
?>

 

Guess you like

Origin www.cnblogs.com/tszr/p/10947633.html