//1.php
class Person{
function __construct(){
echo 'I am one!';
}
}
//name.php
require_once './1.php';
new Person(); //输出 I am one!;
new \Person(); //输出 I am one!;
//name.php require_once './1.php'; new /Person(); // 代码报错:Parse error: syntax error, unexpected '/'
//1.php
namespace one;
class Person{
function __construct(){
echo 'I am one!';
}
}
//name.php
require_once './1.php';
new \one\Person(); //输出 I am one!;
new \Person(); //代码报错:Fatal error: Class 'Person' not found
//1.php
namespace one;
class Person{
function __construct(){
echo 'I am one!';
}
}
//name.php
namespace test;
require './1.php';
new \one\Person(); //输出 I am one!;
new Person(); //这里结果会是什么呢,猜猜看
Fatal error: Class 'test\Person' not found
new \Person();
Fatal error: Class 'Person' not found
//name.php
namespace test;
require './1.php';
class Person{
function __construct(){
echo 'I am test!';
}
}
new \one\Person(); //输出 I am one!;
new Person(); //这里结果会是什么,自己猜猜看
//name.php
namespace test;
namespace one;
class Person{
function __construct(){
echo 'I am one!';
}
}
class Person{
function __construct(){
echo 'I am test!';
}
}
//name.php
namespace test\person;
class Person{
function __construct(){
echo 'I am test!';
}
}new \test\person\Person(); //命名空间里person无法代表类名
//name.php namespace test; echo 'zhai14'; namespace zhai; require './1.php';
//name.php
namespace animal\dog;
class Life{
function __construct(){
echo 'dog life!';
}
}
namespace animal\cat;
class Life{
function __construct(){
echo 'cat life!';
}
}
new Life(); //按照代码执行顺序,这里默认animal\cat这个命名空间
new \animal\dog\Life(); //A
use animal\dog; //a
new dog\Life(); //B
use animal\dog as d; //b
new d\Life();
//name.php
namespace animal\dog;
class Life{
function __construct(){
echo 'dog life!';
}
}
namespace animal\cat;
class Life{
function __construct(){
echo 'cat life!';
}
}
use animal\dog\Life as dog;
new dog();
//name.php
namespace animal\dog;
class Life{
function __construct(){
echo 'dog life!';
}
}
class Dog{
function __construct(){
echo 'dog in dog!';
}
}
namespace animal\cat;
// class Dog{
// function __construct(){
// echo 'dog in cat!';
// }
// }
class Life{
function __construct(){
echo 'cat life!';
}
}
use animal\dog;
new dog\Dog();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有