Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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:名称空间中的类型暗示不起作用?_Php_Type Hinting - Fatal编程技术网

PHP:名称空间中的类型暗示不起作用?

PHP:名称空间中的类型暗示不起作用?,php,type-hinting,Php,Type Hinting,在使用名称空间时,我尝试使用PHP 5.6进行一些类型暗示,但我不断遇到如下错误: <?php namespace NS; class MySubClass extends MyClass { public function __construct(string $mystring) { parent::__construct($mystring); } } ?> PHP可捕获致命错误:参数1传递给 NS\MyClass::\构造()必须是str

在使用名称空间时,我尝试使用PHP 5.6进行一些类型暗示,但我不断遇到如下错误:

<?php namespace NS;

class MySubClass extends MyClass {
    public function __construct(string $mystring) {
        parent::__construct($mystring);
    }
}

?>
PHP可捕获致命错误:参数1传递给 NS\MyClass::\构造()必须是string的实例,string 给予,召唤 /Users/username/path/MyClass.php 在第9行,并在中定义 /Users/username/path/MySubClass.php 在线52

代码基本上如下所示:

<?php namespace NS;

class MySubClass extends MyClass {
    public function __construct(string $mystring) {
        parent::__construct($mystring);
    }
}

?>
错误出现了。 它也不适用于

public function __construct(\string $mystring) {

在命名空间中如何键入提示基本类型?

在PHP 5.6中无法键入提示字符串。PHP7中添加了对该功能的支持

public function __construct(\string $mystring) {