|
101 | 101 |
|
102 | 102 | <div class="php8-compare">
|
103 | 103 | <h2 class="php8-h2" id="override_attribute">
|
104 |
| - <code>#[Override]</code> attribute |
| 104 | + <code>#[\Override]</code> attribute |
105 | 105 | <a class="php8-rfc" href="https://wiki.php.net/rfc/marking_overriden_methods">RFC</a>
|
106 | 106 | </h2>
|
107 | 107 | <div class="php8-compare__main">
|
|
110 | 110 | <div class="php8-code phpcode">
|
111 | 111 | <?php highlight_php_trimmed(
|
112 | 112 | <<<'PHP'
|
113 |
| -// TODO |
| 113 | +use PHPUnit\Framework\TestCase; |
| 114 | + |
| 115 | +final class MyTest extends TestCase |
| 116 | +{ |
| 117 | + protected $logFile; |
| 118 | +
|
| 119 | + protected function setUp(): void |
| 120 | + { |
| 121 | + $this->logFile = fopen('/tmp/logfile', 'w'); |
| 122 | + } |
| 123 | +
|
| 124 | + protected function taerDown(): void |
| 125 | + { |
| 126 | + fclose($this->logFile); |
| 127 | + unlink('/tmp/logfile'); |
| 128 | + } |
| 129 | +} |
| 130 | +
|
| 131 | +// The log file will never be removed, because the |
| 132 | +// method name was mistyped (taerDown vs tearDown). |
114 | 133 | PHP
|
115 | 134 |
|
116 | 135 | ); ?>
|
|
123 | 142 | <?php highlight_php_trimmed(
|
124 | 143 | <<<'PHP'
|
125 | 144 | // TODO
|
126 |
| -PHP |
| 145 | +use PHPUnit\Framework\TestCase; |
| 146 | + |
| 147 | +final class MyTest extends TestCase |
| 148 | +{ |
| 149 | + protected $logFile; |
| 150 | +
|
| 151 | + protected function setUp(): void |
| 152 | + { |
| 153 | + $this->logFile = fopen('/tmp/logfile', 'w'); |
| 154 | + } |
| 155 | +
|
| 156 | + #[\Override] |
| 157 | + protected function taerDown(): void |
| 158 | + { |
| 159 | + fclose($this->logFile); |
| 160 | + unlink('/tmp/logfile'); |
| 161 | + } |
| 162 | +} |
| 163 | +
|
| 164 | +// Fatal error: MyTest::taerDown() has #[\Override] attribute, |
| 165 | +// but no matching parent method exists |
127 | 166 | ); ?>
|
128 | 167 | </div>
|
129 | 168 | </div>
|
|
0 commit comments