PHP Scripts What is PEAR in PHP
|Discussed version: 1.0.0RC3||License: PHP license 2.02|
|Class file (s): PHP / CompatInfo.php; PHP / CompatInfo / Cli.php|
The packages PHP_CompatInfo and PHP_Compat are based on a very nice idea. These packages try to prevent problems that can occur when PHP scripts are not compatible with the PHP version that is used on a server.
PHP_CompatInfo is able to analyze a script and determine which PHP version is required to execute the script.
The package can analyze data from a string, a file or from several files (i.e. a subdirectory).
Listing 10.2 Analyzing a File
The data determined in Listing 10.2 are stored in $ erg in the form of an array. The structure could look like this, for example:
The version key points to the minimum version of PHP required to run the code. The extensions key points to an array that contains information about which extensions must be available in order for the code to run. In this case, mysql appears several times because there are several mysql commands in the parsed file. In the case of longer programs, it makes sense at this point to process the array with array_unique () in order to avoid duplicate entries.
The last key, constants, contains an indexed array in which all system constants used by the script are listed.
If you don't want to parse a file but a string, parseString () is available. As a second parameter, you can transfer an array to the method that supports the key 'ignore_functions'. This can refer to an indexed array of function names that should be ignored during analysis.
In order to search through several strings or arrays at once, the parseArray () method is declared, which is passed an array with the file names or strings. If it is an array that consists of strings, you have to pass an array as the second parameter. This array must contain the key 'is_string', which must contain true. In addition, 'ignore_functions' is also supported.
The last way to parse files is to parseDir (). It is given the path of a directory in which all files are viewed. This method can also process a second parameter in the form of an array. In addition to 'ignore_functions', this array also supports the keys 'file_ext', 'recurse_dir', 'ignore_files' and 'ignore_dirs'. The first allows you to pass an array of filename extensions to specify the files to collect. In the standard setting, files with the extensions .php, .php4, .inc and .phtml are recorded. If you pass false with 'recurse_dir', subdirectories are not searched, which is done by default. The last two keys can each refer to an array in which you can pass the names of files or directories that should be ignored.
Just like parseArray (), this method returns a somewhat larger array. Here the beginning of the array is structured as described above. This first part describes the lowest common denominator that all files need. This is followed by an additional entry for each file containing a nested array that contains the specifications for this individual file.
The methods described are also contained in the PHP_CompatInfo_Cli class, which is defined in the PHP / CompatInfo / Cli.php file. The purpose of this class is to provide the simplest possible interface for using the class on the command line. On the one hand, the methods already described are available here. The constructor also processes command line options directly. Such a script can look like Listing 10.3.
Listing 10.3 Analyzing a Script Using the Command Line
The name of the file to be analyzed can be passed with --file = filename or -f. With --dir = directory or -d you can specify a directory that contains the files you want, and with --recurse or -n you can prevent subordinate directories from being searched. The method run (), which was used here, generates a screen output directly.
- Difference between multiple alleles and a deadly gene.
- Is the birth certificate sufficient for the place of residence
- Why is multitasking bad
- Where is the department office in Patna?
- Why can't species cross
- Is induction motor and motor the same
- Sweat well for a cold
- Everyone has a twin somewhere
- Which is better Eclipse or IntelliJ
- Why is T Mobile 4G so slow
- How should educated people act
- What is the theory of coexistence in ecology
- Make senior engineers good entrepreneurs
- How do you mobilize your company
- Why is footwork important in boxing
- Do objects ever become sensible 1
- How do you speed up your response time
- Which country has big Kashmir country
- Black Panther is smarter than Reed Richards
- Is sin sin theta mathematically correct
- What does a good coding ability mean
- Why did Karan Kundra leave Roadies Rising
- Which standard is used for internet time
- Is Apple's online store 100% safe
- How should I train for BUD S.
- Can a government employee trade stocks
- Hunt marmots in packs or alone
- How does studying in Austria feel?
- What do archaeologists study
- How can you see wisdom any other way?
- All song recommendations that aren't boring
- The nutritional tolerances of people are changing
- Why is open source the future
- What's your favorite pizza chain