What are the naming rules for method names in php

王林
Release: 2023-03-12 21:04:01
Original
2267 people have browsed it

Naming rules for method names in php: The first letter of the first word of the method name should be lowercase, and the first letter of subsequent words should be capitalized. The first character of the parameter name in the method should be lowercase, and all subsequent characters should have the first character uppercase according to the class naming rules.

What are the naming rules for method names in php

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

The function of a method in PHP is to perform an action and achieve a goal, so the name should explain what the method does.

Generally, the prefixes of method names have the first rules, such as is (judgment), get (get), set (set), etc.

Method naming rules:

The first letter of the first word in the method name is lowercase, and the first letter of subsequent words is capitalized.

For example:

class StartStudy{ //设置类 $mLessonOne = ""; //设置类属性 $mLessonTwo = ""; //设置类属性 function getLessonOne(){ //定义方法,得到属性mLessonOne的值 ... } }
Copy after login

Naming rules for parameters in methods:

Use lowercase letters for the first character. All characters after the first character are capitalized according to the class naming convention.

For example:

class EchoAnyWord{ function echoWord($firstWord,$secondWord){ ... } }
Copy after login

Recommended learning:php training

The above is the detailed content of What are the naming rules for method names in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!