apress pro php and jquery 2010 phần 4

Điều này dẫn đến mã ngắn gọn rõ ràng, đó là dễ dàng để làm theo: $ ('p') addClass (mới cấp) văn bản ("Tôi là một đoạn!") AppendTo ('cơ thể'), Chainable phương pháp. là có thể | CHAPTER 3 OBJECT-ORIENTED PROGRAMMING Create a new object newobj new MyOtherClass Attempt to call a protected method echo newobj- getProperty Upon attempting to run this script the following error shows up The class MyClass was initiated A new constructor in MyOtherClass. Fatal error Call to protected method MyClass getProperty from context in Applications XAMPP xamppfiles htdocs testing on line 55 Now create a new method in MyOtherClass to call the getProperty method 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 105 CHAPTER 3 OBJECT-ORIENTED PROGRAMMING this- prop1 newval protected function getProperty . return this- prop1 . br class MyOtherClass extends MyClass . public function construct parent __construct echo A new constructor in . _CLASS__ . . br public function newMethod echo From a new method in . CLASS . . br public function callProtected return this- getProperty Create a new object newobj new MyOtherClass Call the protected method from within a public method echo newobj- callProtected This generates the desired result The class MyClass was initiated A new constructor in MyOtherClass. I m a class property The class MyClass was destroyed. 106 CHAPTER 3 OBJECT-ORIENTED PROGRAMMING Private Properties and Methods A property or method declared private is accessible only from within the class that defines it. This means that even if a new class extends the class that defines a private property that property or method will not be available at all within the child class. To demonstrate this declare getProperty as private in MyClass and attempt to call callProtected from MyOtherClass php class MyClass . public prop1 I m a class property public function __construct echo The class .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.