One of the most important new features in PHP5.3 is the introduction of namespaces. Before that, PHP developers had become eager to implement namespaces in PHP. When PHP applications start to become huge and more complex, namespaces are essential for resolving code conflicts.
One of the most important new features in PHP 5.3 is the introduction of namespaces. Before that, PHP developers had become eager to implement namespaces in PHP. When PHP applications start to become huge and more complex, namespaces are necessary to resolve code conflicts.
Recommendations for bitsCN-related articles: PHP namespace rule parsing and advanced functions
Critics: chaotic PHP
Languages such as C # and Java are designed and follow strict syntax standards. PHP is evolving. The earliest version was released in 1995, with version 3, a process-oriented language. PHP 4 contains the most basic object-oriented, while PHP 5 provides the appropriate standard OOP model, with the namespace included in PHP 5.3.
498) this. style. width = 498; "border =" 0 "/>
PHP critics declare that the language is messy. Function names are inconsistent (for example, strpos, str_split, and substr). object processing is useless, and some syntaxes are not as strange as other languages. However, PHP still keeps the most popular server-side development language. Its Talent mainly lies in the following strengths:
◆ Beginners can start with simple process-oriented programming.
◆ They do not need to touch the OOP technology and can still be seen here
Code compiled for PHP 3 10 years ago can still run under PHP 5.3. Some minor adjustments may be required, but a large amount of rewriting is rarely required. PHP code may not always cute, logical, or elegant, but it is always quick and easy to understand than other options for development.
PHP namespace implementation
Unlike C # and Java, PHP has to maintain the compatibility of code without namespaces. This has been implemented. you can choose to use or not use the namespace. However, if you are using PHP 5.3 or later, I recommend using namespaces, even if you only use the same name in the project.
Using namespace and use as namespace operators seems logical. Some developers may disagree, but it is not important to name them in this case. Finally, return to the question of backslash. Most critics are ugly, hard to read, and hard to input on Mac. Even so, I still think it is better than the two colons I have proposed. For example, the following static method call:
- // PHP 5.3 beta static method call
- Echo: App: Lib1: MyClass: WhoAmI ();
- // PHP 5.3 official static method call
- Echo \ App \ Lib1 \ MyClass: WhoAmI ();
The second line can be quickly entered, with fewer errors possible, easier to read, and easier to understand. If you see a backslash outside the string, you will know that there must be a namespace.
Of course, it would be better if PHP uses "." as a public method, static method, and namespace. This can be consistent with Java, C #, JavaScript, Python, and many other languages. Unfortunately, the history and downward compatibility of PHP make it hard to implement.
No language is perfect, and PHP is not even a member of the perfect language. In any case, the namespace has been well implemented, especially considering its possible limitations and problems.
The author analyzes the implementation of PHP namespaces to counter the voices of PHP opponents. do you know why PHP namespaces are like this? Is the PHP namespace really so messy? As a PHP developer, how do you think?
Author: Craig Buckler
Http://www.sitepoint.com/blogs/2009/08/13/are-php-namespaces-bad/