为什么很少有人在 PHP 项目中使用 namespace ?
看了几个开源系统,都没有用到namespace。主要原因是什么呢?
回复内容:
1 虽然说了很多年,但东西出来的时间短。2 在PHP里,这些元素不是必须的,没有必须用的理由。
3 namespace这个东西如果到了必须用的层次,问题可能也不适合这么问了。这个展开来说就复杂了,所以答案以前两条为准,这条算是买二赠一的鸡肋。
现在namespace已经被广泛使用了,github上面许多开源的软件也都已经使用namespace,一些NB的开源框架使用namespace,如Symfony,larvael等,使用namespace对autoloader及class命名冲突都能够方便的管理 php的可贵在于足够灵活,目前PHP的命名空间还不够灵活。 1、公司的项目都是基于低版本开发转到高版本难免会出BUG(成本)
2、开源应用则是考虑兼容更多的虚拟主机(市场)
3、最主要的原因是在项目中没有必须使用的必要(优势)
总结一下就是成本高,市场支持少,没有明显优势 主要是 PHP 5.3 还尚未普及开来。不过我已经在实际的项目中应用了。 PHP 5.3 以上才支持 namespace
别说是命名空间,就是面向对象也未见得一定会被项目采用,对于一些小项目来说,够不上一定要用这些东东。
说到开源系统,多数会考虑向下兼容,比如很多虚拟主机都是 php 5.2 的
兼容性太坑爹了!
有无namespace,无法很好的兼容!
有namespace的类库无法调用无namespace的类库! 慢慢的都会普及了,运用起来还是很方便的! 我还要补充一下,其实namespace出来得太晚了,但凡大一点的框架已经遇到需要namespace解决的问题,所以就使用了更复杂的类名,导致namespace的使用迫切性不是非常强。另外php的项目普遍开发规模不足,咱们国内的php开发环境也较少关注技术发展。
当然了,技术必然会进步的,像namespace这样其他编程领域已经广泛接受的概念在设计上没有失败的可能,普及应用只是时间问题。 5.3才开始支持的,5.3发布了多少时间?有多少项目是5.3之后才开始做的?而且新的特性一定需要大家熟悉才会被用的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
