24/05/2021 Lập trình web nâng cao 1
Giới thiệu
01
Các vấn đề cơ bản hướng đối tượng trong
02
03
04
Chương 4Lập trình hướng đối tượng
05
24/05/2021 Lập trình web nâng cao 2
Lớp abstract và lớp interfaces
03
01
02
04
Giới thiệu
05
24/05/2021 Lập trình web nâng cao 3
OOP (Object Orient Programming) revolves around the concept of grouping code and
data together in logical units called classes. This process is usually referred to as
encapsulation,or information hiding, since its goal is that of dividing an application
into separate entities whose internal components can change without altering their
external interfaces. (ref: page 132 of ebook “phparchitects Zend PHP 5
Certification Study Guide”)
Programming techniques may include features such as
abstraction, encapsulation, polymorphism, and inheritance.
02
04
Các vấn đề bản OOP trong PHP
05
24/05/2021 Lập trình web nâng cao 4
1. Declaring a Class
Cú pháp khai báo lớp:
dụ:
class <Tên_lớp>{
// Your code is here
}
class foo {
const BAR = "Hello World";
}
echo foo::BAR;
02
04
Các vấn đề bản
OOP trong PHP
05
24/05/2021 Lập tnh web nâng cao 5
1. Declaring a Class
Cú pháp khai báo lớp kế thừa:
Cú pháp xác định lớp đối tượng:
class a {
function test(){ echo "a::test called";}
function func(){echo "a::func called";}
}
class b extends a {
function test(){echo "b::test called";}
}
class c extends b {
function test(){parent::test();}
}
class d extends c {
function test(){b::test();}
}
if ($obj instanceof MyClass) {
echo "\$obj is an instance of MyClass";
}