tailieunhanh - OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P6

OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P6:A number of years ago, before I started using PHP, I created dynamic web pages using C. This really wasn’t too different from some of the other options available at the time, though it seems almost unthinkable now. Creating a dynamic page meant outputting HTML from your script and recompiling that script if any changes needed to be made. | To briefly return to our earlier discussion of access modifiers another way of describing the difference between public and private access as far as methods are concerned is to say that they separate the interface from the implementation. A user programmer need only concern himself with the public methods of a class in order to use it efficiently. In other words he need not worry about private functions because they represent the inner workings of a class s implementation. For this reason you can say that the separation of public and private methods simplifies the use of a class. In the original version of the constructor presented in Chapter 4 you assigned each filename to an array element effectively creating a numeric array. In the revised constructor however you have created an associative array with the filename functioning as the key and the title as the value. As noted earlier you can t have files in the same directory with duplicate names so the filename can function as a unique key. Filtering Content To this point you have changed the Directoryitems class to take advantage of changes to the syntax of PHP namely by using access modifiers and the magic constructor. You ve also changed the internal workings of the constructor in order to create a title. All that remains is to create the methods that relate to filtering the contents of a directory. However there s no point in filtering if you don t have to a directory may already contain only the file type you are interested in. Hence you need a method to loop through all files and determine whether they are the same type. Listing 5-2 contains this method. public function checkAllSpecificType 0 extension extension strtolower extension bln true ext foreach this- filearray as key value ext substr key strpos key . 1 ext strtolower ext if extension ext bln false break return bln Listing 5-2 The checkAllSpecificType method Listing 5-2 is a simple modification of the method developed in Chapter 4 checkAllImages. You

TỪ KHÓA LIÊN QUAN
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.