Blogger Information
Blog 55
fans 0
comment 1
visits 42215
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
命名空间的使用(5-8)—2018年5月11日16点40分
旺小舞的博客
Original
566 people have browsed it

命名空间一:

namespace one
{
    class Demo{public $name='hyman';}
    const SITE='深圳';
    function add($a,$b){return $a+$b;}
}

命名空间二:

namespace two
{
    class Demo1{public $name='程序员';}
    const SITE='民治';
    function add($a,$b){return $a+$b;}
}

__NAMESPACE__ 函数可查看当前的属于空间

命名空间的引入可用use,例如在namespace one 中导入two空间中的Demo如下语法:

use two\Demo as Demo1;

从而实现减轻代码的功能,如需要在二个相同Demo下执行本Demo,需要在Demo前面加\即可



Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post