Menu

P2pcQuickStart

OpenAutonomy Inc.

PHP-to-PHP Compiler Quick Start

Below is a an example of the different outputs created by running p2pc in its 3 different modes on a simple set of input files.

  • Preprocess: inlines files
  • Strip: removes whitespace
  • Deadcode: removes unreachable functions

Input Files

The files listed here are the inputs used for all the running modes to follow.

test_input.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/php
<?php
// This is a very simple test which demonstrates how the compiler works.  It should
//  produce the same output when compiled or not.
require_once('NoCompile.php');

echo "START\n";
require_once('a.php');
require_once('b.php');
require_once('c.php');
echo "END\n";

?>

resources/a.php

<?php
echo "A\n";
require_once('b.php');
require_once('d.php');

function unused($foo)
{
    return $foo + 1;
}
?>

resources/b.php

<?php
echo "B\n";
require_once('a.php');
require_once('e.php');

?>

resources/c.php

<?php
require_once('f.php');
echo "C\n";

?>

resources/d.php

<?php
echo "D\n";
require_once('b.php');

?>

resources/e.php

<?php
echo "E\n";
require_once('a.php');

?>

resources/f.php

<?php
echo "F\n";

?>

Output files produced with different options

Note that all of these programs produce the same result.

--preprocess

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/php
<?php
// This is a very simple test which demonstrates how the compiler works.  It should
//  produce the same output when compiled or not.

echo "START\n";
echo "A\n";
echo "B\n";
echo "E\n";

echo "D\n";

function unused($foo)
{
    return $foo + 1;
}
echo "F\n";

echo "C\n";

echo "END\n";

?>

--strip

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/php
<?php
echo"START\n";
echo"A\n";
echo"B\n";
echo"E\n";
echo"D\n";
function unused($foo){return $foo+1;
}echo"F\n";
echo"C\n";
echo"END\n";

?>

--deadCode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/usr/bin/php
<?php
echo"START\n";
echo"A\n";
echo"B\n";
echo"E\n";
echo"D\n";
echo"F\n";
echo"C\n";
echo"END\n";

?>

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.