Blogger Information
Blog 46
fans 3
comment 1
visits 33305
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
508命名空间
吃不起土的少年的博客
Original
672 people have browsed it

实例

<?php
/**
 * Created by PhpStorm.
 * User: 金超
 * Date: 2018/5/9
 * Time: 13:37
 */
//创建第一个命名空间
namespace resource;
class method
{
 private $name='';
 private $method='';
 public function __construct($name='jack',$method='bus')
 {
     $this->name=$name;
     $this->method=$method;
 }
 public function goHome($name='jack',$method='bus')
 {
     return $this->name=$name.'今天通过'.$this->method=$method.'回家';

 }
}


namespace resource\count;
//创建第二个命名空间
//引用第一个命名空间中的类:method
use resource\method;

$num1=new method();
$num2=new method();

echo $num1->goHome();
echo'<hr style="color: blueviolet">';
echo$num2->goHome('Rose','ride on a bicycle');

运行实例 »

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

QQ截图20180509141423.png

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