5

When I run a script on Windows using PHP 5.6 (coming from WampServer 2.4) I get this confusing result:

$binary = PHP_BINARY;  // $binary: "C:\wamp\bin\php\php5.6.15\php.exe"
$bindir = PHP_BINDIR;  // $bindir: "C:\php"

PHP_BINARY is correct but PHP_BINDIR is completely wrong. Is the latter variable deprecated or something? Any other ideas why it would output some random path that doesn't even exist on my disk?

Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
  • Could you share the script ? –  Feb 17 '16 at 15:07
  • This is the script. I declare two variables and run it as a unit test from PhpStorm. (The variable contents that is displayed to the right is a debugging feature of PhpStorm.) – Borek Bernard Feb 17 '16 at 15:10
  • I hope [this answer](http://stackoverflow.com/questions/3889486/how-to-get-the-path-of-the-php-bin-from-php) will be helpful. –  Feb 17 '16 at 15:15

2 Answers2

6

PHP_BINARY is a value set on runtime (when the script is executed)

PHP_BINDIR is a value set on compile time, not on runtime.

The path is set to the prefix used in configure (Linux equivalent: ./configure --prefix <path>). The default path on windows is C:\php. You cannot change it without recompiling PHP.

To get the path, you should trail down PHP_BINARY.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
0

The issue is with PHP_BINDIR which according to the php-internals/11c783wgty/bug-54514 is set at compile time. This suggests this may change at some later date.

Anything set at compile time is going to be irrelevant to, at least us windows users, as we normally rely on someone else to do the compilation as Windows does not come with a free compiler. As far as I can tell this would apply to php compiled on a unix machine as well as a windows machine as there is no reason to be positive PHP is running from where it was compile into.

So dont use PHP_BINDIR to find where the current executable is running from.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149