亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP development basic tutorial magic constants

Overview

PHP provides a large number of predefined constants to any script it runs.

However, many constants are defined by different extension libraries and will only appear when these extension libraries are loaded, or after dynamic loading, or have been included during compilation.

1. There are eight magic constants whose values ??change as their positions in the code change

For example, the value of __LINE__ It depends on which line it is in the script. These special constants are not case-sensitive

See the following table for details:

17.png

You can’t learn by just looking at it. Let’s see the output results from examples. Bar
Example: The code is as follows

<?php
//__LINE__  文件中當(dāng)前行號(hào)__________________________
echo '這是第 “ '  . __LINE__ . ' ” 行';
echo "<hr/>";
//__FILE__  文件的完整路徑和文件名__________________
echo '該文件位于 “ '  . __FILE__ . ' ” ';
echo "<hr/>";
//__DIR__  文件所在的目錄___________________________
echo '該文件位于 “ '  . __DIR__ . ' ” ';
echo "<hr/>";
//__LINE__  文件中當(dāng)前行號(hào)__________________________
echo '這是第 “ '  . __LINE__ . ' ” 行';
echo "<hr/>";
//__FUNCTION__  函數(shù)名稱____________________________
function test() {
    echo  '函數(shù)名為:' . __FUNCTION__ ;
}
test();
echo "<hr/>";
//__CLASS__  類的名稱_______________________________
class c {
    function _print() {
        echo '類名為:'  . __CLASS__ . "<br>";
        echo  '函數(shù)名為:' . __FUNCTION__ ;
    }
}
$t = new c();
$t->_print();
echo "<hr/>";
?>

Note: Please understand the following magic constants first, and there will be details in subsequent chapters

Note: Pay attention to the php version problem. Inappropriate versions will report errors


Continuing Learning
||
<?php //__LINE__ 文件中當(dāng)前行號(hào)__________________________ echo '這是第 “ ' . __LINE__ . ' ” 行'; echo "<hr/>"; //__FILE__ 文件的完整路徑和文件名__________________ echo '該文件位于 “ ' . __FILE__ . ' ” '; echo "<hr/>"; //__DIR__ 文件所在的目錄___________________________ echo '該文件位于 “ ' . __DIR__ . ' ” '; echo "<hr/>"; //__LINE__ 文件中當(dāng)前行號(hào)__________________________ echo '這是第 “ ' . __LINE__ . ' ” 行'; echo "<hr/>"; //__FUNCTION__ 函數(shù)名稱____________________________ function test() { echo '函數(shù)名為:' . __FUNCTION__ ; } test(); echo "<hr/>"; //__CLASS__ 類的名稱_______________________________ class c { function _print() { echo '類名為:' . __CLASS__ . "<br>"; echo '函數(shù)名為:' . __FUNCTION__ ; } } $t = new c(); $t->_print(); echo "<hr/>"; ?>
submitReset Code