Running following in Terminal on macOS Mojave
php -r 'foo();' 2>/dev/null
Produces
Fatal error: Uncaught Error: Call to undefined function foo() in Command line code on line 1
Error: Call to undefined function foo() in Command line code on line 1
Call Stack:
0.0002 390016 1. {main}() Command line code:0
But on Ubuntu Xenial and FreeBSD it produces no output, which is expected, as I am silencing the error. I tried with zsh 5.7.1, default bash 3.2.57 and bash 5.0.11. I'm interested why is this the case on macOS.
Another interesting thing here is that when redirecting both stdout and stderr, then there is finally no output. But redirecting neither stdout nor stderr has the silence effect.
Some more info:
➜ ~ type php
php is /usr/local/bin/php
➜ ~ file $(type -p php)
php: cannot open `php' (No such file or directory)
is: cannot open `is' (No such file or directory)
/usr/local/bin/php: Mach-O 64-bit executable x86_64
➜ ~
type php
andfile $(type -p php)
?php -r 'foo();' 1>/dev/null
suppresses the output here (which of course isn't what you want)zsh
.