phpeveryday.com

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


OOP: Classes as Namespace (Part 2)

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


Methods in class can be accessed in two ways: dinamically or statically. Dinamically, it mean instantiating an object. We have done in past tutorial. Statically, by treating the class as a namespace. Look following code:


  <?
  class vehicle
  {
   	var $type;
   	
   	function vehicle( $type )
   	{
     		$this->type = $type;
   	}
 
    function oil_change ( $miles )
    {
      return ($miles / 15000);
    }
 
  }
 
 
  echo vehicle::oil_change (45000);
 
  ?>

We use :: operator. Namespace can avoid naming conflicts in your library.



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