菜单

Detailed examples of magic constants in PHP

2017年11月22日 - PHPer

Detailed examples of magic constants in PHP

This paper introduces the magic constants in PHP programming, master and flexible application of these methods and constants, to improve the programming level of PHP, a great help. Friends need to learn under reference.

Magic constants:

Namespace ns1;

Class Test {

Function __construct () {

Var_dump (__LINE__);

Var_dump (__FILE__);

Var_dump (__DIR__);

Var_dump (__FUNCTION__);

Var_dump (__CLASS__);

Var_dump (__METHOD__);

Var_dump (__NAMESPACE__);

}

}

New Test ();

Operation result

Int 5

String’E:\wamp\www\a.php'(length=17)

String’E:\wamp\www'(length=11)

String’__construct'(length=11)

String’ns1\Test'(length=8)

String’ns1\Test:: __construct'(length=21)

String’ns1′(length=3)

发表评论

电子邮件地址不会被公开。