Home  >  Article  >  Backend Development  >  How to test your own code in php

How to test your own code in php

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-09-27 13:10:173373browse

How to test your own code in php

phpHow to test your own code? Here are several methods to introduce to you:

Violent debugging

This method is simple and crude, and is generally used by PHP programmers, that is, browser debugging. After writing the code in the editor, open the universal browser and enter the address to start debugging the code.

Breakpoint debugging

To be honest, if this method is just to look at the output results, it is completely unnecessary. It seems to be a waste of time and experience, but it is generally I will run debug after the code block is written to check whether the process and results are within my expectations or if I encounter some logical problems that I cannot detect. It is more reliable to choose breakpoint debugging, which saves time and effort. Even the most powerful programmers have moments of confusion, right?

Related recommendations: "php tutorial"

Command debugging

If you download a piece of code from the official website or github Snippet, if you are eager to debug but are not willing to put the code snippet into the project or open a new directory, you can use the php command to execute this code block:

php -f filename.php

If the code snippet is shorter, you can use:

php -r "code ..."

Execute and run PHP code

Fragment debugging

When you suddenly think of a method or algorithm and are eager to verify it, but are unwilling to open the editor Or execute the command line that comes with php. You can choose to use the psysh tool to verify your ideas. The installation of this tool is very simple.

Psy Shell v0.8.17 (PHP 7.1.14 — cli) by Justin Hileman
New version is available (current: v0.8.17, latest: v0.9.6)
>>> date('Y-m-d H:i:s',time())
=> "2018-08-09 14:18:10"
>>>

Download address: https://psysh.org/

Testing and debugging

This is a serious debugging method that many programmers It is considered that the task ends after the development of functional modules and components, and then is handed over to testers for testing. In fact, this is not the case. Some hidden bugs or fatal errors, logic errors, and system errors (such as starting useless threads, unused variables, methods, classes, etc.) cannot be tested. In fact, as a programmer, the process of developing functions is like this.

Understand the requirements -> Decompose the requirements -> Organize the logic -> Design the code -> Type the code -> Debugging -> Test

The above is the detailed content of How to test your own code 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