-
Notifications
You must be signed in to change notification settings - Fork 3
02_Basic_usage
heguangyu5 edited this page Jun 30, 2022
·
1 revision
$ mkdir /tmp/bpc
$ cd /tmp/bpc
$ cat -n a.php
1 <?php
2
3 echo "hello world\n";
$ bpc a.php
$ ./a
hello world$ cat -n main.php
1 <?php
2
3 if ($argc == 1) {
4 include "inc1.php";
5 } else {
6 include "inc2.php";
7 }
8
9 sayhi();
10
11 $f = "sayhi";
12 $f();
$ cat -n inc1.php
1 <?php
2
3 echo "This is inc1.php\n";
4
5 function sayhi()
6 {
7 echo "I am inc1.php\n";
8 }
$ cat -n inc2.php
1 <?php
2
3 echo "This is inc2.php\n";
4
5 function sayhi()
6 {
7 echo "I am inc2.php\n";
8 }
$ bpc main.php inc1.php inc2.php
$ ./main
This is inc1.php
I am inc1.php
I am inc1.php
$ ./main arg1
This is inc2.php
I am inc2.php
I am inc2.php$ bpc -o sayhi main.php inc1.php inc2.php
$ ./sayhi
This is inc1.php
I am inc1.php
I am inc1.php
$ ./sayhi arg1
This is inc2.php
I am inc2.php
I am inc2.phpby set BPC_AUTO_RUN env to TRUE, compile and run can be done in one step.
$ BPC_AUTO_RUN=TRUE bpc a.php
hello world
$ BPC_AUTO_RUN=TRUE bpc main.php inc1.php inc2.php
This is inc1.php
I am inc1.php
I am inc1.php
$ BPC_AUTO_RUN=TRUE bpc main.php inc1.php inc2.php -- script-arg1
This is inc2.php
I am inc2.php
I am inc2.phpyou can set php ini by -d option.
$ cat -n err.php
1 <?php
2
3 var_dump(mb_substr("abc", new stdclass));
4
5 f();
$ BPC_AUTO_RUN=TRUE bpc -d display_errors=on err.php
Warning: mb_substr() expects parameter 2 to be integer, object given in bpc/err.php on line 3
NULL
Fatal error: Uncaught Error: Call to undefined function f() in bpc/err.php:5
Stack trace:
#0 {main}
thrown in bpc/err.php on line 5