phar-io/phive

phive install failure: Undefined variable: output

arcesino opened this issue · 6 comments

I installed phive locally in my project using the instructions at https://phar.io/#Install with the only difference that instead of moving the executable to /usr/local/bin/phive I'm moving it to project's repo bin/ directory.

Then, when I run:

bin/phive install phpunit

I got following error:

❯ bin/phive install phpunit
Phive 0.15.0 - Copyright (C) 2015-2022 by Arne Blankerts, Sebastian Heuer and Contributors
[ERROR]   An error occurred while processing your request:

          Undefined variable: output
          
          #0 src/shared/environment/UnixoidEnvironment.php(89)
          #1 src/shared/environment/UnixoidEnvironment.php(89): PharIo\Phive\Cli\Runner->errorHandler()
          #2 src/shared/environment/Environment.php(55): PharIo\Phive\UnixoidEnvironment->getWhichCommand()
          #3 src/shared/config/Config.php(130): PharIo\Phive\Environment->getPathToCommand()
          #4 src/Factory.php(381): PharIo\Phive\Config->getGPGBinaryPath()
          #5 src/Factory.php(374): PharIo\Phive\Factory->getGnupg()
          #6 src/Factory.php(367): PharIo\Phive\Factory->getGnupgSignatureVerifier()
          #7 src/Factory.php(360): PharIo\Phive\Factory->getPharDownloader()
          #8 src/Factory.php(328): PharIo\Phive\Factory->getPharService()
          #9 src/Factory.php(100): PharIo\Phive\Factory->getInstallService()
          #10 src/commands/CommandLocator.php(42): PharIo\Phive\Factory->getInstallCommand()
          #11 src/shared/cli/Runner.php(241): PharIo\Phive\CommandLocator->getCommand()
          #12 src/shared/cli/Runner.php(95): PharIo\Phive\Cli\Runner->execute()
          #13 (350): PharIo\Phive\Cli\Runner->run()
          #14 {main}

          Environment: PHP 7.4.28 (on Darwin 20.6.0)
          Phive Version: 0.15.0

          This should not have happened and is most likely a bug.
          Please report it at https://github.com/phar-io/phive/issues, make sure you include
          the full output of this error message. Thank you!

The PHP I'm using was installed using phpbrew and my OS is macOS Big Sur v11.6

I cannot reproduce this on Linux.

I also fail to see how this error can occur: Based on the stacktrace the undefined varibale $output is used as an by-reference paramter to exec. I don't understand how it could possibly be "not set" in this context.

I'll have to investigate that.

I tried installing phive using Homebrew and I'm seeing that's also failing using my phpbrew installed PHP but it works correctly if I use the Homebrew's installed PHP.

The only customization in my phpbrew installed PHP is that I disabled a lot of functions so that it matches the PHP configuration in my web hosting provider. The disabled functions are:

disable_functions = allow_url_fopen,apache_child_terminate,apache_setenv,define_syslog_variables,dl,escapeshellarg,escapeshellcmd,eval,exec,fp,fput,ftp_connect,ftp_exec,ftp_get,ftp_login,ftp_nb_fput,ftp_put,ftp_raw,ftp_rawlist,highlight_file,inject_code,leak,passthru,pfsockopen,popen,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,virtual,allow_url_include,chgrp,lchgrp,chown,lchown,diskfreespace,fpaththru,getmyuid,ignore_user_abord,link,listen,pcntl_exec,set_time_limit,tmpfile,posix,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getpwnam,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_setegid,posix_seteuid,posix_setgid,posix_times,posix_ttyname,disk_free_space,diskfreespace,ini_alter,ini_restore,openlog,debug_zval_dump

Actually, I also had php_uname function disabled but I enabled it since phive failed with an exception explicitly pointing that function was disabled, so I enabled it back.

Based on this, I tried enable all the functions in my phpbrew installed PHP's php.ini file and that made the trick. So, it's clear to me that the error I was getting was caused due to some of the disabled function but, since the error doesn't give any hint, I'm not able to figure out which one.

Hope this additional information can help figure out the issue, if any.

I took a look at src/shared/environment/UnixoidEnvironment.php and noticed it was using exec function which is one I had disabled. I enabled it back and then received a couple more errors for functions escapeshellarg & symlink but, for those functions, the error was really helpful:

❯ bin/phive install phpunit
Phive 0.15.0 - Copyright (C) 2015-2022 by Arne Blankerts, Sebastian Heuer and Contributors
[ERROR]   An error occurred while processing your request:

          escapeshellarg() has been disabled for security reasons
          
          #0 src/shared/environment/Environment.php(55)
          #1 unknown file(0): PharIo\Phive\Cli\Runner->errorHandler()

Once I enabled back those other functions I can run phive without issues. So, it seems to me the issue is simply the misleading error when exec function is disabled.

Thanks so much for the support!

Ah! Yes, that helps a lot and explains it even: We're calling gnupg via exec (unless the ext/gnupg extension is installed). Without exec priviliges (and the exec function being available) we cannot operate.

I'm not sure whether this qualifies as a bug. Breaking PHP by arbitrarily disabling function is something we certainly do not test for.

So apparently, for whatever reason a disabledexec behaves differently than the other functions. Interesting and maybe even a bug in PHP itself ;)

I agree this doesn't qualify as a bug in Phive. It may be helpful to improve the error so it points out to exec function being disabled. In any case, having this issue will help others that may encounter the same error.