Here comes my phpbrew list and phpbrew system results:
$ phpbrew list
php-7.4.1
php-7.3.13
* php-5.6.40
$ php -v
PHP 5.6.40 (cli) (built: Dec 27 2019 17:15:44)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
$ phpbrew system
/Users/mark/.phpbrew/php/php-7.3.13/bin/php
It use PHP-5.6.40 as default php interpreter, and use PHP-7.3.13 as system interpreter. When I use phpbrew config to edit my php.ini file. I suppose it will edit php.ini for 5.6.40, but it just edit php.ini for 7.3.13.
I also try phpbrew list-ini, it shows me ini files for 7.3.13, instead of 5.6.40.
$ phpbrew list-ini
Loaded ini files:
- /Users/mark/.phpbrew/php/php-7.3.13/var/db/ast.ini
- /Users/mark/.phpbrew/php/php-7.3.13/var/db/gd.ini
- /Users/mark/.phpbrew/php/php-7.3.13/var/db/opcache.ini
- /Users/mark/.phpbrew/php/php-7.3.13/var/db/xdebug.ini
But, phpbrew cd works well.
$ phpbrew cd etc
Switching to /Users/mark/.phpbrew/php/php-5.6.40/etc, run 'cd -' to go back.
Is it expected behavior with the new introduced system command? or a bug?
My phpbrew version is 1.25.1 and os is macOS 10.14.6.
Yeah, this is a bug. Besides being used as an interpreter for PHPBrew, the system interpreter shouldn't leak into any other use cases.
It looks like in order to work properly, the functionality of ConfigCommand and ListIniCommand needs to be reimplemented in the shell. Otherwise, even if we execute them using the currently used interpreted, it will stop working when we bump the runtime PHP version requirement.
Ideally, we want to identify potentially affected commands like those before reworking them.
Can we just implement a new function to wrap php_ini_loaded_file() like the following?
function getCurrentPhpIni()
{
$bin = Config::getCurrentPhpBin();
$file = system($bin."/php -r 'echo php_ini_loaded_file();'");
return $file
}
Maybe, it will be easier.
I just tested in my branch, it seems work, only a prove of concept.
class ConfigCommand extends Command
{
// ...
public function execute()
{
$file = $this->getCurrentPhpIni();
if (!file_exists($file)) {
$php = Config::getCurrentPhpName();
$this->logger->warn("Sorry, I can't find the {$file} file for php {$php}.");
return;
}
Utils::editor($file);
}
private function getCurrentPhpIni()
{
$bin = Config::getCurrentPhpBin();
$file = system($bin."/php -r 'echo php_ini_loaded_file();'");
return $file;
}
}
That sounds good. Please shoot a PR. It's a bit convoluted that we're using two PHP interpreters to execute one command but we can revisit the design later.
Fixed by #1136.