2016-12-07 23 views
1

スカラー型にphp7タイプヒントを使用するようにアプリケーションを更新しました。私は、エラーが消えintintegerを交換した場合php 7.0 typehint:整数値とデフォルト値で致命的なエラーが発生する

public function call(string $url, integer $timeout = 30) 
{ 
    // some code... 
} 

PHP Fatal error: Default value for parameters with a class type can only be NULL in xxx.php on line 23

エラーがこの機能である:私は私のユニットテストを実行すると、私はこのエラーを得ました。私はいつもintと整数が同じであると聞きましたが、ドキュメントに関連するものは何も表示されません。

整数はクラスでスカラー型ではないようです。また、真((int) 1) === ((integer) 1)戻りがintと整数が同じ

であることを改めて示唆

私はPHP 7.0.8

+0

「整数」はhttp://php.net/manual/en/functions.arguments.php#functions.arguments.type-declarationには記載されていません。私は、このような混乱を避けるために型キャストで '(整数)'を許してはならないと主張します。 – Devon

+0

だから、 'bool'と' boolean'と同じものになると思います。 –

+0

私はそう仮定します。実際のキーワードは、PHPではboolとintです。 http://php.net/manual/en/reserved.other-reserved-words.php – Devon

答えて

7

を使用する文書によると、これらが有効なタイプです:

Class/interface name 
self 
array 
callable 
bool 
float 
int 
string 

これもあります:

Warning

Aliases for the above scalar types are not supported. Instead, they are treated as class or interface names. For example, using boolean as a parameter or return type will require an argument or return value that is an instanceof the class or interface boolean, rather than of type bool.

出典:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration

+0

私は文書でそれを逃した...それは "新機能"ページに記載されていません –

関連する問題