TAILIEUCHUNG - OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P5

OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P5: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. | function indexOrder sort this- filearray function naturalCaseInsensitiveOrder natcasesort this- filearray function getCount return count this- filearray Listing 4-2 Wrapper methods Finally add one final method to check that files are all images function checkAllImages bln true extension types array O jpg jpeg gif png foreach this- filearray as key value extension substr value strpos value . 1 extension strtolower extension if in_array extension types bln false break return bln Listing 4-3 A method to select only images The checkAllImages method loops through each element in the file array extracts the extension and checks that it is one of O the acceptable file types. In sum the Directoryitems class is made up of one data member a special function called a constructor and four other functions or methods. As already noted you should save this file as . Creating an Instance A class by itself is of absolutely no use whatsoever and if you preview in a browser the code created so far nothing will be displayed. That s because at this point we don t really have anything -just the idea for something. We need to create an instance of the class. The many Platonists amongst you will immediately know what we re talking about. Remember Plato and ideal forms Of course you do it hasn t been that long since you took Philosophy 101. The explanation of a form usually involved a chair because there was always one in the classroom. The form of a chair doesn t exist anywhere but any specific chair embodies Show a Little Class 21 that form. In other words each particular chair is an instantiation of the chair class. If you skipped that lecture we could say that a class acts as a template for a specific occurrence of a class in much the way that a building relates to its blueprint. Listing 4-4 is a PHP page that creates an instance of the Directoryitems class. Briefly this web page opens a directory immediately below the current working directory checks that all the .

4    5    0    12-08-2020
139    3    0    12-08-2020
19    16    0
182    15    0
138    6    0
3    7    0
142    12    0