The simplest way to replicate is through a web context, by doing:
Create a file.php
with the following contents: <?php
. No whitespace!
Make index.php
with the following contents:
<?php
header('Content-Type: text/plain');
require 'file.php';
echo 'test';
Now, witness the results.
Expected: test
Actual: <?phptest
I've stumbled upon this quite some times while developing, and it's quite annoying.
Environment:
Why such behavior, how come PHP doesn't parse this?
Quoting from the docs:
Note:
In PHP 5.2 and earlier, the parser does not allow the
<?php
opening tag to be the only thing in a file. This is allowed as of PHP 5.3 provided there are one or more whitespace characters after the opening tag.
my emphasis