Blogger Information
Blog 42
fans 4
comment 0
visits 30621
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5.8 use 导入空间/别名 --34Day
小丑的博客
Original
992 people have browsed it

实例

<?php

namespace Teacher
{

    class Person
    {
        public $name = 'Teacher-Person';
        function __construct()
        {
            echo 'Teacher空间-Person类';
        }
    }

    function Person()
    {
        return 'Teacher空间-Person()函数';
    }

    function teach(){
        echo 'Teacher空间-teach()函数';
    }

}



namespace Teacher\Student
{

//    use Teacher1\Person as Person1;


    new \Teacher1\Person();


    echo '<hr>';

    class Person
    {
        function __construct()
        {
            echo 'Student空间-Person类';
        }
    }

    function Person()
    {
        return 'Student空间-Person()函数';
    }



}



namespace Teacher1
{

    class Person
    {
        public $name = 'Teacher-Person';
        function __construct()
        {
            echo 'Teacher11空间-Person类';
        }
    }

    function Person()
    {
        return 'Teacher1空间-Person()函数';
    }

    function teach(){
        echo 'Teacher1空间-teach()函数';
    }

}


namespace test
{

    use Teacher;

    new Teacher\Person(); //Teacher空间-Person类
    echo '<br>';
    echo (new Teacher\Person())->name; //Teacher空间-Person类Teacher-Person
    echo '<br>';
    echo Teacher\Person();  //Teacher空间-Person()函数

    echo '<hr>';
    use Teacher\Student;

    new Student\Person(); //Student空间-Person类
    echo '<br>';
    echo Student\Person();  //Student空间-Person()函数

}

运行实例 »

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


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