PHP and MySQL Web Development - P38

PHP and MySQL Web Development - P38: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 152 Chapter 6 Object-Oriented PHP function operation2 param1 param2 and create a object of type classname called a as follows a new classname We then call operations the same way that we call other functions by using their name and placing any parameters that they need in brackets. Because these operations belong to an object rather than normal functions we need to specify to which object they object name is used in the same way as an object s attributes as follows a- operation1 a- operation2 12 test If our operations return something we can capture that return data as follows x a- operation1 y a- operation2 12 test Implementing Inheritance in PHP If our class is to be a subclass of another you can use the extends keyword to specify this. The following code creates a class named B that inherits from some previously defined class named A. class B extends A var attribute2 function operation2 If the class A was declared as follows class A var attribute1 function operation1 all the following accesses to operations and attributes of an object of type B would be valid Implementing Inheritance in PHP 153 b new B b- operation1 b- attribute1 10 b- operation2 b- attribute2 10 Note that because class B extends class A we can refer to operation1 and attrib-ute1 although these were declared in class a subclass of A B has all the same functionality and data. In addition B has declared an attribute and an operation of its own. It is important to note that inheritance only works in one direction. The subclass or child inherits features from its parent or superclass but the parent does not take on features of the child. This means that the last two lines in this code are wrong a new A a- operation1 a- attribute1 10 a- operation2 a- attribute2 10 The class A does not have an operation2 or an attribute2. Overriding We have shown a subclass declaring new attributes and operations. It is also valid and sometimes useful to redeclare the same attributes and operations. We

Không thể tạo bản xem trước, hãy bấm tải xuống
88    28    2    28-03-2023
5    20    1    28-03-2023
38    9    1    28-03-2023
Đã 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.