この RFC は4種類のスカラー型、int、float、string と bool の新しい型宣言の追加を提案します。これらの型宣言は PHP 関数が使う既存のメカニズムと同じようにふるまいます。
この RFC はファイル単位でオプションの新しいディレクティブである declare(strict_types=1); をさらに追加することを提案します。このディレクティブによって、エクステンションとビルトインの PHP 関数を含む、すべての関数呼び出しと戻り値の宣言は "strict" なスカラー型の宣言に対して型チェックがなされます。さらに、このディレクティブを伴うエクステンションとビルトインの PHP 関数の呼び出しによって、パラメーター解析が失敗した段階において、E_RECOVERABLE_ERROR が生成され、これらの関数とユーザーランドの型宣言との協調がもたらされます。
これら2つの機能によって、PHP のプログラムは正しく動き、読み書きの前提知識を減らすことができます (self-documenting)。
新しい予約語は追加しません。int、float、string、bool の名前は型宣言の用途に許可され、(use と class_alias も含めて) クラス/インターフェース/トレイトの名前に使うことが禁止されます。
内部において新しいユーザーランドのスカラー型の宣言は Fast Parameter Parsing API 関数を呼び出すことで実装されます。
strict_types declare() ディレクティブ
strict モードにおけるエラーハンドラのふるまい
Weak typing and strict typing
This Proposal Is A Compromise
Internal Functions Like ceil() Return Unexpected Types
"37" Should Be Accepted For int Types
Integers Should Be Accepted For Strict float Arguments
Weak Should Error On "10 Birds" Style-Strings Passed To Int Parameters
Int -> Float Conversion Isn't Lossless
Int->Float Exception Makes Strict Mode "Flawed"
Static Analysis Is Possible With Weak Declarations
Errors Should Use Exceptions Instead Of Recoverable Errors
There Should Be A numeric Type
Internal Functions Should "Opt-In" To Typing
Why Not Use "use strict" Instead Of declare()
Why Not Allow Block-Mode For Declare
Internal Functions Do Not Have Declared Return Types
Why Not Add Support For Null?
Why Not Add Support For MIXED?
Why Not Add An INI Setting For Default Mode
Type Aliases Should Not Be Supported
This Proposal Should Have Multiple Vote Options
Integer Overflow To Float Behavior
Backward Incompatible Changes
Unaffected PHP Functionality