略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 定义子命名空间

2024-04-15

定义子命名空间

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

与目录和文件的关系很象,PHP 命名空间也允许指定层次化的命名空间的名称。因此,命名空间的名字可以使用分层次的方式定义:

示例 #1 声明分层次的单个命名空间

<?php
namespace MyProject\Sub\Level;

const 
CONNECT_OK 1;
class 
Connection /* ... */ }
function 
connect() { /* ... */  }

?>
上面的例子创建了常量 MyProject\Sub\Level\CONNECT_OK,类 MyProject\Sub\Level\Connection 和函数 MyProject\Sub\Level\connect
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/language.namespaces.nested.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3