Not. PHP does not support explicit type declarations or hint types; using the juggling type is clearly part of the PHP interpreter. In documents in a type, only hints of the type of the object and array are hinted.
However, if you have a function with strict type requirements, it becomes important to check these arguments at the beginning of the function. If you are very attached to the idea of ββtypes in PHP, you can: a) switch to a typed language (heh) or b) use the autoboxing / object-wrapper pattern. There is a significant performance is_string for this, but instead of using primitive type checks (i.e. is_string ), you can create a wrapper class and use the hint type:
class StringWrapper { public $value = null; function __construct($val) { $this->value = $val; } } function requires_a_string(StringWrapper $string_value) { echo $string_value->value; } $string = new StringWrapper('Hello world!');
As you can see, this is a fairly large hill to raise (with the creation of a wrapper for each type) to avoid:
function requires_a_string($string_value='') { if (!is_string($string_value)) return false; echo $string_value; }
My verdict: not worth it.
Here you can read a few more autoboxins: http://php.webtutor.pl/en/2011/04/13/strong-data-typing-in-php-part-ii-autoboxing-and-indestructable-objects-english- version / Also pay attention to this RFC for autoboxing: https://wiki.php.net/rfc/autoboxing It has been a while, so I would not hold out for that.
source share