As hakre stated, casting to user defined types is not natively possible in PHP (as far as I know).
What you could do is create a method in either class A or B. Something like:
class A
{
public static function fromB( B $object )
{
/* your routine to convert an object of class B to an instance of class A */
}
/* or */
public static function fromA( A $object )
{
/* your routine to convert any object that is a subclass of A to a concrete instance of class A */
}
}
or
class B
extends A
{
// this method could even be implemented in A already as well actually
public function toA()
{
/* your routine to convert this object to an object of class A */
}
}
In the first example the first factory method can be problematic, since it requires A to have concrete knowledge about a specific subclass. You need to determine whether this is desirable in your situation. Perhaps you could abstract this to have the factory method accept any object that inherits from A, like the second factory method.
In the second example, B automatically already knows about A, because it inherits from it. This might be more desirable. But come to think of it, this could even already be implemented in A as well, such that the method is automatically available in all subclasses of A already.