<?php
echo "A";
try {
echo "B";
throw new Exception("B");
try {
echo "C";
} catch(Exception $e) {
echo "inner";
}
echo "D";
} catch(Exception $e) {
echo "outer";
}
echo "E";
?>
调用php -dvld.active=1 -dvld.execute=0 -dvld.dump_paths=1 multiple_catch.php 2> multiple_catch.php.byte
结果
number of ops: 16
compiled vars: !0 = $e
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
3 0 E > ECHO 'A'
7 1 ECHO 'B'
8 2 NEW $1 'Exception'
3 SEND_VAL_EX 'B'
4 DO_FCALL 0
5 > THROW 0 $1
12 6* ECHO 'C'
7* JMP ->10
14 8 E > > CATCH last 'Exception'
15 9 > ECHO 'inner'
18 10 ECHO 'D'
11 > JMP ->14
20 12 E > > CATCH last 'Exception'
21 13 > ECHO 'outer'
24 14 > ECHO 'E'
27 15 > RETURN 1
但是,只是天真地阅读 op 列,看起来好像 op 5 抛出的异常会导致打印出“内部”。但是,当考虑到原始源时,这显然是错误的,因为运行源确认:
$> php multiple_catch.php
ABouterE
PHP引擎如何根据字节码知道它所在的try块?