diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-17 01:35:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-17 01:35:04 +0900 |
| commit | 0766039bd9e6b9f5e6334e84666f5be698d41fc3 (patch) | |
| tree | 0f3a52fdbf56496850f903d64dcf7725fb0aedbe /public/posts/2023-01-10 | |
| parent | ee72f8780cf3681e4202cc3a6358fb4038db1ec8 (diff) | |
| download | blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.gz blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.zst blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.zip | |
feat(nuldoc): implement syntax highlight
Diffstat (limited to 'public/posts/2023-01-10')
| -rw-r--r-- | public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html index ab47b2b..61d9880 100644 --- a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html +++ b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2023: ボツになったトークン問題 その 3 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -92,24 +92,24 @@ 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); -} catch (Throwable $e) { - while ($e = $e->getPrevious()) printf('%c', $e->getLine() + 23); - echo "\n"; + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()) <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">'%c'</span>, <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>); + <span class="hljs-keyword">echo</span> <span class="hljs-string">"\n"</span>; } -function f(int $i) { - if ($i < 0) f(); - try { - match ($i) { - 0 => 0 / 0, +<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{ + <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> < <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>(); + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) { + <span class="hljs-number">0</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 15, 36 => 0 / 0, - 14 => 0 / 0, - 37 => 0 / 0, + <span class="hljs-number">15</span>, <span class="hljs-number">36</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">14</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">37</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -120,16 +120,16 @@ function f(int $i) { - 6 => 0 / 0, + <span class="hljs-number">6</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 5 => 0 / 0, + <span class="hljs-number">5</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 22 => 0 / 0, + <span class="hljs-number">22</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 34, 35 => 0 / 0, + <span class="hljs-number">34</span>, <span class="hljs-number">35</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -138,10 +138,10 @@ function f(int $i) { - 25 => 0 / 0, - 17, 21 => 0 / 0, + <span class="hljs-number">25</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">17</span>, <span class="hljs-number">21</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 24, 32 => 0 / 0, + <span class="hljs-number">24</span>, <span class="hljs-number">32</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -149,12 +149,12 @@ function f(int $i) { - 33 => 0 / 0, + <span class="hljs-number">33</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 16 => 0 / 0, + <span class="hljs-number">16</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 18 => 0 / 0, + <span class="hljs-number">18</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -163,35 +163,35 @@ function f(int $i) { - 7 => 0 / 0, + <span class="hljs-number">7</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 2 => 0 / 0, - 1, 20 => 0 / 0, - 10, 28 => 0 / 0, - 8, 12, 26 => 0 / 0, - 4, 9, 13 => 0 / 0, + <span class="hljs-number">2</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">1</span>, <span class="hljs-number">20</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">10</span>, <span class="hljs-number">28</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">8</span>, <span class="hljs-number">12</span>, <span class="hljs-number">26</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">4</span>, <span class="hljs-number">9</span>, <span class="hljs-number">13</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 31 => 0 / 0, + <span class="hljs-number">31</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 29 => 0 / 0, + <span class="hljs-number">29</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 11 => 0 / 0, + <span class="hljs-number">11</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 3, 19, 23 => 0 / 0, + <span class="hljs-number">3</span>, <span class="hljs-number">19</span>, <span class="hljs-number">23</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 27 => 0 / 0, + <span class="hljs-number">27</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 30 => 0 / 0, + <span class="hljs-number">30</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, }; - } finally { - f($i - 1); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>); } } @@ -201,8 +201,8 @@ function f(int $i) { -function g() { - return __LINE__; +<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{ + <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>; }</code></pre> <p> @@ -247,19 +247,19 @@ function g() { このうち 1つ目のケースは、<code>finally</code>節の中でエラーを投げると PHP 処理系が勝手に<code>$previous</code>を設定してくれる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> -try { - try { - throw new Exception("Error 1"); - } finally { - throw new Exception("Error 2"); +<span class="hljs-keyword">try</span> { + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">"Error 1"</span>); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">"Error 2"</span>); } -} catch (Exception $e) { - echo $e->getMessage() . PHP_EOL; - // => Error 2 - echo $e->getPrevious()->getMessage() . PHP_EOL; - // => Error 1 +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Exception</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL; + <span class="hljs-comment">// => Error 2</span> + <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()-><span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL; + <span class="hljs-comment">// => Error 1</span> }</code></pre> <p> @@ -273,14 +273,14 @@ try { 出力部をコメントや改行を追加して再掲する: </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); -} catch (Throwable $e) { - while ($e = $e->getPrevious()) { - printf('%c', $e->getLine() + 23); + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()) { + <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">'%c'</span>, <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>); } - echo "\n"; + <span class="hljs-keyword">echo</span> <span class="hljs-string">"\n"</span>; }</code></pre> <p> @@ -291,7 +291,7 @@ try { フォーマット指定子<code>%c</code>は、整数を ASCII コード<span></span>と見做して印字する。トークン<code>#base64_decode('SGVsbG8sIFdvcmxkIQ==')</code>の<code>b</code>であれば、ASCII コード<code>98</code>なので、75 行目で発生したエラー、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>1, 20 => 0 / 0,</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-number">1</span>, <span class="hljs-number">20</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,</code></pre> <p> によって表現されている。エラーを起こす方法はいろいろと考えられるが、今回はゼロ除算を使った。 @@ -308,24 +308,24 @@ try { <code>f()</code>の定義を再掲する (エラーオブジェクトの行数を利用しているので、一部分だけ抜き出すと値が変わることに注意): </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>function f(int $i) { - if ($i < 0) f(); - try { - match ($i) { - 0 => 0 / 0, // 12 行目 + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{ + <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> < <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>(); + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) { + <span class="hljs-number">0</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 12 行目</span> - 15, 36 => 0 / 0, - 14 => 0 / 0, - 37 => 0 / 0, + <span class="hljs-number">15</span>, <span class="hljs-number">36</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">14</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">37</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - // (略) + <span class="hljs-comment">// (略)</span> - 30 => 0 / 0, // 97 行目 + <span class="hljs-number">30</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 97 行目</span> }; - } finally { - f($i - 1); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>); } }</code></pre> @@ -333,12 +333,12 @@ try { 前述のように、<code>finally</code>節でエラーを投げると PHP 処理系が<code>$previous</code>を設定する。ここでは、エラーを繋げるために<code>f()</code>を再帰呼び出ししている。最初に<code>f()</code>を呼び出している箇所を確認すると、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); // 3 行目</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); <span class="hljs-comment">// 3 行目</span></code></pre> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>function g() { - return __LINE__; // 111 行目 + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{ + <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>; <span class="hljs-comment">// 111 行目</span> }</code></pre> <p> |
