tailieunhanh - Zend PHP Certification Study Guide- P4
Zend PHP Certification Study Guide- P4: Hãy thẳng thừng, Giả sử bạn đang thuê một ai đó để giám sát hệ thống và PHP của bạn có nó thu hẹp xuống để hai ứng cử viên. Một trong những ứng cử viên nói, "Oh yeah, tôi biết tất cả về PHP." Các ứng cử viên khác nói, "Oh yeah, tôi biết tất cả về PHP, tôi đã được thông qua kỳ thi chứng chỉ Zend." câu hỏi tiếp theo của bạn có thể sẽ là "Zend Chứng nhận là gì?" Và các ứng viên nói, "Một công ty chuyên về. | 44 Chapter 2 Object-Oriented PHP The great advantage of inheritance is that it provides a simple mechanism for extending the capabilities of your code in a gradual way without having to rewrite loads of code every time. Magic Functions Serializing Objects You might sometimes want objects to be passed along between different calls to your scripts for example from one page to the next. One way to do so is to use a process known as serialization in which the contents of the object are saved and then the object is re-created by reversing the process. In PHP this can be performed automatically by PHP by simply saving all the object s properties and then storing them back in the object when it is rebuilt. In some cases however this is not what you might want. For example one of your properties could be a file resource in which case you would have to close the file when the object is serialized and then open it again when it is unserialized. In these instances PHP can t do the job for you but you can implement two magic functions to do whatever you need on an ad hoc basis php class base_class var var1 var var2 function base_class value this- var1 value this- var2 value 100 function calc_pow exp return pow var1 exp function __sleep Return an array that contains the name of all the variables to be saved return array var1 function wakeup Exam Prep Questions 45 Reconstruct var2 this- var2 this- var1 100 As you can see thesleep function is called whenever an object is serialized. It returns an array that contains the names minus the dollar sign of all the data members that must be saved. In our case base_class var2 is actually derived directly from the value of base_class var1 so we don t want to save the object is unserialized the interpreter will call_wakeup in which we take the opportunity to rebuild var2 with the appropriate value. Exam Prep Questions 1. What will the following script output php class a var c function a pass this- c pass function print_data .
đang nạp các trang xem trước