blob: e9bcee94478a8ee8b679e32c2d498d07d680ae9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
@require: class-slydifi/theme/akasaka
@require: code-printer/code-design
@require: code-printer/code-printer
@require: code-printer/code-syntax
@require: code-printer/code-theme
@require: figbox/figbox
let-block +code-block source keywords =
let syntax =
let void-syntax-rule = CodePrinter.syntax-rule-fun (fun _ -> None) in
CodePrinter.make-syntax (|
line-comment = void-syntax-rule;
block-comment = void-syntax-rule;
string = void-syntax-rule;
keywords = keywords;
identifier = void-syntax-rule;
others = [];
|)
in
'<
+code-printer?:(
CodePrinter.make-config syntax CodeTheme.iceberg-light
|> CodePrinter.set-number-fun CodeDesign.number-fun-null
)(source);
>
let-block +code-block-php source =
'<
+code-printer?:(
CodePrinter.make-config CodeSyntax.php CodeTheme.iceberg-light
|> CodePrinter.set-number-fun CodeDesign.number-fun-null
)(source);
>
let catchline-try = `<?php
try {
f(3);
} catch (Throwable $e) {
do {
printf('%c', $e->getLine() + 21);
} while ($e = $e->getPrevious());
echo "\n";
}`
let catchline-fn-f = `function f(int $i) {
if ($i < 0) return;
try {
match ($i) {
0 => X, // 14行目
// (間の空行は省略)
2 => X, // 51行目
// (間の空行は省略)
1, 3 => X, // 59行目
};
} finally {
f($i - 1);
}
}`
let catchline-fn-f-with-comments = `function f(int $i) {
if ($i < 0) return;
try {
match ($i) {
0 => X, // 14行目: エラー!未定義の定数!
// (間の空行は省略)
2 => X, // 51行目: エラー!未定義の定数!
// (間の空行は省略)
1, 3 => X, // 59行目: エラー!未定義の定数!
};
} finally {
f($i - 1);
}
}`
let error-chain = `<?php
try {
throw new \Exception("a");
} finally {
throw new \Exception("b");
}
`
open FigBox
in
document '<
+make-title(|
title = {
|PHPerKaigi 2023 のトークン問題で
|ボツにした問題を供養する
|};
author = {|nsfisis (いまむら)|};
date = {|第149回PHP勉強会@東京|};
|);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+frame{自己紹介}<
+fig-center(vconcat [
hconcat [
gap 20pt;
textbox{nsfisis (いまむら)};
gap 20pt;
include-image 50pt `assets/me.jpeg`;
];
gap 20pt;
textbox{\@ デジタルサーカス株式会社};
]);
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+frame{PHPerKaigiとは、トークン問題とは}<
+fig-center(vconcat [
gap 20pt;
textbox{時間がないので省略。長谷川さんに聞いてください};
gap 20pt;
textbox{変わったPHPプログラムを持ってきたので解説します};
]);
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+frame{Catchline}<
+code-block-php(catchline-try);
>
+frame{Catchline}<
+code-block-php(catchline-fn-f);
>
+frame{Catchline}<
+code-block-php(catchline-try);
+p{
\inline-code(`f()`);を呼び出して\inline-code(`Throwable`);を捕まえ、何かする
}
>
+frame{Catchline}<
+code-block-php(catchline-fn-f-with-comments);
>
+frame{Catchline}<
+code-block-php(catchline-try);
+p{
\inline-code(`\Throwable::getPrevious()`);を順に辿り、(エラーの発生した行数+21)を
}
+p{
ASCIIコード\text-color(Color.gray(0.75)){[1]}と見做して出力
}
+p{
\text-color(Color.gray(0.75)){[1]: VAS Syndrome}
}
>
+frame{Catchline}<
+p{
\inline-code(`\Throwable::getPrevious()`);
}
+p{
発生したエラーの1つ前のエラー(=大本の原因)
}
+p{
通常は例外クラスのコンストラクタに渡して設定する
}
>
+frame{Catchline}<
+code-block-php(error-chain);
+p{
\inline-code(`finally`);節の中で例外を発生させると、PHPの処理系が勝手に`$previous`を設定する
}
>
+frame{Catchline}<
+code-block-php(catchline-fn-f-with-comments);
>
+frame{Catchline}<
+code-block-php(catchline-try);
+p{
(エラーの発生した行数+21)をASCIIコードと見做して出力
}
>
+frame{Catchline}<
+code-block-php(catchline-fn-f-with-comments);
>
+frame{Catchline}<
+p{
\listing{
* 14 + 21 = 35 (\inline-code(`#`);)
* 51 + 21 = 72 (\inline-code(`H`);)
* 59 + 21 = 80 (\inline-code(`P`);)
}
}
+p{
組み合わせて\inline-code(`#PHP`);に
}
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+frame{おわりに}<
+fig-center(vconcat ?:(align-center) [
gap 20pt;
textbox{来たる3月のPHPerKaigi 2023で};
gap 20pt;
textbox{これより数段凝った問題を5つ出題します!};
gap 20pt;
textbox{みなさまの挑戦をお待ちしております!};
]);
>
>
|