|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Bug14318; |
| 4 | + |
| 5 | +class HelloWorld5 |
| 6 | +{ |
| 7 | + public function test5(): void |
| 8 | + { |
| 9 | + global $pdo; |
| 10 | + |
| 11 | + try { |
| 12 | + $this->maybeThrows5($sql = "SELECT * FROM foo"); |
| 13 | + $rs = $pdo->query($sql); |
| 14 | + if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) { |
| 15 | + // do something |
| 16 | + } |
| 17 | + } catch (\PDOException $e) { |
| 18 | + var_dump($sql); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @throws \RuntimeException |
| 24 | + */ |
| 25 | + public function maybeThrows5(string $s): void |
| 26 | + { |
| 27 | + if (random_int(0, 1) === 1) { |
| 28 | + throw new \RuntimeException(); |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +class HelloWorld6 |
| 34 | +{ |
| 35 | + public function test6(): void |
| 36 | + { |
| 37 | + global $pdo; |
| 38 | + |
| 39 | + try { |
| 40 | + $this->maybeThrows6(strlen($sql = "SELECT * FROM foo")); |
| 41 | + $rs = $pdo->query($sql); |
| 42 | + if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) { |
| 43 | + // do something |
| 44 | + } |
| 45 | + } catch (\PDOException $e) { |
| 46 | + var_dump($sql); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @throws \RuntimeException |
| 52 | + */ |
| 53 | + public function maybeThrows6(int $s): void |
| 54 | + { |
| 55 | + if (random_int(0, 1) === 1) { |
| 56 | + throw new \RuntimeException(); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +class HelloWorld7Static |
| 62 | +{ |
| 63 | + public function test7(): void |
| 64 | + { |
| 65 | + global $pdo; |
| 66 | + |
| 67 | + try { |
| 68 | + self::maybeThrows7($sql = "SELECT * FROM foo"); |
| 69 | + $rs = $pdo->query($sql); |
| 70 | + if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) { |
| 71 | + // do something |
| 72 | + } |
| 73 | + } catch (\PDOException $e) { |
| 74 | + var_dump($sql); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @throws \RuntimeException |
| 80 | + */ |
| 81 | + public static function maybeThrows7(string $s): void |
| 82 | + { |
| 83 | + if (random_int(0, 1) === 1) { |
| 84 | + throw new \RuntimeException(); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +class HelloWorld8Static |
| 90 | +{ |
| 91 | + public function test8(): void |
| 92 | + { |
| 93 | + global $pdo; |
| 94 | + |
| 95 | + try { |
| 96 | + self::maybeThrows8(strlen($sql = "SELECT * FROM foo")); |
| 97 | + $rs = $pdo->query($sql); |
| 98 | + if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) { |
| 99 | + // do something |
| 100 | + } |
| 101 | + } catch (\PDOException $e) { |
| 102 | + var_dump($sql); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @throws \RuntimeException |
| 108 | + */ |
| 109 | + public static function maybeThrows8(int $s): void |
| 110 | + { |
| 111 | + if (random_int(0, 1) === 1) { |
| 112 | + throw new \RuntimeException(); |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments