Framework: Artisan error. Negative number as argument

Created on 18 Sep 2019  路  2Comments  路  Source: laravel/framework

  • Laravel Version: 5.8.34
  • PHP Version: 7.3.8
  • Database Driver & Version: Ver 15.1 Distrib 10.0.38-MariaDB

Steps To Reproduce:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MyCommand extends Command
{
    protected $signature = 'my:command {value}';

    public function handle(): void
    {
        $this->line($this->argument('value'));
    }
}

Run:

$ php artisan my:command test_string
test_string

$ php artisan my:command -123
RED: The "-1" option does not exist.

$ php artisan my:command "-123"
RED: The "-1" option does not exist.

$ php artisan my:command '-123'
RED: The "-1" option does not exist.

$ php artisan my:command \-123
RED: The "-1" option does not exist.

$ php artisan my:command "\-123"
\-123

Expect:

$ php artisan my:command -123
-123

Most helpful comment

Use a double dash:

php artisan my:command -- -123

All 2 comments

The reason is Symfony trusts a parameter starting with '-' as a shortcut.

Use a double dash:

php artisan my:command -- -123
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

shopblocks picture shopblocks  路  3Comments

JamborJan picture JamborJan  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments