Tương tác giữa PHP và jQuery - part 11

Phương pháp bảo quản Chức năng gốc Trong khi phương pháp ghi đè Để thêm chức năng mới cho một phương pháp di truyền trong khi vẫn giữ phương pháp ban đầu nguyên vẹn, sử dụng từ khoá cha mẹ | CHAPTER 3 OBJECT-ORIENTED PROGRAMMING return this- getProperty public function setProperty newval this- prop1 newval public function getProperty return this- prop1 . br class MyOtherClass extends MyClass public function construct echo A new constructor in . CLASS__ . . br public function newMethod echo From a new method in . CLASS__ . . br Create a new object newobj new MyOtherClass Output the object as a string echo newobj- newMethod Use a method from the parent class echo newobj- getProperty This changes the output in the browser to A new constructor in MyOtherClass. From a new method in MyOtherClass. I m a class property The class MyClass was destroyed. 101 CHAPTER 3 OBJECT-ORIENTED PROGRAMMING Preserving Original Method Functionality While Overwriting Methods To add new functionality to an inherited method while keeping the original method intact use the parent keyword with the scope resolution operator php class MyClass public prop1 I m a class property public function construct echo The class CLASS__ was initiated br public function destruct echo The class CLASS__ was destroyed. br public function toString echo Using the toString method return this- getProperty public function setProperty newval this- prop1 newval public function getProperty return this- prop1 . br class MyOtherClass extends MyClass public function construct parent __construct Call the parent class s constructor echo A new constructor in . CLASS__ . . br public function newMethod echo From a new method in . CLASS__ . . br 102 CHAPTER 3 OBJECT-ORIENTED PROGRAMMING Create a new object newobj new MyOtherClass Output the object as a string echo newobj- newMethod Use a method from the parent class echo newobj- getProperty This outputs the result of both the parent constructor and the new class s constructor The class MyClass was initiated A new constructor in MyOtherClass. From a new method in MyOtherClass. I m a class property The class MyClass was destroyed. .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
207    559    4    18-05-2024
10    476    2    18-05-2024
Đã 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.