SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Wildan Maulana | wildan [at] tobethink.com Object Oriented Programming with PHP 5 #2
What will We Learn Today() ,[object Object],[object Object],[object Object],[object Object]
Let's Bake Some Objects <? //emailer.class..php class  Emailer { private $sender; private $recipients; private $subject; private $body; function __construct($sender) { $this->sender = $sender; $this->recipients = array(); } public function addRecipients($recipient) { array_push($this->recipients, $recipient); } public function setSubject($subject) { $this->subject = $subject; } public function setBody($body) { $this->body = $body; } public function sendEmail() { foreach ($this->recipients as $recipient) { $result = mail($recipient, $this->subject, $this->body, &quot;From: {$this->sender}&quot;); if ($result)  { echo &quot;Mail successfully sent to {$recipient}<br/>&quot;; } } } } ?>
Accessing Properties and Methods from Inside the Class ,[object Object],public function setBody($body) { $this->body = $body; } $this->setSubject(“Hello World!”);
Using an Object ,[object Object],<? $emailerobject = new Emailer(&quot;hasin@pageflakes.com&quot;); $emailerobject->addRecipients(&quot;hasin@somewherein.net&quot;); $emailerobject->setSubject(&quot;Just a Test&quot;); $emailerobject->setBody(&quot;Hi Hasin, How are you?&quot;); $emailerobject->sendEmail(); ?>
Modifiers ,[object Object]
Private ,[object Object],<? include_once(&quot;class.emailer.php&quot;); $emobject = new Emailer(&quot;hasin@somewherein.net&quot;); $emobject->subject = &quot;Hello world&quot;; ?>
Public ,[object Object]
Protected ,[object Object],[object Object]
Protected #2 ,[object Object],<? class ExtendedEmailer extends emailer { function __construct(){} public function setSender($sender) { $this->sender = $sender; } } ?>
Protected #3 ,[object Object],<? include_once(&quot;emailer.class.php&quot;); include_once(&quot;extendedemailer.class.php&quot;); $xemailer = new ExtendedEmailer(); $xemailer->setSender(&quot;hasin@pageflakes.com&quot;); $xemailer->addRecipients(&quot;hasin@somewherein.net&quot;); $xemailer->setSubject(&quot;Just a Test&quot;); $xemailer->setBody(&quot;Hi Hasin, How are you?&quot;); $xemailer->sendEmail(); ?>
Protected #4 ,[object Object],<? include_once(&quot;class.emailer.php&quot;); include_once(&quot;class.extendedemailer.php&quot;); $xemailer = new ExtendedEmailer(); $xemailer->sender = &quot;hasin@pageflakes.com&quot;; ?> Error !
Constructors and Destructors ,[object Object],[object Object],[object Object]
Constructors and Destructors #2 <? //factorial.class.php class factorial { private $result = 1;// you can initialize directly outside private $number; function __construct($number) { $this->number = $number; for($i=2; $i<=$number; $i++) { $this->result *= $i; } } public function showResult() { echo &quot;Factorial of {$this->number} is {$this->result}. &quot;; } } ?>
Constructors and Destructors #3 ,[object Object],[object Object],function __destruct() { echo &quot; Object Destroyed.&quot;; }
Class Constants ,[object Object],<? class WordCounter { //you need not use $ sign before Constants const ASC=1;  const DESC=2; private $words; function __construct($filename) { $file_content = file_get_contents($filename); $this->words = (array_count_values(str_word_count(strtolower ($file_content),1))); } public function count($order) { if ($order==self::ASC) asort($this->words); else if($order==self::DESC) arsort($this->words); foreach ($this->words as $key=>$val) echo $key .&quot; = &quot;. $val.&quot;<br/>&quot;; } } ?>
Class Constants#2 <? include_once(&quot;class.wordcounter.php&quot;); $wc = new WordCounter(&quot;words.txt&quot;); $wc->count(WordCounter::DESC); ?>
Extending a Class [Inheritance] ,[object Object],[object Object]
Extending a Class [Inheritance] #2 <? class HtmlEmailer extends emailer { public function sendHTMLEmail() { foreach ($this->recipients as $recipient) { $headers = 'MIME-Version: 1.0' . &quot;&quot;; $headers .= 'Content-type: text/html; charset=iso-8859-1' . &quot;&quot;; $headers .= 'From: {$this->sender}' . &quot;&quot;; $result = mail($recipient, $this->subject, $this->body, $headers); if ($result) echo &quot;HTML Mail successfully sent to {$recipient}<br/>&quot;; } } } ?>
Extending a Class [Inheritance] #3 <? include_once(&quot;class.htmlemailer.php&quot;); $hm = new HtmlEmailer(); //.... do other things $hm->sendEmail(); $hm->sendHTMLEmail(); ?>
Overriding Methods ,[object Object],[object Object]
Preventing from Overriding ,[object Object],<? class SuperClass { public final function someMethod() { //..something here } } class SubClass extends SuperClass { public function someMethod() { //..something here again, but it wont run } } ?>
Preventing from Extending ,[object Object],<? final class aclass { } class bclass extends aclass { } ?> Error !
Polymorphism ,[object Object],[object Object]
<? include(&quot;emailer.class.php&quot;); include(&quot;extendedemailer.class.php&quot;); include(&quot;htmlemailer.class.php&quot;); $emailer = new Emailer(&quot;hasin@somewherein.net&quot;); $extendedemailer = new ExtendedEmailer(); $htmlemailer = new HtmlEmailer(&quot;hasin@somewherein.net&quot;); if ($extendedemailer instanceof emailer ) echo &quot;Extended Emailer is Derived from Emailer.<br/>&quot;; if ($htmlemailer instanceof emailer ) echo &quot;HTML Emailer is also Derived from Emailer.<br/>&quot;; if ($emailer instanceof htmlEmailer ) echo &quot;Emailer is Derived from HTMLEmailer.<br/>&quot;; if ($htmlemailer instanceof extendedEmailer ) echo &quot;HTML Emailer is Derived from Emailer.<br/>&quot;; ?> Extended Emailer is Derived from Emailer. HTML Emailer is also Derived from Emailer. The output
Interface ,[object Object],[object Object],[object Object],[object Object]
Interface #2 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? //mysqldriver.class.php include(&quot;dbdriver.interface.php&quot;); class MySQLDriver implements DBDriver { } ?> implement Error !
Interface #2 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? include(&quot;interface.dbdriver.php&quot;); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute() { //execute the query and output result } } ?> implement Error ! The execute() does'nt have an argument
Interface #3 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? include(&quot;interface.dbdriver.php&quot;); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute() { //execute the query and output result } } ?> implement public function execute($query) { //execute the query and output result } Error ! The execute() does'nt have an argument Should have one argument
Abstract Class ,[object Object],[object Object],[object Object]
Abstract Class #2 <?php //reportgenerator.abstract.php abstract class ReportGenerator { public function generateReport($resultArray) { //write code to process the multidimensional result array and //generate HTML Report } } ?>
Abstract Class #3 <?php include(&quot;dbdriver.interface.php&quot;); include(&quot;reportgenerator.abstract.php&quot;); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } // You need not declare or write the generateReport method here //again as it is extended from the abstract class directly.&quot; } ?>
Abstract Method ,[object Object],[object Object],[object Object],.............................. abstract public function connectDB(); .............................
Static Method and Properties ,[object Object],[object Object]
Static Method and Properties #2 <?php //dbmanager.class.php class DBManager { public static function getMySQLDriver() { //instantiate a new MySQL Driver object and return } public static function getPostgreSQLDriver() { //instantiate a new PostgreSQL Driver object and return } public static function getSQLiteDriver() { //instantiate a new MySQL Driver object and return } } ?>
Static Method and Properties #2 ,[object Object],<?php //dbmanager.test.php include_once(&quot;dbmanager.class.php&quot;); $dbdriver = DBManager::getMySQLDriver(); //now process db operation with this $dbdriver object ?> ,[object Object]
How static property actually works ? <?php //statictester.class.php class StaticTester { private static $id=0; function __construct() { self::$id +=1; } public static function checkIdFromStaticMehod() { echo &quot;Current Id From Static Method is &quot;.self::$id.&quot;&quot;; } public function checkIdFromNonStaticMethod() { echo &quot;Current Id From Non Static Method is &quot;.self::$id.&quot;&quot;; } } $st1 = new StaticTester(); StaticTester::checkIdFromStaticMehod(); $st2 = new StaticTester(); $st1->checkIdFromNonStaticMethod(); //returns the val of $id as 2 $st1->checkIdFromStaticMehod(); $st2->checkIdFromNonStaticMethod(); $st3 = new StaticTester(); StaticTester::checkIdFromStaticMehod(); ?> Current Id From Static Method is 1 Current Id From Non Static Method is 2 Current Id From Static Method is 2 Current Id From Non Static Method is 2 Current Id From Static Method is 3 The Output :  Using this special facility,  a special design pattern  &quot;Singleton&quot; works perfectly in PHP.
Accesor Methods ,[object Object],[object Object],[object Object],[object Object]
Accesor Methods <?php class Student { private $name; private $roll; public function setName($name) { $this->name= $name; } public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?> But what happen if  we have lots of properties ? Do we have to create  accesor method for all the properties ? No ..! We can use magic method to achieve this...
Using Magic Method to Set/Get Class Properties ,[object Object],[object Object],[object Object],[object Object]
Using Magic Method to Set/Get Class Properties #2 <?php //student.class.php class Student { private $properties = array(); function __get($property) { return $this->properties[$property]; } function __set($property, $value) { $this->properties[$property]=&quot;AutoSet {$property} as: &quot;.$value; } } ?> <?php $st = new Student(); $st->name = &quot;Afif&quot;; $st->roll=16; echo $st->name.&quot;&quot;; echo $st->roll; ?> AutoSet name as: Afif AutoSet roll as: 16
Using Magic Method to Set/Get Class Properties #3 ,[object Object],[object Object],[object Object]
Magic Methods for Overloading  Class Methods <?php class Overloader { function __call($method, $arguments) { echo &quot;You called a method named {$method} with the following arguments <br/>&quot;; print_r($arguments); echo &quot;<br/>&quot;; } } $ol = new Overloader(); $ol->access(2,3,4); $ol->notAnyMethod(&quot;boo&quot;); ?> You called a method named access with the following arguments Array ( [0] => 2 [1] => 3 [2] => 4 ) You called a method named notAnyMethod with the following arguments Array ( [0] => boo )
Visually Representing Class
Summary ,[object Object],[object Object]
Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperNyros Technologies
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5Jason Austin
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpMichael Girouard
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
Oop in-php
Oop in-phpOop in-php
Oop in-phpRajesh S
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHPDavid Stockton
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOPfakhrul hasan
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentationMutinda Boniface
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHPRamasubbu .P
 
Python: Basic Inheritance
Python: Basic InheritancePython: Basic Inheritance
Python: Basic InheritanceDamian T. Gordon
 
Task 2
Task 2Task 2
Task 2EdiPHP
 
De constructed-module
De constructed-moduleDe constructed-module
De constructed-moduleJames Cowie
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and GithubJo Erik San Jose
 

Was ist angesagt? (20)

PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Oops in php
Oops in phpOops in php
Oops in php
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Class and Objects in PHP
Class and Objects in PHPClass and Objects in PHP
Class and Objects in PHP
 
Python: Basic Inheritance
Python: Basic InheritancePython: Basic Inheritance
Python: Basic Inheritance
 
Task 2
Task 2Task 2
Task 2
 
De constructed-module
De constructed-moduleDe constructed-module
De constructed-module
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
 

Ă„hnlich wie Object Oriented Programming With PHP 5 #2

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxAtikur Rahman
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Stephan Schmidt
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Phpsanjay joshi
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHPRohan Sharma
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Chris Tankersley
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Alena Holligan
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
 
Perl Teach-In (part 2)
Perl Teach-In (part 2)Perl Teach-In (part 2)
Perl Teach-In (part 2)Dave Cross
 
Dependency Injection for PHP
Dependency Injection for PHPDependency Injection for PHP
Dependency Injection for PHPmtoppa
 
OOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsOOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsChris Tankersley
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 

Ă„hnlich wie Object Oriented Programming With PHP 5 #2 (20)

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptx
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
09 Oo Php Register
09 Oo Php Register09 Oo Php Register
09 Oo Php Register
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index12-security.ppt - PHP and Arabic Language - Index
12-security.ppt - PHP and Arabic Language - Index
 
Security.ppt
Security.pptSecurity.ppt
Security.ppt
 
Perl Teach-In (part 2)
Perl Teach-In (part 2)Perl Teach-In (part 2)
Perl Teach-In (part 2)
 
Dependency Injection for PHP
Dependency Injection for PHPDependency Injection for PHP
Dependency Injection for PHP
 
OOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsOOP Is More Than Cars and Dogs
OOP Is More Than Cars and Dogs
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 

Mehr von Wildan Maulana

Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018Wildan Maulana
 
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Wildan Maulana
 
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam MelonKetahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam MelonWildan Maulana
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Wildan Maulana
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipWildan Maulana
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWWildan Maulana
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...Wildan Maulana
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsWildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...Wildan Maulana
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpWildan Maulana
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity ProviderWildan Maulana
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Wildan Maulana
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpWildan Maulana
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationWildan Maulana
 
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...Wildan Maulana
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarWildan Maulana
 
Statistik Listrik
Statistik ListrikStatistik Listrik
Statistik ListrikWildan Maulana
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesWildan Maulana
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaWildan Maulana
 
Menggunakan AlisJK : Equating
Menggunakan AlisJK : EquatingMenggunakan AlisJK : Equating
Menggunakan AlisJK : EquatingWildan Maulana
 

Mehr von Wildan Maulana (20)

Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018Hasil Pendataan Potensi Desa 2018
Hasil Pendataan Potensi Desa 2018
 
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
Double for Nothing? Experimental Evidence on an Unconditional TeacherSalary I...
 
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam MelonKetahanan Pangan #1 : Gerakan Sekolah Menanam Melon
Ketahanan Pangan #1 : Gerakan Sekolah Menanam Melon
 
Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014Pengembangan OpenThink SAS 2013-2014
Pengembangan OpenThink SAS 2013-2014
 
ICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi ArsipICA – AtoM : Retensi Arsip
ICA – AtoM : Retensi Arsip
 
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RWOpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
OpenThink Labs Workshop : Ketahanan Pangan Skala RT/RW
 
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
OpenThink Labs : Dengar Pendapat Komunitas ciliwung dengan kemen pu dan kemen...
 
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyToolsPostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
PostgreSQL BootCamp : Manajemen Master Data dengan SkyTools
 
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...Mensetup Google Apps sebagai IdP jenis openID  dan Aplikasi Berbasis CakePHP ...
Mensetup Google Apps sebagai IdP jenis openID dan Aplikasi Berbasis CakePHP ...
 
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai SpMensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
Mensetup Google Apps sebagai IdP jenis openID dan Wordpress sebagai Sp
 
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity ProviderKonfigurasi simpleSAMLphp  dengan Google Apps Sebagai Identity Provider
Konfigurasi simpleSAMLphp dengan Google Apps Sebagai Identity Provider
 
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
Instalasi simpleSAMLphp sebagai Identity Provider (IdP)
 
Instalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphpInstalasi dan Konfigurasi simpleSAMLphp
Instalasi dan Konfigurasi simpleSAMLphp
 
River Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River RestorationRiver Restoration in Asia and Connection Between IWRM and River Restoration
River Restoration in Asia and Connection Between IWRM and River Restoration
 
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...Optimasi Limpasan Air Limbah  Ke Kali Surabaya (Segmen Sepanjang – Jagir)  De...
Optimasi Limpasan Air Limbah Ke Kali Surabaya (Segmen Sepanjang – Jagir) De...
 
Penilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan DasarPenilaian Siswa di Finlandia - Pendidikan Dasar
Penilaian Siswa di Finlandia - Pendidikan Dasar
 
Statistik Listrik
Statistik ListrikStatistik Listrik
Statistik Listrik
 
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and UsesProyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
Proyek Al-'Alaq : Electric Bicycles ; History, Characteristics, and Uses
 
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang TuaOpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
OpenThink SAS : Interaksi Antara Sekolah, Wali Kelas, Siswa dan Orang Tua
 
Menggunakan AlisJK : Equating
Menggunakan AlisJK : EquatingMenggunakan AlisJK : Equating
Menggunakan AlisJK : Equating
 

KĂĽrzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

KĂĽrzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Object Oriented Programming With PHP 5 #2

  • 1. Wildan Maulana | wildan [at] tobethink.com Object Oriented Programming with PHP 5 #2
  • 2.
  • 3. Let's Bake Some Objects <? //emailer.class..php class Emailer { private $sender; private $recipients; private $subject; private $body; function __construct($sender) { $this->sender = $sender; $this->recipients = array(); } public function addRecipients($recipient) { array_push($this->recipients, $recipient); } public function setSubject($subject) { $this->subject = $subject; } public function setBody($body) { $this->body = $body; } public function sendEmail() { foreach ($this->recipients as $recipient) { $result = mail($recipient, $this->subject, $this->body, &quot;From: {$this->sender}&quot;); if ($result) { echo &quot;Mail successfully sent to {$recipient}<br/>&quot;; } } } } ?>
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Constructors and Destructors #2 <? //factorial.class.php class factorial { private $result = 1;// you can initialize directly outside private $number; function __construct($number) { $this->number = $number; for($i=2; $i<=$number; $i++) { $this->result *= $i; } } public function showResult() { echo &quot;Factorial of {$this->number} is {$this->result}. &quot;; } } ?>
  • 15.
  • 16.
  • 17. Class Constants#2 <? include_once(&quot;class.wordcounter.php&quot;); $wc = new WordCounter(&quot;words.txt&quot;); $wc->count(WordCounter::DESC); ?>
  • 18.
  • 19. Extending a Class [Inheritance] #2 <? class HtmlEmailer extends emailer { public function sendHTMLEmail() { foreach ($this->recipients as $recipient) { $headers = 'MIME-Version: 1.0' . &quot;&quot;; $headers .= 'Content-type: text/html; charset=iso-8859-1' . &quot;&quot;; $headers .= 'From: {$this->sender}' . &quot;&quot;; $result = mail($recipient, $this->subject, $this->body, $headers); if ($result) echo &quot;HTML Mail successfully sent to {$recipient}<br/>&quot;; } } } ?>
  • 20. Extending a Class [Inheritance] #3 <? include_once(&quot;class.htmlemailer.php&quot;); $hm = new HtmlEmailer(); //.... do other things $hm->sendEmail(); $hm->sendHTMLEmail(); ?>
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. <? include(&quot;emailer.class.php&quot;); include(&quot;extendedemailer.class.php&quot;); include(&quot;htmlemailer.class.php&quot;); $emailer = new Emailer(&quot;hasin@somewherein.net&quot;); $extendedemailer = new ExtendedEmailer(); $htmlemailer = new HtmlEmailer(&quot;hasin@somewherein.net&quot;); if ($extendedemailer instanceof emailer ) echo &quot;Extended Emailer is Derived from Emailer.<br/>&quot;; if ($htmlemailer instanceof emailer ) echo &quot;HTML Emailer is also Derived from Emailer.<br/>&quot;; if ($emailer instanceof htmlEmailer ) echo &quot;Emailer is Derived from HTMLEmailer.<br/>&quot;; if ($htmlemailer instanceof extendedEmailer ) echo &quot;HTML Emailer is Derived from Emailer.<br/>&quot;; ?> Extended Emailer is Derived from Emailer. HTML Emailer is also Derived from Emailer. The output
  • 26.
  • 27. Interface #2 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? //mysqldriver.class.php include(&quot;dbdriver.interface.php&quot;); class MySQLDriver implements DBDriver { } ?> implement Error !
  • 28. Interface #2 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? include(&quot;interface.dbdriver.php&quot;); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute() { //execute the query and output result } } ?> implement Error ! The execute() does'nt have an argument
  • 29. Interface #3 <? //dbdriver.interface.php interface DBDriver { public function connect(); public function execute($sql); } ?> <? include(&quot;interface.dbdriver.php&quot;); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute() { //execute the query and output result } } ?> implement public function execute($query) { //execute the query and output result } Error ! The execute() does'nt have an argument Should have one argument
  • 30.
  • 31. Abstract Class #2 <?php //reportgenerator.abstract.php abstract class ReportGenerator { public function generateReport($resultArray) { //write code to process the multidimensional result array and //generate HTML Report } } ?>
  • 32. Abstract Class #3 <?php include(&quot;dbdriver.interface.php&quot;); include(&quot;reportgenerator.abstract.php&quot;); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } // You need not declare or write the generateReport method here //again as it is extended from the abstract class directly.&quot; } ?>
  • 33.
  • 34.
  • 35. Static Method and Properties #2 <?php //dbmanager.class.php class DBManager { public static function getMySQLDriver() { //instantiate a new MySQL Driver object and return } public static function getPostgreSQLDriver() { //instantiate a new PostgreSQL Driver object and return } public static function getSQLiteDriver() { //instantiate a new MySQL Driver object and return } } ?>
  • 36.
  • 37. How static property actually works ? <?php //statictester.class.php class StaticTester { private static $id=0; function __construct() { self::$id +=1; } public static function checkIdFromStaticMehod() { echo &quot;Current Id From Static Method is &quot;.self::$id.&quot;&quot;; } public function checkIdFromNonStaticMethod() { echo &quot;Current Id From Non Static Method is &quot;.self::$id.&quot;&quot;; } } $st1 = new StaticTester(); StaticTester::checkIdFromStaticMehod(); $st2 = new StaticTester(); $st1->checkIdFromNonStaticMethod(); //returns the val of $id as 2 $st1->checkIdFromStaticMehod(); $st2->checkIdFromNonStaticMethod(); $st3 = new StaticTester(); StaticTester::checkIdFromStaticMehod(); ?> Current Id From Static Method is 1 Current Id From Non Static Method is 2 Current Id From Static Method is 2 Current Id From Non Static Method is 2 Current Id From Static Method is 3 The Output : Using this special facility, a special design pattern &quot;Singleton&quot; works perfectly in PHP.
  • 38.
  • 39. Accesor Methods <?php class Student { private $name; private $roll; public function setName($name) { $this->name= $name; } public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?> But what happen if we have lots of properties ? Do we have to create accesor method for all the properties ? No ..! We can use magic method to achieve this...
  • 40.
  • 41. Using Magic Method to Set/Get Class Properties #2 <?php //student.class.php class Student { private $properties = array(); function __get($property) { return $this->properties[$property]; } function __set($property, $value) { $this->properties[$property]=&quot;AutoSet {$property} as: &quot;.$value; } } ?> <?php $st = new Student(); $st->name = &quot;Afif&quot;; $st->roll=16; echo $st->name.&quot;&quot;; echo $st->roll; ?> AutoSet name as: Afif AutoSet roll as: 16
  • 42.
  • 43. Magic Methods for Overloading Class Methods <?php class Overloader { function __call($method, $arguments) { echo &quot;You called a method named {$method} with the following arguments <br/>&quot;; print_r($arguments); echo &quot;<br/>&quot;; } } $ol = new Overloader(); $ol->access(2,3,4); $ol->notAnyMethod(&quot;boo&quot;); ?> You called a method named access with the following arguments Array ( [0] => 2 [1] => 3 [2] => 4 ) You called a method named notAnyMethod with the following arguments Array ( [0] => boo )
  • 45.
  • 46. Q&A