-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(php) Updates to keep pace with PHP 8.0 and 8.1 (#2997)
* [PHP] Add WeakMap class to internal list PHP 8.0 adds a new [`WeakMap` built-in class](https://php.watch/versions/8.0/weakmap). Adding it to `KEYWORDS.keyword` list. * [PHP] Add `UnhandledMatchError` exception type PHP 8.0 match expression throws an [`UnhandledMatchError` exception](https://php.watch/versions/8.0/match-expression#UnhandledMatchError). It's a new built-in exception type, and adding it the keywords list. * [PHP] Add new `mixed` type in PHP 8.0 PHP 8.0 adds a new [`mixed` type](https://php.watch/versions/8.0/mixed-type) as a new reserved keyword and a type. * [PHP] Add `Stringable` interface PHP 8.0 adds a new built-in interface called [`Stringable`](https://php.watch/versions/8.0/stringable). Adding it to the keywords list. * [PHP] Add `trait` to list of class-like naming patterns Traits follow [class-like syntax](https://www.php.net/manual/en/language.oop5.traits.php), and was missing from the class-like naming pattern matches. * [PHP] Update tests with a `match` expression * [PHP] Number pattern improvements Expands the number detection to support to all numerals supported up to PHP 8.1. - Decimal numbers - Floats - Binary numbers (`0b1100` and `0B1100`). - Hex number support (`0xAFAF` and `0XAFAF`). - Octal number support (`0777`) - [New `0o` and `0O` prefix support for Octals](https://php.watch/versions/8.1/explicit-octal-notation) (`0o777` and `0O777`) (Already accepted and merged to upcoming PHP 8.1) - Scientific notation (`7E-10` and `1.2e3`) - [Underscore number separator](https://php.watch/versions/7.4/underscore_numeric_separator) (Already implemented in PHP 7.4) * [PHP] Misc updates to CHANGES, AUTHORS, and SUPPORTED_LANGUAGES files
- Loading branch information
Showing
9 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<span class="hljs-meta"><?php</span> | ||
|
||
<span class="hljs-variable">$decimal</span> = <span class="hljs-number">12398</span>; | ||
<span class="hljs-variable">$binary</span> = <span class="hljs-number">0b10101</span>; | ||
<span class="hljs-variable">$binary_alt</span> = <span class="hljs-number">0B1001_0000_1111</span>; | ||
<span class="hljs-variable">$hex</span> = <span class="hljs-number">0x12AF</span>; | ||
<span class="hljs-variable">$hex_alt</span> = <span class="hljs-number">0X12_AF</span>; | ||
<span class="hljs-variable">$oct</span> = <span class="hljs-number">0o1234567</span>; | ||
<span class="hljs-variable">$oct_alt</span> = <span class="hljs-number">0O12_34_56_7</span>; | ||
<span class="hljs-variable">$oct_alt2</span> = <span class="hljs-number">0777_555</span>; | ||
<span class="hljs-variable">$sci</span> = <span class="hljs-number">1.2e3</span>; | ||
<span class="hljs-variable">$sci2</span> = <span class="hljs-number">7E-10</span>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
$decimal = 12398; | ||
$binary = 0b10101; | ||
$binary_alt = 0B1001_0000_1111; | ||
$hex = 0x12AF; | ||
$hex_alt = 0X12_AF; | ||
$oct = 0o1234567; | ||
$oct_alt = 0O12_34_56_7; | ||
$oct_alt2 = 0777_555; | ||
$sci = 1.2e3; | ||
$sci2 = 7E-10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<span class="hljs-meta"><?php</span> | ||
|
||
<span class="hljs-keyword">match</span> (<span class="hljs-variable">$key</span>) { | ||
<span class="hljs-number">1</span> => <span class="hljs-string">'Integer 1'</span>, | ||
<span class="hljs-string">'1'</span> => <span class="hljs-string">'String 1'</span>, | ||
<span class="hljs-literal">true</span> => <span class="hljs-string">'Bool true'</span>, | ||
[] => <span class="hljs-string">'Empty array'</span>, | ||
[<span class="hljs-number">1</span>] => <span class="hljs-string">'Array [1]'</span>, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
match ($key) { | ||
1 => 'Integer 1', | ||
'1' => 'String 1', | ||
true => 'Bool true', | ||
[] => 'Empty array', | ||
[1] => 'Array [1]', | ||
}; |