Reputation: 4184
<?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";
?>
Called with php -dvld.active=1 -dvld.execute=0 -dvld.dump_paths=1 multiple_catch.php 2> multiple_catch.php.byte
results in
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
However, just naively reading the op column it looks as if an exception thrown by op 5 would lead to the print out of 'inner'. However, when taking the original source into account, this is obviously wrong as running the source confirms:
$> php multiple_catch.php
ABouterE
How does the PHP engine know the try block it is in based on the byte code?
Upvotes: 0
Views: 38