How to use strict types with anonymous classes in PHP

1 Answer

0 votes
declare(strict_types=1);

function process(object $o): void {
    echo "process() OK";
}

process(new class {});   // OK
process("not object");   // TypeError



/*
run:

ERROR!
process() OK
Fatal error: Uncaught TypeError: process(): Argument #1 ($o) must be of type object, string given

*/

 



answered Aug 9 by avibootz
...