PHP 8.6 is a major update of the PHP language, with new features including Partial Function Application, a new Duration class, a Polling API, and a new clamp() function
', + + 'whats_new' => 'What\'s new in 8.6', + 'upgrade_now' => 'Upgrade to PHP 8.6', + 'old_version' => 'PHP 8.5 and older', + 'badge_new' => 'NEW', + 'documentation' => 'Doc', + 'released' => 'Will be released on November 19, 2026', + 'release_unavailable_reason' => 'PHP 8.6 has not been released yet. It will be released on November 19, 2026.', + 'key_features' => 'Key Features in PHP 8.6', + 'key_features_description' => 'Faster, cleaner, and built for developers.
', + + 'features_pfa_description' => 'Allows some of a function\'s arguments to be provided in advance, returning a Closure that accepts the rest.
', + 'features_readonly_property_defaults_description' => 'Allows readonly properties to declare default values, so fixed values no longer have to be assigned in the constructor.
', + 'features_polling_api_description' => 'Scalable I/O multiplexing using epoll, kqueue, and other native mechanisms, available to event loop libraries like ReactPHP and AMPHP.
', + 'features_clamp_description' => 'Ensures that a given value (numeric or otherwise) falls within a specified range.
', + 'features_duration_description' => 'The Duration class represents elapsed time as measured by a stopwatch.
', + 'features_sort_direction_description' => 'A standard, type-safe way to express sort order that can be shared across libraries.
', + + 'pfa_title' => 'Partial Function Application', + 'pfa_description' => 'Allows some of a function\'s arguments to be provided in advance, using? and ... placeholders for the rest. The result is a Closure, and the function is only called once the remaining arguments are passed to it.',
+ 'readonly_property_defaults_title' => 'Readonly property defaults',
+ 'readonly_property_defaults_description' => 'Instance readonly properties, including those in readonly classes, can now declare a default value. This makes it simple to implement get-only interface properties with fixed values, which previously required assigning them in a constructor. The default counts as the property\'s initialization, so the constructor cannot overwrite it.',
+ 'polling_api_title' => 'Polling API',
+ 'polling_api_description' => 'The new Io\Poll API efficiently monitors many streams at once using the best mechanism available on each platform (epoll, kqueue, event ports, or WSAPoll), without the scalability limits of stream_select(). It is designed as a common foundation that event loop libraries such as ReactPHP and AMPHP can build on.',
+ 'clamp_title' => 'New clamp() function',
+ 'clamp_description' => 'Ensures that a given value (numeric or otherwise) falls within a specified range. Otherwise, the nearest boundary value is returned.',
+ 'duration_title' => 'New \Time\Duration class',
+ 'duration_description' => 'The Duration class represents elapsed time as measured by a stopwatch. Its representation is independent of any time and timezone and allows to represent a range of more than 250 years with nanosecond precision. This makes it well-suited to represent timeouts or benchmark timings in an expressive way.',
+ 'sort_direction_title' => 'New SortDirection enum',
+ 'sort_direction_description' => 'The SortDirection enum provides a shared, type-safe way to express sort order with its Ascending and Descending cases. Previously, every library had to define its own way of representing sort direction, resulting in a mix of incompatible integers, strings, booleans, and custom enums. Since SortDirection is built into PHP, libraries can accept it in their public APIs without needing adapter code.
Learn more about this feature in The PHP Foundation’s blog.
', + 'stream_error_handling_title' => 'Stream Error Handling', + 'stream_error_handling_description' => 'Stream operations can now be configured to throw aStreamException or to fail silently instead of emitting warnings. Errors are reported as structured StreamError objects with a StreamErrorCode enum case, the wrapper name, and the affected path or URL, and can also be retrieved later with stream_last_errors() or passed to a custom error handler.',
+ 'doc_comments_title' => 'DocComments For Function Parameters',
+ 'doc_comments_description' => 'Function and method parameters can now have their own DocComments, which are available via the new ReflectionParameter::getDocComment() method. This allows each parameter to be documented right next to its declaration, without repeating its name and type in a @param tag.',
+ 'isreadable_iswriteable_title' => 'New ReflectionProperty::isReadable() and ReflectionProperty::isWritable() methods',
+ 'isreadable_iswriteable_description' => 'With readonly properties, asymmetric visibility, and property hooks, checking whether a property is public is no longer enough to know whether it can be read or written. The new methods answer this directly for a given scope, and optionally for a specific object, taking into account visibility, initialization state, hooks, and magic methods.',
+
+ 'new_classes_title' => 'Additional features and improvements',
+ 'new_override_constants' => 'The #[\Override] attribute can now be applied to class constants and enum cases.',
+ 'new_enum_debug_info' => 'Enums can now implement the __debugInfo() magic method.',
+ 'new_const_object_writes' => 'Properties of objects stored in constants can now be modified directly, e.g. Config::DEFAULTS->timeout = 30.',
+ 'new_uri_builder' => 'New Uri\Rfc3986\UriBuilder and Uri\WhatWg\UrlBuilder classes build URIs from their components, along with new methods for detecting URI and host types and a Uri\WhatWg\url_percent_encode() function.',
+ 'new_sodium' => 'The Sodium extension adds post-quantum key encapsulation (X-Wing and ML-KEM-768), IP address encryption, and the SHAKE and TurboSHAKE extendable-output functions.',
+ 'new_tls' => 'TLS streams now support session resumption, external pre-shared keys, and TLS 1.3 early data (0-RTT).',
+ 'new_mysqli_quote_string' => 'New mysqli::quote_string() method escapes a string and wraps it in quotes, matching PDO::quote().',
+ 'new_pack_endianness' => 'pack() and unpack() now accept the < and > endianness modifiers on integer and float format codes.',
+ 'new_json_error_location' => 'JSON error messages now include the location of the error in the input.',
+ 'new_error_include_args' => 'The new error_include_args INI setting consistently includes function arguments in error messages.',
+ 'new_intl' => 'New grapheme_strrev() function reverses strings by grapheme cluster, and the new IntlNumberRangeFormatter class formats ranges of numbers.',
+ 'new_zip' => 'New ZipArchive::openString() and ZipArchive::closeString() methods work with in-memory archives.',
+ 'new_performance' => 'Performance improvements include compiling array_map() with first-class callable or partial application callbacks into loops, faster printf() calls, caching of stateless closures, and faster JSON encoding.',
+
+ 'bc_title' => 'Deprecations and backward compatibility breaks',
+ 'bc_return_in_finally' => 'Using return inside a finally block is now deprecated, as it silently discards exceptions and overrides values returned from the try or catch block.',
+ 'bc_constructor_return' => 'Returning a value from __construct() or __destruct() and making them generators is now deprecated. Declaring a nullable return type for __debugInfo() is also deprecated.',
+ 'bc_reserved_identifiers' => 'Using let or is as the name of a class, function, or constant is now deprecated. Using _ as a constant name, namespace as a class constant name, or readonly as a function name is also deprecated.',
+ 'bc_mbregex' => 'The mbstring regular expression functions such as mb_ereg() and mb_split() have been deprecated, as the underlying Oniguruma library is no longer maintained. PCRE functions with the u modifier can be used instead.',
+ 'bc_type_aliases' => 'The is_double(), is_long(), is_integer(), and doubleval() aliases have been deprecated. Use is_float(), is_int(), and floatval() instead.',
+ 'bc_spl_object_hash' => 'spl_object_hash() has been deprecated in favor of spl_object_id(), and spl_classes() in favor of ReflectionExtension::getClassNames().',
+ 'bc_objects_as_arrays' => 'Passing an object where an array is expected to array_walk(), array_walk_recursive(), http_build_query(), mb_convert_variables(), and compression functions and filters is now deprecated. Use get_object_vars() to convert the object first.',
+ 'bc_strcoll' => 'strcoll() and the SORT_LOCALE_STRING sort flag have been deprecated. Use the Collator class from the intl extension instead.',
+ 'bc_ignored_arguments' => 'Passing a third argument to define() is now deprecated, as is calling is_a() or is_subclass_of() with a class name string when $allow_string is false.',
+ 'bc_php_filter' => 'Using more than 16 filters in a php://filter URL without setting the filter.max_filter_count context option is now deprecated.',
+ 'bc_session_defaults' => 'Sessions are now more secure by default: session.use_strict_mode and session.cookie_httponly are enabled, and session.cookie_samesite is set to Lax.',
+ 'bc_session_handlers' => 'Custom session handlers that do not implement both create_sid() and validateId() are now deprecated.',
+ 'bc_other_deprecations' => 'The metaphone(), mysqli_get_charset(), and mysqli_stmt_init() functions are now deprecated, along with the CSV methods of SplFileObject and the sorting, flag, and serialization methods of ArrayIterator.',
+ 'bc_trim_form_feed' => 'trim(), ltrim(), and rtrim() now also strip form feed (\f) characters by default.',
+ 'bc_stream_close_errors' => 'fclose(), file_put_contents(), and copy() now return false when flushing or closing the stream fails, instead of silently ignoring the failure.',
+ 'bc_value_errors' => 'Many functions now throw a ValueError for out-of-range values, invalid flags, or strings containing NUL bytes, instead of silently truncating or ignoring them.',
+
+ 'footer_title' => 'Better syntax, improved performance and type safety.',
+ 'footer_description' => 'The full list of changes is recorded in the ChangeLog.
Please consult the migration guide for a detailed list of new features and backward-incompatible changes.
', +]; diff --git a/public/releases/8.6/languages/ru.php b/public/releases/8.6/languages/ru.php new file mode 100644 index 0000000000..6d168ea5f1 --- /dev/null +++ b/public/releases/8.6/languages/ru.php @@ -0,0 +1,79 @@ + 'PHP 8.6 — большое обновление языка PHP с новыми возможностями, включая частичное применение функций, новый класс Duration, Polling API и новую функцию clamp()', + 'main_title' => 'Лучше, быстрее, надолго', + 'main_subtitle' => 'PHP 8.6 — большое обновление языка PHP. Оно содержит новые возможности, включая частичное применение функций, новый класс Duration, Polling API и новую функцию clamp().
', + + 'whats_new' => 'Что нового в 8.6', + 'upgrade_now' => 'Переходите на PHP 8.6!', + 'old_version' => 'PHP 8.5 и ранее', + 'badge_new' => 'Новинка', + 'documentation' => 'Документация', + 'released' => 'Будет выпущен 19 ноября 2026', + 'release_unavailable_reason' => 'PHP 8.6 ещё не выпущен. Релиз запланирован на 19 ноября 2026 года.', + 'key_features' => 'Основные возможности PHP 8.6', + 'key_features_description' => 'Быстрее, лучше, доступнее для разработчиков.
', + + 'features_pfa_description' => 'Позволяет вызывать функции, передавая лишь часть обязательных параметров, а остальные — позже.
', + 'features_readonly_property_defaults_description' => 'Позволяет задавать значения по умолчанию для readonly-свойств экземпляра.
', + 'features_polling_api_description' => 'Масштабируемое мультиплексирование ввода-вывода на основе epoll, kqueue и других нативных механизмов — для библиотек событийных циклов вроде ReactPHP и AMPHP.
', + 'features_clamp_description' => 'Гарантирует, что значение (числовое или любое другое) находится в заданном диапазоне.
', + 'features_duration_description' => 'Класс Duration представляет прошедшее время, измеренное секундомером.
', + 'features_sort_direction_description' => 'SortDirection — перечисление с двумя вариантами (Ascending и Descending) и без связанного поведения.
', + + 'pfa_title' => 'Частичное применение функций', + 'pfa_description' => 'Позволяет вызывать функции, передавая лишь часть обязательных параметров, а остальные — позже.', + 'readonly_property_defaults_title' => 'Значения по умолчанию для readonly-свойств', + 'readonly_property_defaults_description' => 'Позволяет задавать значения по умолчанию для readonly-свойств экземпляра.', + 'polling_api_title' => 'Polling API', + 'polling_api_description' => 'Новый APIIo\Poll эффективно отслеживает множество потоков одновременно, используя лучший механизм, доступный на каждой платформе (epoll, kqueue, event ports или WSAPoll), и не упирается в ограничения масштабируемости stream_select(). Он задуман как общая основа, на которой могут строиться библиотеки событийных циклов, такие как ReactPHP и AMPHP.',
+ 'clamp_title' => 'Новая функция clamp()',
+ 'clamp_description' => 'Гарантирует, что заданное значение (числовое или любое другое) находится в указанном диапазоне. В противном случае возвращается ближайшее значение в пределах границ диапазона.',
+ 'duration_title' => 'Новый класс \Time\Duration',
+ 'duration_description' => 'Класс Duration представляет прошедшее время, измеренное секундомером. Его представление не привязано ни к какому времени и часовому поясу и позволяет выразить диапазон более чем в 250 лет с точностью до наносекунды. Поэтому он отлично подходит для выразительного представления таймаутов или результатов бенчмарков.',
+ 'sort_direction_title' => 'Новое перечисление SortDirection',
+ 'sort_direction_description' => 'SortDirection — перечисление с двумя вариантами (Ascending и Descending) и без связанного поведения.
Подробнее об этой возможности — в блоге PHP Foundation.
', + 'stream_error_handling_title' => 'Обработка ошибок в потоках', + 'stream_error_handling_description' => 'Теперь операции с потоками можно настроить так, чтобы они выбрасывалиStreamException или тихо завершались с ошибкой вместо вывода предупреждений. Ошибки сообщаются в виде структурированных объектов StreamError с вариантом перечисления StreamErrorCode, именем обёртки и затронутым путём или URL; их также можно получить позже через stream_last_errors() или передать собственному обработчику ошибок.',
+ 'doc_comments_title' => 'DocComments для параметров функций',
+ 'doc_comments_description' => 'Параметры функций и методов теперь могут иметь собственные DocComments, доступные через новый метод ReflectionParameter::getDocComment(). Это позволяет документировать каждый параметр прямо рядом с его объявлением, не повторяя его имя и тип в теге @param.',
+ 'isreadable_iswriteable_title' => 'Новые методы ReflectionProperty::isReadable() и ReflectionProperty::isWritable()',
+ 'isreadable_iswriteable_description' => 'С появлением readonly-свойств, асимметричной видимости и хуков свойств проверки на public уже недостаточно, чтобы понять, можно ли прочитать свойство или записать в него. Новые методы отвечают на этот вопрос напрямую для заданной области видимости — и при необходимости для конкретного объекта, — учитывая видимость, состояние инициализации, хуки и магические методы.',
+
+ 'new_classes_title' => 'Дополнительные возможности и улучшения',
+ 'new_override_constants' => 'Атрибут #[\Override] теперь можно применять к константам классов и вариантам перечислений.',
+ 'new_enum_debug_info' => 'Перечисления теперь могут реализовывать магический метод __debugInfo().',
+ 'new_const_object_writes' => 'Свойства объектов, хранящихся в константах, теперь можно изменять напрямую, например: Config::DEFAULTS->timeout = 30.',
+ 'new_uri_builder' => 'Новые классы Uri\Rfc3986\UriBuilder и Uri\WhatWg\UrlBuilder собирают URI из компонентов. Кроме того, добавлены методы для определения типов URI и хостов и функция Uri\WhatWg\url_percent_encode().',
+ 'new_sodium' => 'Модуль Sodium получил постквантовое инкапсулирование ключей (X-Wing и ML-KEM-768), шифрование IP-адресов и расширяемые выходные функции SHAKE и TurboSHAKE.',
+ 'new_tls' => 'TLS-потоки теперь поддерживают возобновление сессий, внешние предварительно общие ключи (PSK) и ранние данные TLS 1.3 (0-RTT).',
+ 'new_mysqli_quote_string' => 'Новый метод mysqli::quote_string() экранирует строку и заключает её в кавычки, как PDO::quote().',
+ 'new_pack_endianness' => 'pack() и unpack() теперь принимают модификаторы порядка байтов < и > в кодах формата целых чисел и чисел с плавающей точкой.',
+ 'new_json_error_location' => 'Сообщения об ошибках JSON теперь включают место ошибки во входных данных.',
+ 'new_error_include_args' => 'Новая INI-настройка error_include_args последовательно включает аргументы функций в сообщения об ошибках.',
+ 'new_intl' => 'Новая функция grapheme_strrev() переворачивает строки по графемным кластерам, а новый класс IntlNumberRangeFormatter форматирует диапазоны чисел.',
+ 'new_zip' => 'Новые методы ZipArchive::openString() и ZipArchive::closeString() работают с архивами в памяти.',
+ 'new_performance' => 'Среди улучшений производительности — компиляция array_map() с callback-ами первого класса или частичным применением в циклы, более быстрые вызовы printf(), кеширование замыканий без состояния и ускоренное кодирование JSON.',
+
+ 'bc_title' => 'Устаревшая функциональность и изменения в обратной совместимости',
+ 'bc_return_in_finally' => 'Использование return внутри блока finally объявлено устаревшим: оно молча отбрасывает исключения и перекрывает значения, возвращённые из блока try или catch.',
+ 'bc_constructor_return' => 'Возврат значения из __construct() или __destruct() и превращение их в генераторы объявлены устаревшими. Объявление nullable-типа возврата для __debugInfo() также устарело.',
+ 'bc_reserved_identifiers' => 'Использование let или is в качестве имени класса, функции или константы объявлено устаревшим. Также устарело использование _ как имени константы, namespace как имени константы класса и readonly как имени функции.',
+ 'bc_mbregex' => 'Регулярные функции mbstring, такие как mb_ereg() и mb_split(), объявлены устаревшими, поскольку лежащая в их основе библиотека Oniguruma больше не поддерживается. Вместо них можно использовать функции PCRE с модификатором u.',
+ 'bc_type_aliases' => 'Псевдонимы is_double(), is_long(), is_integer() и doubleval() объявлены устаревшими. Используйте is_float(), is_int() и floatval().',
+ 'bc_spl_object_hash' => 'Функция spl_object_hash() объявлена устаревшей в пользу spl_object_id(), а spl_classes() — в пользу ReflectionExtension::getClassNames().',
+ 'bc_objects_as_arrays' => 'Передача объекта туда, где ожидается массив, в array_walk(), array_walk_recursive(), http_build_query(), mb_convert_variables(), а также в функции и фильтры сжатия объявлена устаревшей. Сначала преобразуйте объект с помощью get_object_vars().',
+ 'bc_strcoll' => 'Функция strcoll() и флаг сортировки SORT_LOCALE_STRING объявлены устаревшими. Вместо них используйте класс Collator из модуля intl.',
+ 'bc_ignored_arguments' => 'Передача третьего аргумента в define() объявлена устаревшей, как и вызов is_a() или is_subclass_of() со строкой имени класса, когда $allow_string равен false.',
+ 'bc_php_filter' => 'Использование более 16 фильтров в URL php://filter без установки контекстной опции filter.max_filter_count объявлено устаревшим.',
+ 'bc_session_defaults' => 'Сессии теперь безопаснее по умолчанию: включены session.use_strict_mode и session.cookie_httponly, а для session.cookie_samesite задано значение Lax.',
+ 'bc_session_handlers' => 'Пользовательские обработчики сессий, не реализующие одновременно create_sid() и validateId(), объявлены устаревшими.',
+ 'bc_other_deprecations' => 'Функции metaphone(), mysqli_get_charset() и mysqli_stmt_init() объявлены устаревшими, как и CSV-методы SplFileObject и методы сортировки, работы с флагами и сериализации ArrayIterator.',
+ 'bc_trim_form_feed' => 'trim(), ltrim() и rtrim() теперь по умолчанию удаляют и символ перевода страницы (\f).',
+ 'bc_stream_close_errors' => 'fclose(), file_put_contents() и copy() теперь возвращают false, если сброс или закрытие потока завершилось ошибкой, вместо того чтобы молча её игнорировать.',
+ 'bc_value_errors' => 'Многие функции теперь выбрасывают ValueError при выходе значения за диапазон, недопустимых флагах или строках с NUL-байтами, вместо того чтобы молча обрезать или игнорировать их.',
+
+ 'footer_title' => 'Выше производительность, лучше синтаксис, надёжнее система типов.',
+ 'footer_description' => 'Полный список изменений приведён в ChangeLog.
Подробный список новых возможностей и изменений, ломающих обратную совместимость, смотрите в руководстве по миграции.
', +]; diff --git a/public/releases/8.6/release.inc b/public/releases/8.6/release.inc new file mode 100644 index 0000000000..d04bba0db5 --- /dev/null +++ b/public/releases/8.6/release.inc @@ -0,0 +1,601 @@ + version_compare($version, '8.6', '>='), + ); + PHP, + after: <<<'PHP' + $versions = ['8.4', '8.5', '8.6', '8.7', '9.0']; + + $supported = array_filter( + $versions, + version_compare(?, '8.6', '>='), + ); + PHP, + ), + new FeatureComparison( + id: 'duration-class', + title: message('duration_title', $lang), + description: message('duration_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/duration_class', + message('documentation', $lang) . "|/manual/$documentation/class.time-duration.php", + ], + before: <<<'PHP' + /** + * All delays are in microseconds. + */ + function backoff( + int $baseDelay, + int $step, + int $attempt, + ): void { + $delay = $baseDelay + ($step * (2 ** $attempt)); + + // Wait at most 30 seconds. + usleep(min($delay, 30_000_000)); + } + + // 1 second base delay, plus 100 milliseconds + // doubling with each attempt. + backoff(1_000_000, 100_000, $attempt); + PHP, + after: <<<'PHP' + use Time\Duration; + + function backoff( + Duration $baseDelay, + Duration $step, + int $attempt, + ): void { + $delay = $baseDelay->add($step->multiplyBy(2 ** $attempt)); + + // Durations are comparable, so min() works directly. + $delay = min($delay, Duration::fromSeconds(30)); + + time_nanosleep($delay->seconds, $delay->nanoseconds); + } + + backoff( + Duration::fromSeconds(1), + Duration::fromMilliseconds(100), + $attempt, + ); + + // Preconfigure the delays using Partial Function Application. + $waitBeforeRetry = backoff( + Duration::fromSeconds(1), + Duration::fromMilliseconds(100), + attempt: ?, + ); + $waitBeforeRetry($attempt); + PHP, + ), + new FeatureComparison( + id: 'polling-api', + title: message('polling_api_title', $lang), + description: message('polling_api_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/poll_api', + ], + before: <<<'PHP' + $server = stream_socket_server('tcp://0.0.0.0:8080'); + $clients = []; + + while (true) { + $read = [$server, ...$clients]; + $write = $except = null; + + // Based on select(), which typically can't handle + // more than 1024 connections + stream_select($read, $write, $except, null); + + foreach ($read as $stream) { + if ($stream === $server) { + $clients[] = stream_socket_accept($server); + continue; + } + + $data = fread($stream, 8192); + + if ($data === '' || $data === false) { + $key = array_search($stream, $clients, true); + unset($clients[$key]); + fclose($stream); + } else { + fwrite($stream, $data); + } + } + } + PHP, + after: <<<'PHP' + use Io\Poll\{Context, Event}; + + $server = stream_socket_server('tcp://0.0.0.0:8080'); + + // Automatically uses epoll, kqueue, event ports, or WSAPoll + $poll = new Context(); + $poll->add(new StreamPollHandle($server), [Event::Read]); + + while (true) { + foreach ($poll->wait() as $watcher) { + $stream = $watcher->getHandle()->getStream(); + + if ($stream === $server) { + $client = stream_socket_accept($server); + $poll->add( + new StreamPollHandle($client), + [Event::Read], + ); + continue; + } + + $data = fread($stream, 8192); + + if ($data === '' || $data === false) { + $watcher->remove(); + fclose($stream); + } else { + fwrite($stream, $data); + } + } + } + PHP, + ), + new FeatureComparison( + id: 'stream-error-handling', + title: message('stream_error_handling_title', $lang), + description: message('stream_error_handling_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/stream_errors', + ], + before: <<<'PHP' + $config = @file_get_contents('/etc/app/config.json'); + + if ($config === false) { + // Only an unstructured message string is available + $error = error_get_last(); + log_error($error['message']); + } + PHP, + after: <<<'PHP' + $context = stream_context_create([ + 'stream' => [ + 'error_mode' => StreamErrorMode::Exception, + ], + ]); + + try { + $config = file_get_contents( + '/etc/app/config.json', + context: $context, + ); + } catch (StreamException $e) { + foreach ($e->getErrors() as $error) { + // $error->code is a StreamErrorCode enum case + log_error( + $error->code->name, + $error->message, + $error->wrapperName, + ); + } + } + PHP, + ), + new FeatureComparison( + id: 'clamp-function', + title: message('clamp_title', $lang), + description: message('clamp_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/clamp_v2', + ], + before: <<<'PHP' + var_dump(max(0, min(-10, 100))); + // int(0) + + var_dump(max(0, min(50, 100))); + // int(50) + + var_dump(max(0, min(110, 100))); + // int(100) + PHP, + after: <<<'PHP' + var_dump(clamp(-10, 0, 100)); + // int(0) + + var_dump(clamp(50, 0, 100)); + // int(50) + + var_dump(clamp(110, 0, 100)); + // int(100) + + // Any comparable value works with clamp(). This + // includes the new Duration class. + var_dump(clamp( + \Time\Duration::fromSeconds(30), + min: \Time\Duration::fromMinutes(1), + max: \Time\Duration::fromMinutes(10), + )->seconds); + // int(60) + PHP, + ), + new FeatureComparison( + id: 'sort-direction-enum', + title: message('sort_direction_title', $lang), + description: message('sort_direction_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/sort_direction_enum', + message('documentation', $lang) . "|/manual/$documentation/enum.sortdirection.php", + ], + before: <<<'PHP' + class QueryBuilder + { + private array $orderBy = []; + + public function orderBy( + string $column, + int $direction = SORT_ASC, + ): static { + $this->orderBy[] = $column . ' ' . match ($direction) { + SORT_ASC => 'ASC', + SORT_DESC => 'DESC', + }; + + return $this; + } + } + + $qb->orderBy('name', SORT_DESC); + $qb->orderBy('name', SORT_STRING); + // Accepted by the signature, then fails inside the method: + // UnhandledMatchError: Unhandled match case 2 + PHP, + after: <<<'PHP' + class QueryBuilder + { + private array $orderBy = []; + + public function orderBy( + string $column, + SortDirection $direction = SortDirection::Ascending, + ): static { + $this->orderBy[] = $column . ' ' . match ($direction) { + SortDirection::Ascending => 'ASC', + SortDirection::Descending => 'DESC', + }; + + return $this; + } + } + + $qb->orderBy('name', SortDirection::Descending); + $qb->orderBy('name', SORT_STRING); + // TypeError: QueryBuilder::orderBy(): Argument #2 ($direction) + // must be of type SortDirection, int given + PHP, + ), + new FeatureComparison( + id: 'doc-comments', + title: message('doc_comments_title', $lang), + description: message('doc_comments_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/parameter-doccomments', + ], + before: <<<'PHP' + class DB + { + /** + * Returns up to $limit items matching the $query. + * + * @param string $query Terms to search + * @param int $limit Maximum number of results + */ + public function search(string $query, int $limit = 10): array + { + return []; + } + } + + // Parameter descriptions can only be extracted + // by parsing the function's DocComment. + PHP, + after: <<<'PHP' + class DB + { + /** + * Returns up to $limit items matching the $query. + */ + public function search( + /** Terms to search */ + string $query, + + /** Maximum number of results */ + int $limit = 10, + ): array { + return []; + } + } + + var_dump( + new ReflectionParameter([DB::class, 'search'], 'query') + ->getDocComment(), + ); + // string(22) "/** Terms to search */" + PHP, + ), + new FeatureComparison( + id: 'isreadable-iswriteable', + title: message('isreadable_iswriteable_title', $lang), + description: message('isreadable_iswriteable_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/isreadable-iswriteable', + ], + before: '', + after: <<<'PHP' + class NewsEntry + { + public string $title = 'PHP 8.6 released!'; + + public private(set) string $slug = 'php-86-released'; + } + + $entry = new NewsEntry(); + foreach (['title', 'slug'] as $item) { + $property = new ReflectionProperty(NewsEntry::class, $item); + printf( + "%s: isReadable=%s isWritable=%s\n", + $item, + $property->isReadable(null, $entry) ? 'yes' : 'no', + $property->isWritable(null, $entry) ? 'yes' : 'no', + ); + } + // title: isReadable=yes isWritable=yes + // slug: isReadable=yes isWritable=no + PHP, + ), + new FeatureComparison( + id: 'readonly-property-defaults', + title: message('readonly_property_defaults_title', $lang), + description: message('readonly_property_defaults_description', $lang), + links: [ + 'RFC|https://wiki.php.net/rfc/readonly_property_defaults', + ], + before: <<<'PHP' + interface Rule + { + public string $parser { get; } + } + + final readonly class SlugRule implements Rule + { + public string $parser; + + public function __construct() + { + $this->parser = SlugParser::class; + } + } + PHP, + after: <<<'PHP' + interface Rule + { + public string $parser { get; } + } + + final readonly class SlugRule implements Rule + { + public string $parser = SlugParser::class; + } + PHP, + ), +]; + +echo ReleasePage::getHeroSection( + title: message('main_title', $lang), + subtitle: message('main_subtitle', $lang), + logoSvg: <<<'SVG' + + SVG, + upgradeNow: message('upgrade_now', $lang), + whatsNew: message('whats_new', $lang), + released: message('released', $lang), + isReleaseAvailable: false, + unavailableReason: message('release_unavailable_reason', $lang), +); +?> + +' . $unavailableReason . '
'; + } + if (!str_starts_with($subtitle, '')) { $subtitle = '
' . $subtitle . '
'; } @@ -63,17 +74,27 @@ public static function getHeroSection(' . $unavailableReason . '
'; + } + return <<