If you are writing a command line tool in PHP and want to write to STDERR, here is the command:
file_put_contents('php://stderr', 'This text goes to STDERR');
The relevant documentation page is PHP input/output streams.
P.S. I actually wanted to reply to this page, but there was no way to leave a comment there…