批改状态:合格
老师批语:
php
<?php //1.php
class Person{
function __construct(){
echo 'I am one!<br/>';
}}点击 "运行实例" 按钮查看在线实例
<?php
namespace School\Parents;
class Man{
function __construct(){
echo 'Listen to teachers!<br/>';
}
}
namespace School\Teacher;
class Person{
function __construct(){
echo 'Please study!<br/>';
}
}
namespace School\Student;
require_once './1.php';
require_once './2.php';
class Person{
function __construct(){
echo 'I want to play!<br/>';
}
}
new Person(); //输出I want to play!
new \School\Teacher\Person(); //输出Please study!
//new Teacher\Person(); //报错
// ----------
use School\Teacher;
new Teacher\Person(); //输出Please study!
// ----------
use School\Teacher as Tc;
new Tc\Person(); //输出Please study!
// ----------
//use \School\Teacher\Person;
new \Person(); //报错
// ----------
// use \School\Parent\Man;
// new Man(); //报错点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号