php 的数组接口无效
not work array interface to php
我正在使用 Laravel 框架和版本 php 5.5.12
<?php
namespace App\pattern;
interface status
{
const status = array(
"confirm"=> 1
,"unconfirm"=> 2
,"record"=> 3
);
}
使用后class
$r = $this::status['confirm'];
显示错误
FatalErrorException in ContentController.php line 19: syntax error, unexpected '['
没有$this
,是接口
你需要像这样使用它:
$r = status::status['confirm'];
// ^ ^
// | constant name
// interface name
//
echo $r;
尽管可能很奇怪,接口 确实支持 常量,如 here: php constants
所述
但是在 php 5.5 中,您不能将 array
作为常数
您可以查看 https://3v4l.org/JbdJa 并查看它作为接口调用或在实现该接口的 class 中运行
我正在使用 Laravel 框架和版本 php 5.5.12
<?php
namespace App\pattern;
interface status
{
const status = array(
"confirm"=> 1
,"unconfirm"=> 2
,"record"=> 3
);
}
使用后class
$r = $this::status['confirm'];
显示错误
FatalErrorException in ContentController.php line 19: syntax error, unexpected '['
没有$this
,是接口
你需要像这样使用它:
$r = status::status['confirm'];
// ^ ^
// | constant name
// interface name
//
echo $r;
尽管可能很奇怪,接口 确实支持 常量,如 here: php constants
所述但是在 php 5.5 中,您不能将 array
作为常数
您可以查看 https://3v4l.org/JbdJa 并查看它作为接口调用或在实现该接口的 class 中运行