PHP类型提示错误?

Mic*_*ael 6 php type-hinting php-5.3

我刚收到这个致命错误

可捕获的致命错误:传递给File :: __ construct()的参数1必须是整数的实例,给定整数,在第9行的/home/radu/php_projects/audio_player/index.php中调用,并在/ home/radu/php_projects中定义第7行/audio_player/php/File.php

所以,有班级

class File{        
        public $id;
        public $name;
        public $file_paths;
        public function __construct(integer $id=null, string $name=null, array $file_paths=null)
        {
            foreach(func_get_args() as $name => $val)
            {
                $this->$name = $val;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是触发错误的代码

$file = new File(1, "sound", array());
Run Code Online (Sandbox Code Playgroud)

我错过了什么或者这种PHP类型暗示有什么不好的东西?

小智 4

因为这可能会产生误导,而且这个答案在搜索引擎中的排名仍然很高。

PHP 7 确实引入了标量类型的类型提示

PHP 5 中没有标量类型提示,因此integer类型提示被视为类类型提示。

更多参考http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration