Syntax forced cast, it makes sense not only for scalar types, but also for
instances of classes.

Is a syntactic sugar can be realized

<?php

class User
{
    public function __construct(int $id)
    {
      ......
    }
}

function printPerson((User) $object)
{
   var_dump($object);

   return ($object instanceof User);
}

printPerson(new User(101)); // TRUE

printPerson(101); // TRUE
// scalar int = 101, sent to constructor method class User, the resulting
instance User passed to the function printPerson

Reply via email to