TAILIEUCHUNG - ICT 5 Web Development - Chapter 5: OOP in PHP

ICT 5 Web Development - Chapter 5: OOP in PHP Creating an Object, Accessing attributes and methods, Building a classing, Introspection, Syntax to declare a Class, Autoloading class. | Vietnam and Japan Joint ICT HRD Program ObjectObject-Oriented Programming (OOP) Object: Object: Instance (occurrance) of a class Classes/Objects encapsulates th i d t Cl /Obj t l t their data (called attributes) and behaviour (called attributes) methods) methods) Inheritance: Define Inheritance: Define a new class by saying that it's like an existing class, but with certain new or changed attributes and methods. ICT 5 Web Development Chapter 5. OOP in PHP Nguyen Thi Thu Trang – The old class: superclass/parent/base class class: superclass/parent/ – The new class: subclass/child/derived class The class: subclass/child/derived trangntt@ 2 PHP 5 Content Single-inheritance ingleAccess-restricted ccessOverloadable Object ~ pass-by-reference pass-by- 1. Creating an Object 2. Accessing attributes and methods 3. Building a class Building 4. Introspection 3 4 1 1. Creating an Object Content 1. Creating an Object 2. Accessing attributes and methods 3. Building a class Building 4. Introspection Syntax: – $object = new Class([agrs]); Class([agrs]); .: – $obj1= new User(); User(); – $obj2 = new User('Fred', "abc123"); //args – $obj3 = new ‘User'; // does not work – $class = ‘User'; $obj4 new $class; //ok User ; $obj4= User + name - password - lastLogin + getLastLogin() + setPassword(pass) 5 2. Accessing Attributes and Methods 6 Content 1. Creating an Object 2. Accessing attributes and methods 3. Building a class Building 4. Introspection Syntax: Using -> – $object->attribute name $object- attribute_ attribute_name – $object->method_name([arg, . ]) $object- method_name([arg, ]) . // attribute access $obj1$obj1->name = “Micheal"; print("User name is " . $obj1->name); $obj1$obj1$obj1->getLastLogin( ); // method call // method call with args $obj1$obj1->setPassword("Test4"); 7 8 2 Rules for PHP Identifiers . Syntax to declare a Class class ClassName [extends BaseClass]{ lassN aseClass]{ [[var] access $attribute [ = value ]; .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.