If PHP was written in British English_PHP Tutorial
Rasmus Lerdorf, the father of PHP, was very wise when he created PHP not in Greenlandic or Danish (although he has Greenlandic and Danish ancestry). Although writing in English is not as easy for him as writing in his native language. Since he had spent time in Canada before, he chose the local dialect. It’s not French, nor is it a dialect that doesn’t conform to the standard of pure English, which we usually call “American English.”
Since then, British PHP developers have been particularly dissatisfied with this matter. What was Rasmus thinking? More importantly, how do we change this fait accompli? How do we developers ensure that the fine traditions of the British Empire continue to flourish even in the digital age?
One note Slap
<ol class="dp-xml"><li class="alt"><span><span>$variable_name </span></span></li></ol>
The most necessary change is to delete some symbols that are loved by Americans and replace them with some more refined symbols to make PHP more elegant.
<ol class="dp-c"><li class="alt"><span><span>£variable_name </span></span></li></ol>
Let’s get started
<ol class="dp-xml"> <li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li> <li><span>echo 'Hello World!'; </span></li> <li class="alt"> <span class="tag">?></span><span> </span> </li> </ol>
How many of today’s British programmers were first exposed to the typical American “Hello World” program, simple but offensively old-fashioned and vulgar? A more formal introduction would promote the use of the language by most of the young British geniuses, thus providing a more urbane atmosphere to a wider user base.
<ol class="dp-xml"> <li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li> <li><span>announce 'Good morrow, fellow subjects of the Crown.'; </span></li> <li class="alt"> <span class="tag">?></span><span> </span> </li> </ol>
Acronyms
There is nothing the British hate more than unnecessary abbreviations. "Abbreviations" were unheard of on the streets of London, just as the native English grammarian refused to deign to send "c u soon traffic kthxbye" and other messages, preferring to use some more elegant-looking phrases instead: "Dear Sir or ma'am. I hope to arrive as soon as possible, within an hour. I assure you that your horses will be well accommodated." (Slower input, yes, but not in a hurry).
On the other hand, PHP contains a lot of unnecessary abbreviations and acronyms.
<ol class="dp-xml"> <li class="alt"><span><span>str_replace() </span></span></li> <li><span>is_int() </span></li> <li class="alt"><span>var_dump() </span></li> <li><span>preg_match() </span></li> <li class="alt"><span>json_encode() </span></li> <li><span>mysql_connect() </span></li> </ol>
should be changed to the following:
<ol class="dp-xml"> <li class="alt"><span><span>string_replace() </span></span></li> <li><span>is_integer() </span></li> <li class="alt"><span>variable_dump() </span></li> <li><span>perl_regular_expression_match() </span></li> <li class="alt"><span>javascript_object_notation_encode() </span></li> <li><span>my_structured_query_language_connect() </span></li> </ol>
Correction: I have corrected the expansion of "preg_match" - thanks to the friend who pointed it out.
Eloquence
<ol class="dp-c"> <li class="alt"><span><span class="keyword">if</span><span> (</span><span class="vars">$condition</span><span>) { </span></span></li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"> <span>} </span><span class="keyword">else</span><span> { </span> </li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"><span>} </span></li> </ol>
Shakespeare would not have liked to see his native language twisted into this monster. Simplicity is popular in the right circumstances - not necessarily in some remote places - but not here. The "if ... else" module is the most commonly used conditional code in PHP, so it must be as safe and harmless as possible when used. There are many alternatives, but this conditional statement is perhaps the most robust.
<ol class="dp-c"> <li class="alt"><span><span>perchance (£condition) { </span></span></li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"><span>} otherwise { </span></li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"><span>} </span></li> </ol>
The above modules are also suitable for Americanized, which can only be said to be bulky and disgusting switch... case concepts,
<ol class="dp-c"> <li class="alt"><span><span class="keyword">switch</span><span> (</span><span class="vars">$variable</span><span>) { </span></span></li> <li> <span> </span><span class="keyword">case</span><span> </span><span class="vars">$option1</span><span>: </span> </li> <li class="alt"> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li> <span> </span><span class="keyword">break</span><span>; </span> </li> <li class="alt"> <span> </span><span class="keyword">case</span><span> </span><span class="vars">$option2</span><span>: </span> </li> <li> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li class="alt"> <span> </span><span class="keyword">break</span><span>; </span> </li> <li> <span> </span><span class="keyword">default</span><span>: </span> </li> <li class="alt"> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li> <span> </span><span class="keyword">break</span><span>; </span> </li> <li class="alt"><span>} </span></li> </ol>
like "switch", "break" Keywords like ” and “default” are difficult for readers and lack connection. This American usage really needs improvement. (People who use American usage have some interesting ideas and hope to use statements like i_might_be_partial_to() instead of include() to show their programming genius):
<ol class="dp-c"> <li class="alt"><span><span>what_about (£variable) { </span></span></li> <li><span> perhaps £possibility: </span></li> <li class="alt"> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li><span> splendid; </span></li> <li class="alt"><span> perhaps £other_possibility: </span></li> <li> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li class="alt"><span> splendid; </span></li> <li><span> on_the_off_chance: </span></li> <li class="alt"> <span> </span><span class="comment">//Code here </span><span> </span> </li> <li><span> splendid; </span></li> <li class="alt"><span>} </span></li> </ol>
Spelling
<ol class="dp-c"> <li class="alt"><span><span>imagecolorallocate() </span></span></li> <li><span>serialize() </span></li> <li class="alt"><span>newt_centered_window() </span></li> <li><span>connection_status() </span></li> </ol>
At this point, words have made me suffer a lot. How can a self-respecting gentleman understand these "words"? It undermines anyone's belief in accepting the distorted meanings of words in programming languages. These "words," and numerous similar errors, should be immediately restored to their proper form.
<ol class="dp-c"> <li class="alt"><span><span>imagecolourallocate() </span></span></li> <li><span>serialise() </span></li> <li class="alt"><span>newt_centred_window() </span></li> <li><span>connexion_status() </span></li> </ol>
Habit
<ol class="dp-c"> <li class="alt"><span><span>try { </span></span></li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"> <span>} catch (Exception </span><span class="vars">$e</span><span>) { </span> </li> <li> <span> </span><span class="comment">// Handle exception </span><span> </span> </li> <li class="alt"> <span> </span><span class="keyword">die</span><span>(</span><span class="string">'Message'</span><span>); </span> </li> <li><span>} </span></li> </ol>
try … catch block is a good example of PHP’s lack of features. The new PHP allows the use of this module too directly and lacks the restrictions it should have. Also, the word "die" is very depressing. This new module, although more lengthy, is more elegant and upbeat.
<ol class="dp-c"> <li class="alt"><span><span>would_you_mind { </span></span></li> <li> <span> </span><span class="comment">// Code here </span><span> </span> </li> <li class="alt"><span>} actually_i_do_mind (Exception £e) { </span></li> <li> <span> </span><span class="comment">// Politely move on </span><span> </span> </li> <li class="alt"> <span> cheerio(</span><span class="string">'Message'</span><span>); </span> </li> <li><span>} </span></li> </ol>
Classes
In the hearts of British people, nothing is as important and deep-rooted as the concept of classes, and this part of PHP rarely changes , unless there are important changes made here.
<ol class="dp-c"> <li class="alt"><span><span class="keyword">class</span><span> Republic { </span></span></li> <li> <span> </span><span class="keyword">public</span><span> </span><span class="vars">$a</span><span>; </span> </li> <li class="alt"> <span> </span><span class="keyword">private</span><span> </span><span class="vars">$b</span><span>; </span> </li> <li> <span> </span><span class="keyword">protected</span><span> </span><span class="vars">$c</span><span>; </span> </li> <li class="alt"><span>} </span></li> <li> <span class="vars">$example</span><span> = </span><span class="keyword">new</span><span> Republic; </span> </li> </ol>
First of all, there is no room for class hierarchy in popular systems, which is unacceptable. So we should first give the class a specific level - upper, middle, working - so that the class cannot use the methods of a higher-level class without explicit permission from the higher-level directive class (of course , even if it has subsequently accessed a higher-level class, it is not a formal member of the higher-level directive and cannot grant itself access to higher-level directives of other lower-level directive classes). "public" and "private" are synonymous in the British class system (e.g., school system naming), so these must be adjusted, as is the property visibility of "protected". The word "new", while feasible, needs to be replaced by a more appropriate word in class problems.
<ol class="dp-c"> <li class="alt"><span><span>upper_class Empire { </span></span></li> <li><span> state £a; </span></li> <li class="alt"> <span> </span><span class="keyword">private</span><span> £b; </span> </li> <li><span> hereditary £c; </span></li> <li class="alt"><span>} </span></li> <li><span>£example = nouveau Empire; </span></li> </ol>
The sun never sets...
Hope these few simple changes can enhance PHP's reputation and status among many programming languages. It’s no longer a distant relative of crappy Americana. Instead, it falls back into the lap of the British as kings of scripting languages.
English original text:

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
