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!
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:
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.