PHP 7 Tip Type

<?php
namespace XYZ\Model;

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

?>

Now it happens that a string is considered a type XYZ\Model\string, and therefore, any classes that I implement that implement the interface do not match (in different namespaces).

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

Also, how many types of booleans 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

+4
source share
2 answers

UPDATE: everything is fine with PHP. it is a boolean that does not support the scalar type of hint.

-1
source

Code on 7.0.3, , , ; .

namespace XYZ\Model;

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


class Test implements User {
    public function getName(): string {
        return 'SomeName';
    }
}

$t = new Test;
echo $t->getName();

:

SomeName

+2

All Articles