📜 ⬆️ ⬇️

5 tricks that make life easier for the PHP kettle

Since I am not a programmer, but sometimes I torture WordPress a little , it turns out that I am programming. Of course, confused. Still it is necessary to read another's code and to understand it. And to remember what I had written there myself. Gradually, studying someone else's code and rubbing stuffed bumps, came to some list of techniques that facilitate the life of the PHP-teapot.

1. Before each function, write what this function does. Also write comments before all sorts of complex pieces and regular expressions. Well, at the beginning of the file to write, what kind of file, what is it for, what is contained in it. With the version and date of change.

2. Name the functions so that it is clear what it does. Better with the use of verbs. For example, if a function kills a squirrel, call it kill_the_squirrel (), and if it saves the world, then save_the_world (). Well, variables can be called nouns, only so that it is also clear what it is about. For example, the counter can be called $ counter.
')
3. After each command, put a semicolon. Even if in this case it can be omitted. And new teams to write with a new line. Then, when adding commands, there is less chance that you will forget to put this very semicolon.

4. If a variable is compared with a value, it is better to first write the value, then the variable. For example, if (100 == $ counter) ... and so on. I often instead of two characters equals one. If you write the value first (a constant, as smart people told me), then PHP will give the error parse error with the line number. This will help you quickly find the joint.

5. Use indents and placement of curly braces. Put the opening bracket after the name of the function or operator, such as if, and the closing bracket - in the position corresponding to the first letter of the operator. It is easier to find where things start and end.

Source: https://habr.com/ru/post/12093/


All Articles