Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Artisan控制台命令的本地化_Php_Laravel_Laravel Artisan_Protected - Fatal编程技术网

Php Artisan控制台命令的本地化

Php Artisan控制台命令的本地化,php,laravel,laravel-artisan,protected,Php,Laravel,Laravel Artisan,Protected,我正在为我的Laravel应用程序编写一个可本地化的应用程序。由于命令的帮助文本被定义为$signature类变量的一部分,因此我尝试如下创建它: /** * The name and signature of the console command. * * @var string */ protected $signature = sprintf( "myapp:command {--i|id %s}", __("This is some help text for

我正在为我的Laravel应用程序编写一个可本地化的应用程序。由于命令的帮助文本被定义为
$signature
类变量的一部分,因此我尝试如下创建它:

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = sprintf(
    "myapp:command {--i|id %s}",
    __("This is some help text for the ID")
);
但是,我收到以下错误消息:

PHP致命错误:常量表达式包含无效操作


我假设
protected
类变量被视为常量,那么如何为帮助文本提供一个可正确本地化的字符串呢?有什么方法可以在对象实例化后提供文本吗?

函数不能用于属性声明,但可以用于构造函数,这很好:

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    $this->signature = sprintf(
        "myapp:command {--i|id %s}",
        __("This is some help text for the ID")
    );
    parent::__construct();
}

在构造函数中定义签名怎么样?这很简单。谢谢