PHP 7 类型提示问题


PHP 7 Type Hinting Issues

<?php
namespace XYZ'Model;
interface user{
public function getName() : string;
}
?>

现在,发生的情况是字符串被假定为XYZ'Model'string类型,因此,我实现接口的任何类都不匹配(在不同的命名空间中)。

但是,如果我执行'string,则代码失败并显示Scalar type declaration must be unqualified

此外,布尔值可以有多少种?删除一些提示后,我得到:Return value of xxxxx::save() must be an instance of boolean, boolean returned in xxxxxx.php:41

在 7.0.3 上测试了以下代码,它工作正常,请记住,我在命名空间定义旁边添加了一个缺失的;

namespace XYZ'Model;
interface user {
    public function getName(): string;
}

class Test implements User {
    public function getName(): string {
        return 'SomeName';
    }
}
$t = new Test;
echo $t->getName();

输出:

某名

更新:PHP一切都很好。 它是不支持标量类型提示的布尔值。