Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From <a href="http://php.net/manual/en/language.oop5.typehinting.php" rel="noreferrer">PHP's manual</a> :</p> <blockquote> <p>Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported.</p> </blockquote> <p>So you have it. The error message is not really helpful, I give you that though.</p> <h2>** 2017 Edit **</h2> <p>PHP7 introduced more function data type declarations, and the aforementioned link has been moved to <a href="http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration" rel="noreferrer">Function arguments : Type declarations</a>. From that page :</p> <blockquote> <h3>Valid types</h3> <ul> <li><strong>Class/interface name</strong> : The parameter must be an instanceof the given class or interface name. (since PHP 5.0.0)</li> <li><strong>self</strong> : The parameter must be an instanceof the same class as the one the method is defined on. This can only be used on class and instance methods. (since PHP 5.0.0)</li> <li><strong>array</strong> : The parameter must be an array. (since PHP 5.1.0) callable The parameter must be a valid callable. PHP 5.4.0</li> <li><strong>bool</strong> : The parameter must be a boolean value. (since PHP 7.0.0)</li> <li><strong>float</strong> : The parameter must be a floating point number. (since PHP 7.0.0)</li> <li><strong>int</strong> : The parameter must be an integer. (since PHP 7.0.0)</li> <li><strong>string</strong> : The parameter must be a string. (since PHP 7.0.0)</li> <li><strong>iterable</strong> : The parameter must be either an array or an instanceof Traversable. (since PHP 7.1.0)</li> </ul> <h3>Warning</h3> <p>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:</p> <pre><code>&lt;?php function test(boolean $param) {} test(true); ?&gt; </code></pre> <p>The above example will output:</p> <pre><code> Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of boolean, boolean given, called in - on line 1 and defined in -:1 </code></pre> </blockquote> <p>The last warning is actually significant to understand the error "Argument must of type string, string given"; since mostly only class/interface names are allowed as argument type, PHP tries to locate a class name "string", but can't find any because it is a primitive type, thus fail with this awkward error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload