parse_error
The parse_error attribute tells DocTest to expect a PHP parse error. The block passes if the code fails to parse (non-zero exit code from php -l).
Syntax
php
// This code has intentional syntax errors
echo 'HelloHow It Works
- The code is written to a temporary file as-is
- The file is executed with PHP
- A non-zero exit code (indicating a parse error) means the block passes
- If the code runs successfully, the block fails
When to Use
- Demonstrating what invalid PHP syntax looks like
- Teaching materials showing common mistakes
- Documentation that explains parser behavior
Examples
Missing semicolon
php
$x = 42
echo $x;Unclosed string
php
echo "Hello, World!;Invalid syntax
php
function 123invalid() {}Failure Condition
The block fails if the code executes successfully without a parse error:
markdown
```php parse_error
// This is valid PHP — the block will FAIL
echo 'Hello';
```