روش های ارثی را می توان با تعریف مجدد متدها لغو کرد (از همان روش استفاده کنید نام) در کلاس کودک.
به مثال زیر نگاه کنید. متدهای __construct() و intro() در کودک کلاس (Strawberry) متدهای __construct() و intro() در را لغو می کند کلاس والد (میوه):
مثال
<?php class Fruit { public $name; public $color; public function __construct($name, $color) { $this->name = $name; $this->color = $color;
}
public function intro() { echo "The fruit is {$this->name} and the color is {$this->color}.";
} }
class Strawberry extends Fruit { public $weight; public function __construct($name, $color, $weight) { $this->name = $name; $this->color = $color; $this->weight = $weight;
}
public function intro() { echo "The fruit is {$this->name}, the color is {$this->color}, and the weight is {$this->weight} gram.";
} }
$strawberry = new Strawberry("Strawberry", "red", 50); $strawberry->intro(); ?>