Blogger Information
Blog 56
fans 3
comment 1
visits 50692
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
namespace实例——2018年5月9日
沈斌的博客
Original
723 people have browsed it

php namespace 解决第三发类,函数,常量名字的冲突

Cat.php

实例

<?php
/**
 *
 */
namespace Project\Cat;
class Cat
{
    public $name='cat';
}

const CAT='cat animal';

function jump(){
    return 'cat jump';
}

运行实例 »

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

Dog.php


实例

<?php
/**
 *
 */

namespace Project\Dog;

//命名空间Cat
use Project\Cat as Cat;
//导入Cat.php 文件
require 'Cat.php';

class Dog
{
    public $name='Dog';
}

const CAT='Dog animal';

function jump(){
    return 'dog jump';
}


echo (new Cat\Cat())->name,'<br>';
echo Cat\jump(),'<br>';
echo Cat\CAT;

运行实例 »

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

运行结果

cat
cat jump
cat animal

Correction status:Uncorrected

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