I searched for quite a while now, but i could not find a definite answer to the question wether the constant PHP_OS contains the OS php was built on or runs on.
The php documentation of php_uname (http://php.net/manual/de/function.php-uname.php) states:
“For the name of just the operating system, consider using the PHP_OS constant, but keep in mind this constant will contain the operating system PHP was built on. “
However, on the very same page there is a comment from 2006 stating:
“Contrary to the last note, PHP_OS does display the OS PHP runs on currently, […] This has nothing to do with the system PHP was built on.”
I could not find any definite answer anywhere on the web regarding this question (topis about php_uname and PHP_OS mostly only cover os detection and similar topics). What’s right now – the documentation or the comment?
The pear-core package uses PHP_OS to determine wether it’s running on Unix-like systems or on windows, so is it safe to assume the documentation is indeed wrong?
I had a look at the source code. The configure script does this:
and then
main.cdoes this:which means that
PHP_OSin PHP is what was inphp_osin the C code, which is what was #defined by the header file constructed by the configure script, which is determined by runningunameat configuration time.So, it’s the system you were built on, not the system you were running on.
There’s some special-cased code for Windows:
main.csetsphp_osto"WINNT"ifWIN32is defined. But, again, this is at build time, not at run time, even if you manage to compile on Unix and run on Windows or vice versa.