Home Backend Development PHP Tutorial 如其PHP是用英式英语编写的

如其PHP是用英式英语编写的

Jun 13, 2016 am 10:40 AM
code here nbsp php variable

如果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过于直接地允许使用该模块http://www.gw005.com ,缺乏应有的限制。另外,单词“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在众多编程语言之中的声誉和地位。它不再是蹩脚美国人的远亲。相反,它能重新回到作为脚本语言之王的英国人的怀抱中。

注:原文作者Dave是一位英国开发人员。

Statement of this Website
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

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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles