xref: /web-php/releases/8.2/release.inc (revision 9b12309e)
1<?php
2
3use function releases\php82\common_header;
4use function releases\php82\language_chooser;
5use function releases\php82\message;
6
7if (!isset($lang)) {
8    $lang = 'en';
9}
10
11$_SERVER['BASE_PAGE'] = 'releases/8.2/' . $lang . '.php';
12
13include_once __DIR__ . '/common.php';
14
15common_header(message('common_header', $lang));
16
17?>
18    <section class="php8-section php8-section_dark php8-section_header center">
19        <div class="page-tools">
20            <div class="change-language">
21                <?php language_chooser($lang); ?>
22            </div>
23        </div>
24        <div class="php8-section__content">
25            <div class="php8-logo">
26                <img src="/images/php8/logo_php8_2.svg" alt="PHP 8.2" height="126" width="343">
27            </div>
28            <div class="php8-title"><?= message('main_title', $lang) ?></div>
29            <div class="php8-subtitle"><?= message('main_subtitle', $lang) ?></div>
30            <div class="php8-button-wrapper center">
31                <a class="php8-button php8-button_light" href="/downloads"><?= message('upgrade_now', $lang) ?></a>
32            </div>
33        </div>
34    </section>
35
36    <section class="php8-section center">
37        <div class="php8-compare">
38            <h2 class="php8-h2" id="readonly_classes">
39                <?= message('readonly_classes_title', $lang) ?>
40                <a class="php8-rfc" href="https://wiki.php.net/rfc/readonly_classes">RFC</a>
41                <a class="php8-rfc"
42                   href="/manual/<?= $lang ?>/language.oop5.basic.php#language.oop5.basic.class.readonly"><?= message(
43                        'documentation',
44                        $lang,
45                    ) ?></a>
46            </h2>
47            <div class="php8-compare__main">
48                <div class="php8-compare__block example-contents">
49                    <div class="php8-compare__label">PHP &lt; 8.2</div>
50                    <div class="php8-code phpcode">
51                        <?php highlight_php_trimmed(
52                            <<<'PHP'
53class BlogData
54{
55    public readonly string $title;
56
57    public readonly Status $status;
58
59    public function __construct(string $title, Status $status)
60    {
61        $this->title = $title;
62        $this->status = $status;
63    }
64}
65PHP
66
67                        ); ?>
68                    </div>
69                </div>
70                <div class="php8-compare__arrow"></div>
71                <div class="php8-compare__block example-contents">
72                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
73                    <div class="php8-code phpcode">
74                        <?php highlight_php_trimmed(
75                            <<<'PHP'
76readonly class BlogData
77{
78    public string $title;
79
80    public Status $status;
81
82    public function __construct(string $title, Status $status)
83    {
84        $this->title = $title;
85        $this->status = $status;
86    }
87}
88PHP
89                        ); ?>
90                    </div>
91                </div>
92            </div>
93        </div>
94
95        <div class="php8-compare">
96            <h2 class="php8-h2" id="dnf_types">
97                <?= message('dnf_types_title', $lang) ?>
98                <a class="php8-rfc" href="https://wiki.php.net/rfc/dnf_types">RFC</a>
99                <a class="php8-rfc"
100                   href="/manual/<?= $lang ?>/migration82.new-features.php#migration82.new-features.core.type-system"><?= message(
101                        'documentation',
102                        $lang,
103                    ) ?></a>
104            </h2>
105            <div class="php8-compare__main">
106                <div class="php8-compare__block example-contents">
107                    <div class="php8-compare__label">PHP &lt; 8.2</div>
108                    <div class="php8-code phpcode">
109                        <?php highlight_php_trimmed(
110                            <<<'PHP'
111class Foo {
112    public function bar(mixed $entity) {
113        if ((($entity instanceof A) && ($entity instanceof B)) || ($entity === null)) {
114            return $entity;
115        }
116
117        throw new Exception('Invalid entity');
118    }
119}
120PHP
121
122                        ); ?>
123                    </div>
124                </div>
125                <div class="php8-compare__arrow"></div>
126                <div class="php8-compare__block example-contents">
127                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
128                    <div class="php8-code phpcode">
129                        <?php highlight_php_trimmed(
130                            <<<'PHP'
131class Foo {
132    public function bar((A&B)|null $entity) {
133        return $entity;
134    }
135}
136PHP
137                        ); ?>
138                    </div>
139                </div>
140            </div>
141        </div>
142        <div class="php8-compare__content">
143            <?= message('dnf_types_description', $lang) ?>
144        </div>
145
146        <div class="php8-compare">
147            <h2 class="php8-h2" id="null_false_true_types">
148                <?= message('null_false_true_types_title', $lang) ?>
149                <a class="php8-rfc" href="https://wiki.php.net/rfc/null-false-standalone-types">RFC</a>
150                <a class="php8-rfc" href="https://wiki.php.net/rfc/true-type">RFC</a>
151            </h2>
152            <div class="php8-compare__main">
153                <div class="php8-compare__block example-contents">
154                    <div class="php8-compare__label">PHP &lt; 8.2</div>
155                    <div class="php8-code phpcode">
156                        <?php highlight_php_trimmed(
157                            <<<'PHP'
158class Falsy
159{
160    public function almostFalse(): bool { /* ... */ *}
161
162    public function almostTrue(): bool { /* ... */ *}
163
164    public function almostNull(): string|null { /* ... */ *}
165}
166PHP
167
168                        ); ?>
169                    </div>
170                </div>
171                <div class="php8-compare__arrow"></div>
172                <div class="php8-compare__block example-contents">
173                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
174                    <div class="php8-code phpcode">
175                        <?php highlight_php_trimmed(
176                            <<<'PHP'
177class Falsy
178{
179    public function alwaysFalse(): false { /* ... */ *}
180
181    public function alwaysTrue(): true { /* ... */ *}
182
183    public function alwaysNull(): null { /* ... */ *}
184}
185PHP
186                        ); ?>
187                    </div>
188                </div>
189            </div>
190        </div>
191
192        <div class="php8-compare">
193            <h2 class="php8-h2" id="random_extension">
194                <?= message('random_title', $lang) ?>
195                <a class="php8-rfc" href="https://wiki.php.net/rfc/rng_extension">RFC</a>
196                <a class="php8-rfc" href="https://wiki.php.net/rfc/random_extension_improvement">RFC</a>
197                <a class="php8-rfc" href="/manual/<?= $lang ?>/book.random.php"><?= message('documentation', $lang ) ?></a>
198            </h2>
199            <div class="php8-compare__main">
200                <div class="example-contents example-contents-full">
201                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
202                    <div class="php8-code phpcode">
203                        <?php highlight_php_trimmed(
204                            <<<'PHP'
205use Random\Engine\Xoshiro256StarStar;
206use Random\Randomizer;
207
208$blueprintRng = new Xoshiro256StarStar(
209    hash('sha256', "Example seed that is converted to a 256 Bit string via SHA-256", true)
210);
211
212$fibers = [];
213for ($i = 0; $i < 8; $i++) {
214	$fiberRng = clone $blueprintRng;
215	// Xoshiro256**'s 'jump()' method moves the blueprint ahead 2**128 steps, as if calling
216	// 'generate()' 2**128 times, giving the Fiber 2**128 unique values without needing to reseed.
217	$blueprintRng->jump();
218
219	$fibers[] = new Fiber(function () use ($fiberRng, $i): void {
220		$randomizer = new Randomizer($fiberRng);
221
222		echo "{$i}: " . $randomizer->getInt(0, 100), PHP_EOL;
223	});
224}
225
226// The randomizer will use a CSPRNG by default.
227$randomizer = new Randomizer();
228
229// Even though the fibers execute in a random order, they will print the same value
230// each time, because each has its own unique instance of the RNG.
231$fibers = $randomizer->shuffleArray($fibers);
232foreach ($fibers as $fiber) {
233	$fiber->start();
234}
235PHP
236                        ); ?>
237                    </div>
238                </div>
239            </div>
240        </div>
241        <div class="php8-compare__content">
242            <?= message('random_description', $lang) ?>
243        </div>
244
245        <div class="php8-compare">
246            <h2 class="php8-h2" id="constants_in_traits">
247                <?= message('constants_in_traits_title', $lang) ?>
248                <a class="php8-rfc" href="https://wiki.php.net/rfc/constants_in_traits">RFC</a>
249                <a class="php8-rfc"
250                   href="/manual/<?= $lang ?>/migration82.new-features.php#migration82.new-features.core.constant-in-traits"><?= message(
251                        'documentation',
252                        $lang,
253                    ) ?></a>
254            </h2>
255            <div class="php8-compare__main">
256                <div class="example-contents example-contents-full">
257                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
258                    <div class="php8-code phpcode">
259                        <?php highlight_php_trimmed(
260                            <<<'PHP'
261trait Foo
262{
263    public const CONSTANT = 1;
264}
265
266class Bar
267{
268    use Foo;
269}
270
271var_dump(Bar::CONSTANT); // 1
272var_dump(Foo::CONSTANT); // Error
273PHP
274                        ); ?>
275                    </div>
276                </div>
277            </div>
278        </div>
279        <div class="php8-compare__content">
280            <?= message('constants_in_traits_description', $lang) ?>
281        </div>
282
283        <div class="php8-compare">
284            <h2 class="php8-h2" id="deprecate_dynamic_properties">
285                <?= message('deprecate_dynamic_properties_title', $lang) ?>
286                <a class="php8-rfc" href="https://wiki.php.net/rfc/deprecate_dynamic_properties">RFC</a>
287                <a class="php8-rfc"
288                   href="/manual/<?= $lang ?>/migration82.deprecated.php#migration82.deprecated.core.dynamic-properties"><?= message(
289                        'documentation',
290                        $lang,
291                    ) ?></a>
292            </h2>
293            <div class="php8-compare__main">
294                <div class="php8-compare__block example-contents">
295                    <div class="php8-compare__label">PHP &lt; 8.2</div>
296                    <div class="php8-code phpcode">
297                        <?php highlight_php_trimmed(
298                            <<<'PHP'
299class User
300{
301    public $name;
302}
303
304$user = new User();
305$user->last_name = 'Doe';
306
307$user = new stdClass();
308$user->last_name = 'Doe';
309PHP
310
311                        ); ?>
312                    </div>
313                </div>
314                <div class="php8-compare__arrow"></div>
315                <div class="php8-compare__block example-contents">
316                    <div class="php8-compare__label php8-compare__label_new">PHP 8.2</div>
317                    <div class="php8-code phpcode">
318                        <?php highlight_php_trimmed(
319                            <<<'PHP'
320class User
321{
322    public $name;
323}
324
325$user = new User();
326$user->last_name = 'Doe'; // Deprecated notice
327
328$user = new stdClass();
329$user->last_name = 'Doe'; // Still allowed
330PHP
331                        ); ?>
332                    </div>
333                </div>
334            </div>
335        </div>
336        <div class="php8-compare__content">
337            <?= message('deprecate_dynamic_properties_description', $lang) ?>
338        </div>
339
340    </section>
341
342    <section class="php8-section center php8-section_light php8-columns">
343        <div class="php8-column">
344            <h2 class="php8-h2" id="other_new_things"><?= message('new_classes_title', $lang) ?></h2>
345            <div class="php8-compare__content php8-compare__content--block">
346                <ul>
347                    <li><?= message('new_mysqli', $lang) ?></li>
348                    <li><?= message('new_attributes', $lang) ?></li>
349                    <li><?= message('new_zip', $lang) ?></li>
350                    <li><?= message('new_reflection', $lang) ?></li>
351                    <li><?= message('new_functions', $lang) ?></li>
352                </ul>
353            </div>
354        </div>
355
356        <div class="php8-column">
357            <h2 class="php8-h2" id="deprecations_and_bc_breaks"><?= message('bc_title', $lang) ?></h2>
358            <div class="php8-compare__content">
359                <ul>
360                    <li><?= message('bc_string_interpolation', $lang) ?></li>
361                    <li><?= message('bc_utf8', $lang) ?></li>
362                    <li><?= message('bc_datetime', $lang) ?></li>
363                    <li><?= message('bc_odbc', $lang) ?></li>
364                    <li><?= message('bc_str_locale_sensitive', $lang) ?></li>
365                    <li><?= message('bc_spl_enforces_signature', $lang) ?></li>
366                    <li><?= message('bc_spl_false', $lang) ?></li>
367                    <li><?= message('bc_spl_null', $lang) ?></li>
368                    <li><?= message('bc_spl_deprecated', $lang) ?></li>
369                </ul>
370            </div>
371        </div>
372    </section>
373
374    <section class="php8-section php8-section_dark php8-section_footer php8-footer">
375        <div class="php8-section__content">
376            <h2 class="php8-h2 center"><?= message('footer_title', $lang) ?></h2>
377            <div class="php8-button-wrapper center">
378                <a class="php8-button php8-button_light" href="/downloads"><?= message('upgrade_now', $lang) ?></a>
379            </div>
380            <div class="php8-footer__content"><?= message('footer_description', $lang) ?></div>
381        </div>
382    </section>
383
384<?php
385
386site_footer();
387