phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


OOP: Implementing Inheritance ( Part 3 )

Tag: OOP   Category: PHP Basic
post: 17 Nov 2007 read: 920


Inheritance is mean "extending" a class. When we extend a class, we use extends keyword. It will add methods and properties in new class from base class. For example like following code:


  <?
  class vehicle
  {
    	var $type;
    	var $limit = 100;
  	
    	function vehicle( $type )
    	{
      		$this->type = $type;
    	}
  	
    	function oil_change ( $miles )
    	{
      		return ($miles / $this->limit);
    	}
  
  }
  
  class car extends vehicle
  {
  
    	var $limit = 1500;
  	
    	function car ( $type )
    	{
      		$this->type = $type;
  		
    	}
  
  }
  
  $obj = new car( 'city car' );
  echo $obj->type;
  echo $obj->oil_change(4500);
  ?>


Series this article:
OOP: Class (Part 1)
OOP: Classes as Namespace (Part 2)
OOP: Implementing Inheritance ( Part 3 )

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting