PHP OOP : Constructor function

What is Constructor ?

Constructor is a special type of function of a class which is automatically executed when object of that class is created. Constructor is also called as magic function because in php constructor is start usually with two underscore characters. It saves lot of time on big project.

function __constructor(){
body part;
}

Example of Constructor :-

Tagged : / / / / / / / / / / / /

Introduction to PHP OOP

What is PHP?

  • PHP stands for hypertext preprocessor.
  • It is widely used in backend programming language.
  • PHP programming patterns are procedural/core php and object oriented.
  • Lots of framework are use like laravel, CakePHP, Yii, Zend, Codeigniter etc.
  • Code more modular and reusable.
  • Well organised code.
  • Easier to debug.
  • Best for large website projects.

Why is it so popular ?

  • Code reusable
  • Easier to debug
  • Best for medium and large website project
  • Backend programming use
  • Code more modular
  • Understanding code easier

What are class and object ?

  • Class are the blueprint of object ; Object use blueprint to build their project or functions.
  • Class example :- blueprint of house ; Object example :- built house.
  • Class function one ; Object function are lots that are related to class function.
  • If there is a function which is written in object but not written in class then that function will not work.

What is properties and methods ?

properties like :-

$a;
$b;
$c;
$d;

Methods like :-

sum(){
$c=$a+$b;
return $c;
}

Example of PHP :-

Tagged : / / / / / / / / / / / /