Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnvironmentDetector doesn't parse options separated with a space #28831

Closed
matt-allan opened this issue Jun 13, 2019 · 1 comment · Fixed by #28869
Closed

EnvironmentDetector doesn't parse options separated with a space #28831

matt-allan opened this issue Jun 13, 2019 · 1 comment · Fixed by #28869
Labels

Comments

@matt-allan
Copy link
Contributor

  • Laravel Version: 5.8.21
  • PHP Version: 7.3.5
  • Database Driver & Version: N/A

Description:

The Symfony console component that is used by the Artisan console allows separating option names and values with either a space or an equals (=) sign. For example:

$ php artisan serve --port=9090 
Laravel development server started: <http://127.0.0.1:9090>
$ php artisan serve --port 9090 
Laravel development server started: <http://127.0.0.1:9090>

However, the --env option is only parsed correctly if you use an equals sign. If you use a space app()->environment() will return false.

This inconsistency is pretty confusing and difficult to debug. If you dump $this->option('env') in a command it will return the expected value but $app()->environment() will return false.

Steps To Reproduce:

  1. Pass the --env flag to tinker, i.e. `php artisan tinker --env testing
  2. Execute app()->environment() in the tinker shell
$ php artisan tinker --env=testing
Psy Shell v0.9.8 (PHP 7.3.5 — cli) by Justin Hileman
>>> app()->environment()
=> "testing"
>>> 
$ php artisan tinker --env testing                                                                                                                                     
Psy Shell v0.9.8 (PHP 7.3.5 — cli) by Justin Hileman
>>> app()->environment()
=> false
>>> 

This appears to be happening because the environment detector uses $_SERVER['argv'] and $_SERVER['argv'] splits the options into two separate array elements if you use a space instead of an equals sign, and the EnvironmentDetector expects a single element to contain both the name and the value.

$ php artisan tinker --env testing                                                                                                                                     
Psy Shell v0.9.8 (PHP 7.3.5 — cli) by Justin Hileman
>>> $_SERVER['argv']
=> [
     "artisan",
     "tinker",
     "--env",
     "testing",
   ]
$ php artisan tinker --env=testing                                                                                                                                    
Psy Shell v0.9.8 (PHP 7.3.5 — cli) by Justin Hileman
>>> $_SERVER['argv']
=> [
     "artisan",
     "tinker",
     "--env=testing",
   ]
@driesvints driesvints added the bug label Jun 13, 2019
@driesvints
Copy link
Member

Thanks for reporting. Welcoming any help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants