Piping PHP CLI output to less broken

Today I had an interesting problem.

When I ran:

 # php test.php | less

The ‘less’ program entered input mode and the up and down arrow (and j, k keys) weren’t working.

Eventually I figured out a solution:

 # php test.php < /dev/null | less

The PHP CLI seems to be interfering with the terminal and piping in /dev/null to PHP CLI stdin fixes the problem!