


PHP design pattern one: namespace, automatic loading class, PSR-0 coding specification
Apr 09, 2018 pm 04:11 PM本篇文章介绍的内容是php设计模式一之命名空间、自动加载类、PSR-0编码规范 ,现在分享给大家,有需要的朋友可以参考一下
一、命名空间:解决在生产环境中多人协同开发时出现类名或函数名冲突的问题;
test1.php
1 2 3 4 5 6 |
|
test2.php
1 2 3 4 5 6 |
|
test.php
1 2 3 4 5 6 |
|
二、自动加载类:解决在项目中引入过多的依赖类文件问题;
demo1.php
1 2 3 4 5 6 7 |
|
demo2.php
1 2 3 4 5 6 7 |
|
demo.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
三、PSR-0编码规范
1)、必须使用命名空间并且与文件的绝对路径一致;
2)、类名首字母须大写且与文件名保持一致;
3)、除入口文件以外其他php文件必须只有一个类且没有可执行的代码;
四、基于PSR-0编码规范编写一套基础框架
1)、目录结构
1 2 3 4 5 6 7 |
|
Autoloader.php
1 2 3 4 5 6 7 8 9 10 |
|
App/Controller/Home/Index.php
1 2 3 4 5 6 7 8 9 10 11 |
|
index.php
1 2 3 4 5 6 7 8 |
|
The above is the detailed content of PHP design pattern one: namespace, automatic loading class, PSR-0 coding specification. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
