Getting Started

How to get started with your first parses

This simple tutorial will demonstrate how to parse a simple file or a directory.

Since version 2.6.0 you are free to use your favorite autoloading solution. Here, we will show the default and Symfony abilities.

Parse a single file with default options

To parse a file with the PHP5 known references of your extensions loaded, you have just to specify the file’s location.

Example 1: with version 2.6.0 or better (and default autoloader; see line 2)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
require_once 'Bartlett/PHP/CompatInfo/Autoload.php';

$source = '/path/to/myFile.php';

try {
    $phpci = new PHP_CompatInfo();
    $phpci->parse($source);

    $allResultsAtOnce = $phpci->toArray();

} catch (PHP_CompatInfo_Exception $e) {
    die ('PHP_CompatInfo Exception : ' . $e->getMessage() . PHP_EOL);
}
Example 2: with version 2.6.0 or better (and Symfony ClassLoader component; see lines 2 to 10)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
require_once 'Symfony/Component/ClassLoader/UniversalClassLoader.php';

use Symfony\Component\ClassLoader\UniversalClassLoader;

$loader = new UniversalClassLoader();
$loader->registerPrefixes(array(
    'PHP_' => '/path/to/PEAR/Bartlett/',
));
$loader->register();

$source = '/path/to/myFile.php';

try {
    $phpci = new PHP_CompatInfo();
    $phpci->parse($source);

    $allResultsAtOnce = $phpci->toArray();

} catch (PHP_CompatInfo_Exception $e) {
    die ('PHP_CompatInfo Exception : ' . $e->getMessage() . PHP_EOL);
}
Example 3: with all versions until 2.5.0 (no autoloader, but the library itself; see line 2)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
require_once 'Bartlett/PHP/CompatInfo.php';

$source = '/path/to/myFile.php';

try {
    $phpci = new PHP_CompatInfo();
    $phpci->parse($source);

    $allResultsAtOnce = $phpci->toArray();

} catch (PHP_CompatInfo_Exception $e) {
    die ('PHP_CompatInfo Exception : ' . $e->getMessage() . PHP_EOL);
}

Single file alternative with the CLI tool

From your PEAR bin_dir directory run this command

$ phpci --no-configuration print --reference PHP5 --report summary /path/to/myFile.php

It won’t use the default XML configuration file phpcompatinfo.xml or phpcompatinfo.xml.dist If you are sure of XML configuration settings, remove the --no-configuration option.

Will print out a summary report like this one

    PHP COMPAT INFO REPORT SUMMARY
    -------------------------------------------------------------------------------
    A TOTAL OF
     5 EXTENSIONS 3 INTERFACES 11 CLASSES 27 FUNCTIONS 4 CONSTANTS
    WERE FOUND IN 1 FILE
    WITH CONDITIONAL CODE LEVEL 32
    REQUIRED PHP 5.1.3 (MIN)
    -------------------------------------------------------------------------------
    Time: 2 seconds, Memory: 8.50Mb
    -------------------------------------------------------------------------------

When you set verbose level to 3 (-vvv), and run again the print command

$ phpci --no-configuration -vvv print --reference PHP5 --report summary /path/to/myFile.php

It will print out this new detailed summary report

    PHP COMPAT INFO REPORT SUMMARY
    -------------------------------------------------------------------------------
    FILES                         EXTENSIONS INTERFACES CLASSES FUNCTIONS CONSTANTS
    -------------------------------------------------------------------------------
    BASE: /path/to
    -------------------------------------------------------------------------------
    DIR.:
    myFile.php                            5          3      11        27         4
    -------------------------------------------------------------------------------
    A TOTAL OF
     5 EXTENSIONS 3 INTERFACES 11 CLASSES 27 FUNCTIONS 4 CONSTANTS
    WERE FOUND IN 1 FILE
    WITH CONDITIONAL CODE LEVEL 32
    REQUIRED PHP 5.1.3 (MIN)
    -------------------------------------------------------------------------------
    Time: 2 seconds, Memory: 8.50Mb
    -------------------------------------------------------------------------------

    Warning messages : (2)

      Cannot load extension reference 'odbc'
      Cannot load extension reference 'mysqlnd'

Parse a directory with default options

If you wish to parse an entire directory, you can specify the directory location instead of a file.

Caution
the default behavior will not parse directories recursively.
Example with default autoloader
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
require_once 'Bartlett/PHP/CompatInfo/Autoload.php';

$source = '/path/to/myFolder';

try {
    $phpci = new PHP_CompatInfo();
    $phpci->parse($source);

    $allResultsAtOnce = $phpci->toArray();

} catch (PHP_CompatInfo_Exception $e) {
    die ('PHP_CompatInfo Exception : ' . $e->getMessage() . PHP_EOL);
}

Directory alternative with the CLI tool

From your PEAR bin_dir directory and the default XML configuration file phpcompatinfo.xml.dist installed into PEAR cfg_dir/PHP_CompatInfo.

$ phpci -vvv print /path/to/myFolder

Will print out the summary report

    PHP COMPAT INFO REPORT SUMMARY
    -------------------------------------------------------------------------------
    FILES                         EXTENSIONS INTERFACES CLASSES FUNCTIONS CONSTANTS
    -------------------------------------------------------------------------------
    BASE: /path/to/myFolder
    -------------------------------------------------------------------------------
    DIR.:
    Cache.php                             3          0       2         4         3
    CLI.php                               3          0       8        16         6
    Configuration.php                     3          0       5        10         3
    Exception.php                         1          0       2         0         0
    Reference.php                         1          1       0         0         1
    Report.php                            2          0       2        11         3
    TokenParser.php                       2          0      14         9         3
    TokenStream.php                       4          0       3        17         3
    -------------------------------------------------------------------------------
    A TOTAL OF
     5 EXTENSIONS 1 INTERFACE 31 CLASSES 47 FUNCTIONS 6 CONSTANTS
    WERE FOUND IN 8 FILES
    WITH CONDITIONAL CODE LEVEL 32
    REQUIRED PHP 5.1.2 (MIN)
    -------------------------------------------------------------------------------
    Time: 2 seconds, Memory: 12.00Mb
    -------------------------------------------------------------------------------

    Warning messages : (2)

      Cannot load extension reference 'odbc'
      Cannot load extension reference 'mysqlnd'