tailieunhanh - The php anthology 2nd edition 2007 - phần 2

Chú ý rằng khi chúng ta sử dụng một phương pháp tĩnh, chúng tôi sử dụng:: nhà điều hành, chứ không phải là đối tượng - nhà điều hành, để truy cập các phương pháp | 32 The PHP Anthology Simpo PDF Merge and Split Unregistered Version - http php require_once class HTML public static function p content attributes array return new HTMLParagraph content attributes Here s an example of how the HTML class could be used echo HTML p This is a static method This example would output as follows p This is a static method p Notice that when we use a static method we use the operator rather than the object - operator to access the method. You may have noticed that this is the same operator used to call a method of the parent class of the current object as in parent method . The parent class usage is a special case where inheritance is concerned as the parent class method retains access to the object s instance data and therefore isn t static. this Can t be Used in Static Methods As static methods are used without the instantiation of an object the this variable can t be used in static methods. Now to extend this example a bit and possibly to excite your interest in OOP in PHP 5 into the bargain imagine for a moment that we ve added a static method and a corresponding class for each possible HTML element to our HTML class. Remembering that one HTMLElement object can be passed to the constructor of another HTMLElement object as its content we can now create methods for all HTML elements that we can use as demonstrated in the following example Introduction 33 Simpo PDF Merge and Split Unregistered Version - http echo HTML div HTML h1 Welcome to my web site array id header This example would output the following HTML div id header h1 Welcome to my web site h1 div Taking the above example as your goal I ll leave the implementation of such an API up to you. Come on with this introduction to OOP under your belt it should be easy How do I write portable PHP code Not all PHP installations are the same. Depending on version and configuration settings in your file your .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
crossorigin="anonymous">
Đã 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.