search
HomeBackend DevelopmentPHP Tutorial如若PHP是用英式英语编写的

如果PHP是用英式英语编写的
PHP之父Rasmus Lerdorf在创造出PHP时,他并没有用格陵兰语或者丹麦语编写(尽管他有格陵兰和丹麦血统),这是非常明智的。虽然对他来说用英语编写,并没有用自己母语编写来得容易。由于他以前在加拿大待过,所以他选择了本地方言。不是法语,也不是不合纯正英语标准的方言,我们通常称其为“美式英语”。

从那以后,英国的PHP开发人员就对这件事情格外不满。Rasmus在想什么?更重要的是,我们要如何改变这个既成的事实?我们开发人员如何保证即使在数字时代,大英帝国的优良传统也能继续发扬光大?

一记耳光

?$variable_name   ? 最有必要更改就是要删除一些深受美国人喜欢的符号,并用一些更加精炼的符号代替,让PHP变得更加优雅。

??variable_name  开始吧

? 今天的英国程序员中,有多少人一开始接触到的就是“Hello World”这个典型的美国式程序,虽然简单但老套粗俗令人反感?一份更加冠冕正式的介绍将会促进大部分年轻的英国天才使用这种语言,从而为更广阔的用户群提供更加文雅的气氛。

? 缩写词

没有东西比没必要的缩写词更加让英国人痛恨的。“缩写词”在伦敦的街道上闻所未闻,正如土生土长的英国文法家不肯自降身份去发送“c u soon traffic kthxbye”等各种信息,宁愿使用一些看起来更加文雅的词句代替:“亲爱的先生或女士。只要时间允许,我希望在一个小时之内,尽快到达。我向各位保证,你们的马匹会得到妥善安置。敬上。”(输入较慢,是的,但是不至于仓促)。

从另一方面来说,PHP里面包含很多毫无必要的缩写字和缩写字首字母。

?str_replace()  ?is_int()  ?var_dump()  ?preg_match()  ?json_encode()  ?mysql_connect() 应该改成下面这样:

?string_replace()  ?is_integer()  ?variable_dump()  ?perl_regular_expression_match()  ?javascript_object_notation_encode()  ?my_structured_query_language_connect() 校正:我已经更正了“preg_match”的扩充——感谢指出来的朋友。

口才

?if ($condition) {  ?    // Code here  ?} else {  ?    // Code here  ?} 莎士比亚可不愿意看到他的母语被扭曲成这个怪物。简练在适当的场合很受欢迎——在一些偏僻的地方未必如此——但不是这里。“if … else”模块是PHP之中用得最多的条件代码,所以它在使用时必须是尽可能的安全无害。有很多选择可以取代,但是这个条件语句也许是最稳健的。

?perchance (?condition) {  ?    // Code here  ?} otherwise {  ?    // Code here  ?} 上述模块同样适用于美国化的,只能说是笨重的,让人厌恶的switch … case概念,

?switch ($variable) {  ?    case $option1:  ?        //Code here  ?        break;  ?    case $option2:  ?        //Code here  ?        break;  ?    default:  ?        //Code here  ?        break;  ?} 像”switch”, “break” and “default”这样的关键字对读者来说很有难度并且缺乏联系。这种美式用法真是需要改进。(使用美式用法的人有一些有趣的想法,期望用i_might_be_partial_to()这样的语句来代替include()来显示他们天才的编程天赋):

?what_about (?variable) {  ?    perhaps ?possibility:  ?        //Code here  ?        splendid;  ?    perhaps ?other_possibility:  ?        //Code here  ?        splendid;  ?    on_the_off_chance:  ?        //Code here  ?        splendid;  ?} 拼写

?imagecolorallocate()  ?serialize()  ?newt_centered_window()  ?connection_status() 在这点上,单词让我吃过不少亏。自重的绅士期待该如何看得懂这些“单词”。它削弱了任何人接受编程语言中单词的曲解含义的信念。这些“单词”和众多相似的错误,应该立即恢复到适当的形式。

?imagecolourallocate()  ?serialise()  ?newt_centred_window()  ?connexion_status() 习惯

?try {  ?    // Code here  ?} catch (Exception $e) {  ?    // Handle exception  ?    die('Message');  ?} try … catch语句块是PHP缺乏特点的一个很好证明。新的PHP过于直接地允许使用该模块,缺乏应有的限制。另外,单词“die”很让人丧气。这个新模块,尽管更加冗长,但更为文雅和乐观。

?would_you_mind {  ?    // Code here  ?} actually_i_do_mind (Exception ?e) {  ?    // Politely move on  ?    cheerio('Message');  ?} 类

在英国人的心里,没有什么东西跟类的概念一样重要和根深蒂固,而且,PHP当中的这一部分很少变动,除非是这里做出的重要更改。

?class Republic {  ?    public $a;  ?    private $b;  ?    protected $c;  ?}  ?$example = new Republic; 首先,流行的系统中并没有类层次存在的余地,这是无法接受的。所以我们首先应该赋予类的特定等级——上层,中层,工作层(upper, middle, working )——如果没有更高等级指令类的明确许可,类就无法使用一个更高级的类的方法(当然,即使它后来已经访问了更高级的类,但它并非更高级指令的正式成员,无法授予自身访问其他低级别指令类的更高级指令)。“public”和“private”,在英国人的类系统中是同义词(例如,学校制度命名),所以这些必须进行调整,“protected”的属性可见性也一样。单词“new”,虽然可行,但在类问题上需要有一个更加恰当的词来代替。

?upper_class Empire {  ?    state ?a;  ?    private ?b;  ?    hereditary ?c;  ?}  ??example = nouveau Empire; 日不落…

希望这些少数简单的变动能够提升PHP在众多编程语言之中的声誉和地位。它不再是蹩脚美国人的远亲。相反,它能重新回到作为脚本语言之王的英国人的怀抱中。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)