Request for Comments: Optional Strict Type Checking for Scalars

The idea is that certain applications and/or use cases could benefit from the ability to specify the specific types that functions and methods accept as parameters. The benefits of this approach is the improved code clarity and more detailed code interrogation via reflection for the purposes of WSDL and automatic comment generation. There are also security benefits of effectively being able to perform strict type checking around input parameters.

The implemented functionality allows the type hints to be queried by the Reflection API, and through extensions. PHP itself does *not* do any extra checks.

The supported type hints are as follows: (int/integer/long, float/double, string/binary, bool/boolean, resource, object, scalar and numeric)

The “object” type-hint indicates that the function and/or method is looking for an object of some-sort, rather then a specific instance of an object as the current functionality offers.

The patch also introduces additional methods into reflection, to simplify interrogation of the code.

ReflectionParameter::isInt() - Returns whether parameter MUST be a long

ReflectionParameter::isDouble() -Returns whether parameter MUST be a double

ReflectionParameter::isBool() - Returns whether parameter MUST be a boolean

ReflectionParameter::isObject() - Returns whether parameter MUST be a boolean

ReflectionParameter::isString() - Returns whether parameter MUST be a string

ReflectionParameter::isResource() - Returns whether parameter MUST be a resource

ReflectionParameter::getTypeHint() - Returns what type hint is defined for this parameter

rfc/typecheckingparseronly.txt · Last modified: 2017/09/22 13:28 by