Appearance
The result comment assertion uses // => at the end of a line to verify the value of the expression on that line.
// =>
$x = 42; // => 42 $flag = true; // => true $nothing = null; // => NULL
var_export()
var_export
Since var_export is used, the expected values follow PHP's var_export format:
42
3.14
true
false
null
NULL
'hello'
[1, 2]
array (0 => 1, 1 => 2,)
array (...)
$a = 10 + 5; // => 15 $b = 10 * 3; // => 30
$upper = strtoupper('hello'); // => 'HELLO' $len = strlen('test'); // => 4
$empty = empty([]); // => true $isset = isset($undefined); // => false
Regular PHP comments (without =>) are left untouched. Only the // => pattern triggers an assertion:
=>
```php $x = 42; // This is just a comment, not an assertion $y = 42; // => 42 <-- This IS an assertion ```
Result Comment Assertion
The result comment assertion uses
// =>at the end of a line to verify the value of the expression on that line.Syntax
How It Works
// =>is evaluatedvar_export()var_exportoutput is compared against the expected value on the rightSince
var_exportis used, the expected values follow PHP'svar_exportformat:4242423.143.143.14truetruetruefalsefalsefalsenullNULLNULL'hello''hello''hello'[1, 2]array (0 => 1, 1 => 2,)array (...)When to Use
Examples
Arithmetic
String functions
Boolean checks
Regular Comments
Regular PHP comments (without
=>) are left untouched. Only the// =>pattern triggers an assertion: