• Tidak ada hasil yang ditemukan

PHP OOP

N/A
N/A
Protected

Academic year: 2024

Membagikan "PHP OOP"

Copied!
9
0
0

Teks penuh

(1)

PHP OOP

Wichan Thumthong

(2)

PHP OOP

class objects properties

method

magic method inheritance

override

(3)

PHP OOP

<?php

class Simple{

public $hello = “Hello World”;

}

$obj = new Simple;

echo $obj ->hello;

?>

CLASS

OBJECT

PROPERTIES

(4)

<?php

class Simple{

public $hello = “Hello World”;

function setHello($val){

$this->hello = $val;

}

function getHello(){

return $this->hello;

} }

?>

METHOD

(5)

<?php

class Simple{

public $hello = “Hello World”;

function setHello($val){

$this->hello = $val;

}

function getHello(){

return $this->hello;

} }

$obj = new Simple;

echo $obj->hello.’<br>’;

$boj->setHello(‘Hello New World’);

echo $obj->getHello();

?>

OBJECTS METHOD

(6)

PHP OOP

<?php

class FirstClass{

public $name = "WichanT";

public function sayhi(){

echo "Hi ".$this->name." ".$this->saybye();

}

public function saybye(){

return " Bye";

} }

$obj= new FirstClass;

$obj->name="OTHER";

$obj->sayhi();

echo $obj->saybye();

?>

(7)

MAGIC METHOD

<?php

class Simple{

public $hello = “Hello World”;

function __construct(){

echo “Before”;

}

function __destruct(){

echo “After”;

} }

?>

(8)

INHERITANCE

<?php

include “simple.class.php”;

class Test extends Simple{

}

$obj = new Test;

echo $obj->hello.’<br>’;

$boj->setHello(‘Hello New World’);

echo $obj->getHello();

?>

(9)

OVERRIDE

<?php

include “simple.class.php”;

class Test extends Simple{

public function setHello($val){

$this->hello = “Hello ”.$val;

}

public function getHello(){

return $this->hello.” Are you OK?”;

} }

$obj = new Test;

echo $obj->hello.’<br>’;

$boj->setHello(‘WichanT’);

echo $obj->getHello();

?>

Referensi

Dokumen terkait

 Class merupakan blueprint yang dapat. menggambarkan setiap

Sebenarnya pada contoh diatas, kita bisa saja hanya memberikan alias hanya pada tiga class saja sudah cukup, namun agar tidak timbul kebingungan, akan lebih baik jika kita

Nerd Note : the 'person' class is called (by nerds,) the 'base' class or the 'parent' class because it's the class that the 'employee' is based on!. This class hierarchy can

Object Class Instance of • Class name • Attribute • method terdiri dari Menentukan data yang dapat disimpan dan apa yang bisa

With inheritance, you need to consider type casting, base class functionality, and how to override or overload methods or properties. ( Type casting is when you cast to a

Untuk menggambarkan inheritance atau pewarisan di dalam pemro- graman, pada saat Anda menggunakan kembali atau mengganti method dari class yang sudah ada, serta ketika

OO Object Oriented Suatu paradigma yang menggunakan objek dengan identitas yang membungkus propertis dan operasi, melewatkan pesan, dan inheritance untuk menyelesaikan domain

The document provides 15 multiple-choice questions at the university level about C++ and object-oriented programming