Blogger Information
Blog 61
fans 0
comment 0
visits 54029
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
命名空间练习1
笑颜常开的博客
Original
932 people have browsed it

<?php
/**
* Created by PhpStorm.
* User: 廖广
* Date: 2019/4/4
* Time: 10:55
*/
//用大括号在一个PHP文档中声明多个命名空间


/**
* Created by PhpStorm.
* User: 廖广
* Date: 2019/4/3
* Time: 22:52
*/
//定义命名空间one
namespace  one{
   //在命名空间中定义三个全局成员
   class Pig{public static $name='peter';}
   function hello() {return 'Hello 朱老师';}
   const SITE='php.cn';
//访问成员
   echo Pig::class.'<br>';
   echo hello().'<br>';
   echo SITE.'<hr>';
//echo Pig::$name.'<br>';
}


//在一个php文档中允许创建多个命名空间
namespace  two{
   //在命名空间中定义三个全局成员
   class Pig{public static $name='peter';}
   function hello() {return 'Hello 猪哥';}
   const SITE='php中文网';
//访问成员
//如果在two空间访问one空间,怎么办?
   echo Pig::class.'<br>';
   echo hello().'<br>';
   echo SITE.'<hr>';
//全局空间
}

//大括号可以声明一个全局空间
namespace {
   class Pig{public static $name='peter';}
   function hello() {return 'Hello 灭绝师太';}
   const SITE='学习交流分享的平台';
}

namespace three{
//    调用全局成员
echo \Pig::class.'<br>';
echo \hello().'<br>';
echo \SITE;
}

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