Calling An Overridden Method (Php 5 Syntax)

<?php
 class Item {
   private $name;   function __construct( $name="item", $code=0 ) {
     $this->name = $name;
     $this->code = $code;
   }  function getName() {
    return $this->name;
  }
}class PriceItem extends Item {
  function getName() {
    return "(price) ".parent::getName ();
  }
}$item = new PriceItem ("widget", 5442);
print $item->getName();?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.