TAILIEUCHUNG - PHP 5 Recipes A Problem-Solution Approach PHẦN 6

lớp Parrot mở rộng Bird {công chức năng birdCall () {printf ("% s cho biết: squawk * \ n", $ this- getName ());} Bạn cũng có thể ghi đè lên lớp Bird xây dựng . Trong trường hợp này, những gì bạn làm là gọi của cha mẹ | 318 7-15 USING THE SPL DIRECTORYITERATOR OBJECT The Code php Create a new instance of a recursivedirectoryiterator. di new RecursiveDirectoryIterator sample4 function dirrecurse di Cycle through the directory. for di- valid di- next Ensure that you have a directory and exclude the dots. if di- isDir di- isDot Output the directories in bold. span style font-weight bold php echo di- current span php div style margin-left 10px php Check if the current directory has any children. if di- hasChildren And if so run the function again. dirrecurse di- getChildren div php Else if you have a file. elseif di- isFile Then echo the file. echo di- current . br Run the recursion. dirrecurse di How It Works If this code runs correctly you should see the same result as you did in recipe 7-14. This code however is much smoother and abides much better by object-oriented guidelines. Our favorite part of this code is how the object can check in advance for any children. If a child entity exists and keep in mind it checks against the dots as well then it can perform its duty. All in all we prefer the iterator means of handling directories and look forward to what the PHP developers will come up with next. 7-15 USING THE SPL DIRECTORYITERATOR OBJECT 319 Summary As it is PHP 5 has no trouble in the slightest when it comes to dealing with files and directories. As the software continues to improve and more features are added it may be time to begin porting your code to the much more flexible object-oriented SPL. As you saw the SPL can quickly and efficiently take care of any directory issues you may have. In the meantime however you can put the regular PHP means of dealing with files and directories to good use by writing your own classes and then extending them. The functionality involved is quite robust and should enable a solution no matter what the problem entails. It is important to remember to exception handle any potential trouble spots. When dealing with files .

Đã 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.