Skip to content
On this page

PHP

Version

Running on Php v8.1.27

Supported languages

PHP

Testing framework

PHPUnit

Special reminders and implementation details

php
use PHPUnit\Framework\TestCase;

/**
* @testdox HelloWorld.php
*/
class HelloWorldTest extends TestCase {
  /**
  * @testdox Should display "Hello World!"
  */
  public function testHelloWorld() {
    $output = helloWorld();
    $this->assertEquals('Hello World!', $output);
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Included libraries

How to debug

Debugging PHP code is essential for every developer. One of the simplest yet effective ways to debug is by using echo or var_dump statements.

Steps to Debug Using Echo or Var_dump

  1. Identify the Problem Area: Locate the section of your code where you suspect the problem might be.

  2. Insert echo or var_dump Statements: Add echo or var_dump statements before and after the suspected problematic code to print out variable values and flow control.

  3. Check the Results Output of your tests

  4. Analyze the Output: Look at the values printed on the results console area to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.

Here’s an example of how to use echo or var_dump for debugging:

php
function calculate_sum($a, $b) {
    echo "calculate_sum called with arguments: $a, $b <br>"; // Log function call
    $sum = $a + $b;
    echo "Sum after addition: $sum <br>"; // Log sum calculation
    return $sum;
}

$result = calculate_sum(5, 10);
echo "Result of calculate_sum: $result"; // Log the result
1
2
3
4
5
6
7
8
9