PHPBuilder - Object Oriented Programming in PHP: The Way to Large PHP Projects



RSS Twitter
Articles Application Architecture

Object Oriented Programming in PHP: The Way to Large PHP Projects

by: Luis Argerich
|
January 25, 2008

This arcticle introduces Object Oriented Programming (OOP) in PHP. I will show you how to code less and better by using some OOP concepts and PHP tricks. Good luck!
Concepts of object oriented programming: There're differences between authors, I can mention that a OOP language must have:
  • Abstract data types and information hidding
  • Inheritance
  • Polymorphism
The encapsulation is done in php using classes:

<?php

class Something {
    
// In OOP classes are usually named starting with a cap letter.
    
var $x;

    function 
setX($v) {
        
// Methods start in lowercase then use lowercase to seprate
        // words in the method name example getValueOfArea()
        
$this->x=$v;
    }

    function 
getX() {
        return 
$this->x;
    }
}

?>
Of course you can use your own nomenclature, but having a standarized one is useful.

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Luis Argerich

Comment:



Comment:

(Maximum characters: 1200). You have characters left.