I have a method that returns true or false, however when I add a type declaration isAdmin() : string
it is not throwing a fatal error.
I have declare(strict_types=1);
in a second file that is included before the class.
Example:
file1.php
<?php
declare(strict_types=1);
file2.php
<?php
include "file1.php";
class Test
{
public function user() : int
{
return true;
}
}
$test = new Test();
var_dump($test->user());
This code won't throw a fatal error. Instead the var_dump returns the bool as int(1)
. If I change method type to a string, var_dump returns the bool as string(1) "1"
.
How can I avoid putting declare(strict_types=1);
in every model file?