Q:

What is the proper OO way to convert an object to one of its subclasses (covariant return type)?

I have a subclass that needs to return a subclass of the return type of its parent class.  I believe this is called a covariant return type.  I am wondering the simplest way to convert from the parent to the child class.
class A {
}
class B extends A {
  function bar() {
  }
}

class Car {
  function foo() {
    return new A();
  }
}

class BrokenCar extends Car {
  function foo() {
    $a = parent::foo();
    //What is the cleanest way to convert $a to type B ?
  }
}

A:

In PHP you can not "convert" objects from type/class A to B with a feature available in the language.
You can do so however by making use of serialization if your objects support it (normally plain old PHP objects do support serialization). In the serailized form you change the class of the object and unserialize it again. A has turned into B then. But that's not really fluent.

A:

This actually should be a comment, but I'm going to make an important point.
Programming is engineering and programming is design. There's no way to tell why design A is better than design B without knowing how it's going to be used. Ask a designer, should your submit button be red or green - and she says: hmm, where, on which site? Ask an engineer if you should use a beam or a gear couping - and the answer will be: depends on what for. So, what makes you think we can give you a meaningful design advice, if you only gave us a "BrokenCar" class with a "foo" method. Tell us what you actually want to achieve with that, otherwise the only answer I can come up with is
the best way to use foo is bar

