Just like we do with __ToString, is there a way to define a method for casting?
$obj = (MyClass) $another_class_obj;
I think you mean Type-Hinting.
As of PHP 7.2, you can type-hint arguments in functions:
function something(Some_Object $argument) {...} # Type-hinting object on function arguments works on PHP 7.2+
But you can't type-hint it like this:
(Some_Object) $variable = get_some_object($id); # This does not work, even in PHP 7.2
The alternative for type-hinting objects while it isn't implemented officialy in PHP, is:
$variable = get_some_object($id); # We expect Some_Object to return
is_a($argument, 'Some_Object') || die('get_some_object() function didn't return Some_Object');