OK, let's expand my example a bit:
Shape defines a draw() method on it. Each subclass overrides the draw() method to do some specific drawing (possbily with new member variables such as radius, possibly not).
Let's take an example where it doesn't use any extra info, but rather just has different behavior.
Here's some quick code:
$obj = new Shape();
// Draw the object normally
$obj->Draw();
// Draw the object as a 3D shape
$objTwo = (3DShape) $obj;
$obj->Draw();
You can't do this without casting because you have no context as to which version of Draw() you should be calling without casting the object.
( To expand a bit on the sceanrio. Here's some simplified code
// Creates an array generic shape based on xml
function createShapeObjectsFromXML($xml) {
}
$arrShapes = createShapeObjectsFromXML($xml);
// Now I want to manipulate and change those objects, some will be Circles, others squares, etc. I may set properties on those, I may not
(Code omitted)
for ($i = 0; $i < count($arrShapes); $i++) {
// Will call overriden Draw() function
$arrShapes[$i]->Draw();
}
Hoipe that makes things a little more clear)