PHP string analyzer is a static program analyzer that approximates the string output of a PHP program with a context-free grammar. The analyzer can be used to check properties of a PHP program. For example, it can be used to validate dynamically generated Web pages by a PHP program.
<?php for ($i = 0; $i < $n; $i++) $x = "0".$x."1"; echo $x; ?>For the analysis, we need to specify the initial values of the global variables in the program. The specification is given as follows:
$x : /abc|xyz/ $n : intThe specification /abc|xyz/ is a regular expression representing the set of strings {abc, xyz}. The type 'int' is specified for the variable $n. The analyzer is executed as follows:
% phpsa -ispec example0.ispec -simplify example0.phpwhere the option -simplify indicates that the analyzer tries to simplify the CFG.
({$268$, $293$}, // variables
{$268$ -> $293$|0$268$1,$293$ -> abc|xyz}, // productions
$268$) // start symbol
This grammar represents the set of strings { 0^nabc1^n | n >= 0} U { 0^nxyz1^n | n >= 0} as we expect.