No programmer can complete a function or module in one go and flawlessly without debugging. Debugging actually involves many situations.
Violent debugging
This method is simple and crude. Most PHP programmers will use it. That is browser debugging. When editing After writing the code in the browser, open the universal browser and enter the address to start debugging the code.
Breakpoint debugging (Recommended learning: PHP programming from entry to proficiency)
To be honest, if you just look at this method Outputting results is completely unnecessary. It seems like a high-level waste of time but is actually a waste of time. 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, saving time and effort. Even the most powerful programmers have moments of confusion, right?
Command debugging
If you download a code snippet from the official website or github and are eager to debug it but are not willing to put the code snippet into the project or open a new one Directory, you can use the php command to execute this code block
php -f filename.php
If the code fragment is short, you can use
php -r "code ..."
to execute and run the 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 execute and 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. Many programmers think that the task ends after the functional modules and components are developed, and then they can be 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
If you never do the last step If you haven't done it, you are only half a programmer. For testing, I recommend using PHPunit. Only by better understanding your own code can you be a qualified programmer.
The above is the detailed content of how to test php code. For more information, please follow other related articles on the PHP Chinese website!

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

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools
