Home  >  Article  >  Backend Development  >  What are the naming rules for method names in php

What are the naming rules for method names in php

王林
王林Original
2021-09-23 14:22:072347browse

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的值
 
            ...
    }
}

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){
        ...
    }
}

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!

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