Build system of Sublime Text 3 executes a different version of PHP

Deadly 提交于 2019-12-08 05:48:24

问题


I am using SublimeText3 on OSX. The problem is:

  • If I execute PHP script on SublimeText3, then it is executed by PHP 5.5.
  • But if I execute the same script from shell (iTerm), then it is executed by PHP 7.

How can I execute a script with PHP7 on SublimeText3?

The build system is following.

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

And the PHP script is just:

<?php
phpinfo();
?>

回答1:


Specify the absolute path to the command (cmd).

Let's say $file is /path/to/file, then the command ['php', "$file"] expands to php /path/to/file. This is like running the following on the command line:

$ php /path/to/file

Because the command (php ) is relative, the system path (on linux the system path is in the environment variable PATH) is searched to find php.

You can specify an absolute path for the command. Let's 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 a 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

  • What are Enviornment Variables


来源:https://stackoverflow.com/questions/40002608/build-system-of-sublime-text-3-executes-a-different-version-of-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!