Blogger Information
Blog 44
fans 0
comment 1
visits 30959
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5月8日作业——命名空间的使用
时光记忆的博客
Original
731 people have browsed it

定义第一个类脚本:demo1.php

实例

namespace 0508/Demo1;
class Demo1{
   public $name = 'demo1';
   public function tell($name){
      return '我是'.$name.'的命名空间';
   }
   
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

定义第一个类脚本:demo2.php

实例

namespace 0508/Demo2;
use 0508/Demo1;

class Demo2{
   public function tell(){
      return '我在调用Demo1命名空间的方法'.'<br>.Demo1::tell();
   }
   
}

$demo = new Demo2;
echo $demo->tell();

运行实例 »

点击 "运行实例" 按钮查看在线实例

输出:

我在调用Demo1命名空间的方法

我是Demo1的命名空间

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