Re: [RFC] Scalar Type Hints
| From: | S.A.N | Date: | Fri, 02 Jan 2015 21:55:32 +0000 |
| Subject: | Re: [RFC] Scalar Type Hints | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80110@lists.php.net to get a copy of this message | ||
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