Sublime Text 3 build system runs another version of PHP

I am using SublimeText3 on OSX. The problem is this:

  • If I run a PHP script on SublimeText3, then it runs PHP 5.5.
  • But if I execute the same script from the shell (iTerm), then it runs PHP 7.

How can I execute a script from PHP7 to SublimeText3?

The assembly system is as follows.

{ "cmd" : ["php", "$file"], "file_regex": "php$", "selector" : "source.php" } 

And the PHP script is just:

 <?php phpinfo(); ?> 
+1
source share
1 answer

Specify the absolute path to the command (cmd).

Say $file is /path/to/file , then the command ['php', "$file"] expands to php /path/to/file . This is similar to executing the following commands on the command line:

 $ php /path/to/file 

Since the command ( php ) is relative, a search on the system path (on the linux system path in the PATH environment variable) is performed to find php .

You can specify the absolute path for the command. Say you have the following versions installed:

  • /path/to/php/versions/7.0.0/bin/php
  • /path/to/php/versions/5.5.0/bin/php

Then you can configure the command to use v7.0.0:

 { "cmd" : ["/path/to/php/versions/7.0.0/bin/php", "$file"], "file_regex": "php$", "selector" : "source.php" } 

And v5.5.0:

 { "cmd" : ["/path/to/php/versions/5.5.0/bin/php", "$file"], "file_regex": "php$", "selector" : "source.php" } 

And so on...

Further reading

+2
source

Source: https://habr.com/ru/post/1258130/


All Articles