How to resolve “must be an instance of string, string given” prior to PHP 7?

后端 未结 9 1260
情话喂你
情话喂你 2020-11-27 10:32

Here is my code:

function phpwtf(string $s) {
    echo \"$s\\n\";
}
phpwtf(\"Type hinting is da bomb\");

Which results in this error:

9条回答
  •  长情又很酷
    2020-11-27 11:05

    As of PHP 7.0 type declarations allow scalar types, so these types are now available: self, array, callable, bool, float, int, string. The first three were available in PHP 5, but the last four are new in PHP 7. If you use anything else (e.g. integer or boolean) that will be interpreted as a class name.

    See the PHP manual for more information.

提交回复
热议问题