It has been a long time since I switched from C++ to PHP. I have always been a bit obsessed with code cleanliness. I use strict camel case naming for file names, interface names, class names, method names, etc.
But sometimes I hesitate whether to capitalize the first letter or to use underline to distinguish. Let’s briefly summarize and summarize today.
1. File name
File names use camel case naming method, that is, capitalize the first letters of all words, such as: UserLoginController.php
2. Class name
Class names also use camel case nomenclature, and the length should be controlled within five words. If the logic is well described, use an abbreviated form, such as: class Account , class RealNameVerify.
3. Class method name
The class method name uses camel case naming method, that is, the first word is all lowercase, and the first letter of the subsequent words is all capitalized, and the first letter is as descriptive as possible Operation type, such as: getUserInfo, updateGameConfig, bindPhone.
For private methods of the class, they should start with a single underscore, such as: _guestLogin
4. Class member variables and method variables
Although many people believe that class member variables start with m, it is my personal habit to define all variables in the form of lowercase letters and underlined links, such as: $game_repository, $table_config, $return_data.
By the way Let’s take a look at a better way to name variables:
1. Member variables start with m, such as: $mTable, $mUrl
2. Static variables start with s, such as: $sCount, $ sStatus
3. Global variables start with g, such as: $gConnectTime
5. Class constants, global constants
For constants, use all uppercase letters and connect words with underscores Method, such as: PAYMENT_METHOD_TTBANK.
Finally, there is no absolute best naming convention, only the naming convention that is most suitable for the team, in detail The naming rules also need to be changed according to the framework used, the specific project background, etc.
But a unified, clear, and simple naming rule is very useful for project development and maintenance.
The above is the detailed content of Naming rules that PHP programmers are accustomed to. For more information, please follow other related articles on the PHP Chinese website!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools
