Search code examples
phptypeshint

PHP 7 Type Hinting Issues


<?php
namespace XYZ\Model;

interface user{
public function getName() : string;
}

?>

Now, what happens is that string is assumed to be the type XYZ\Model\string and hence, any classes I make implementing the interface don't match up (in different namespaces).

If however I do a \string, the code fails with Scalar type declaration must be unqualified.

Besides, how many types of boolean can there be? After removing some hints, I got: Return value of xxxxx::save() must be an instance of boolean, boolean returned in xxxxxx.php:41


Solution

  • UPDATE: Everything's alright with PHP. it's boolean that doesn't support scalar type hinting.