-
-
Notifications
You must be signed in to change notification settings - Fork 204
Open
Labels
PHP: 8.0Status: to be implementedType: enhancementType: metaRepo strategy/structure relatedRepo strategy/structure related
Description
This is just an issue to keep track of which of the implemented RFCs for PHP 8.0 have been addressed.
This list should be updated when additional RFCs are accepted/implemented.
To Do
- Reclassifying engine warnings
Reevaluate the current level of various engine notices/warnings
Notes:- For the new "argument # must be passed by reference" warning: while we may not be able to detect this for userland functions, we should be able to use the list of PHP native functions combined with reflection to check if any arguments is expected to be passed by reference and trigger a warning if a non-variable is passed in that position.
Beware of changes in the PHP native function method signature across versions though! Reflection will only know the signature as per the PHP version the sniff is run on.
- For the new "argument # must be passed by reference" warning: while we may not be able to detect this for userland functions, we should be able to use the list of PHP native functions combined with reflection to check if any arguments is expected to be passed by reference and trigger a warning if a non-variable is passed in that position.
- Saner string to number comparison
Proposes to change non-strict comparisons between strings and numbers to behave more reasonably. - Saner numeric strings
- Make sorting stable
Make all sorts in PHP stable by default
Notes after initial RFC review (by @jrfnl):- There isn't really anything sniffable for the actual sorting change, as to determine whether this would be problematic depends on how and where the output of the sort is used, which is beyond basic static analysis.
- However... custom sorting functions returning a boolean value instead of an integer value are now deprecated and, up to a point, detecting those kind of custom sorting functions would be sniffable.
Notes for implementation:- Check the callback parameter of those sorting functions which take a callback.
- If the callback is a native PHP function, use reflection to get the return type.
- If the callback is a closure or arrow function (short closure), try to determine the type of the return value by looking for a return type in the closure signature and if not found, looking at all
returnstatements within the closure. - If the callback is a method in an anonymous class passed as the callback, find the method within the anonymous class (if available and not inherited from a parent class) and try to determine the type of the return value, potentially using the method docblock (if available) as a fallback if the type cannot be determined from a return type declaration or the return statement(s).
- If the callback is a method and the method is from the current class, find the method declaration and try to determine the return type.
- If the callback is a method and the sorting call is outside class or in another class, see if that class happens to be declared in the current file, find the method declaration and try to determine the return type.
- If the callback is a global or namespaced function, see if the declaration can be found in the current file and try to determine the return type.
This case will have the least chance of successfully determining the type. - If the return type could be determined and is boolean, throw a deprecation warning.
- Locale-independent float to string cast
- Change default PDO error mode
- Stricter type checks for arithmetic/bitwise operators
- throw expression
Convert throw statement into an expression - Always generate fatal error for incompatible method signatures
Resolve inconsistent handling of abstract and non-abstract methods during inheritance. - Always generate fatal error for incompatible method signatures
Resolve inconsistent handling of abstract and non-abstract methods during inheritance.
Notes after initial RFC review (by @jrfnl):- For classes implementing PHP native interfaces, a registry with the method signatures could be created and the signature of methods implementing the interface could be checked against the registry.
- IIRC PHP doesn't natively have any traits, but it would need to be checked if there are any abstract classes which need to be handled too.
- Having said that, this would still not be straight forward as the types in the signature declaration would need to be checked with LSP in mind, which comes with its own set of problems if the type is an OO type (we don't know the inheritance chain). That's of course, aside from the "simple" LSP issues which would need to be dealt with, like
intbeing contravariant withfloatandarraybeing co-variant with?arrayorarray|false. - For userland interfaces/traits/parent classes, the only case in which this could reliably be checked, is when the interface/trait and the class implementing the interface/using the trait would be declared in the same file, however, as it is uncommon to have multiple OO structures defined in the same file, as the fast majority of PHP projects adhere to PSR-4, this would be an edge case. Also see Signature of abstract methods defined in traits is checked against the implementing class method in php 8+ #1712
- All in all, it's probably not worth the time investment needed to write this sniff for the very, very few cases which could be detected.
- Arrays starting with a negative index
Proposes to make implicit array keys consistent. - Consistent type errors for internal functions
Consistently throw TypeError for parameter parsing failures of internal functions.
Notes:- For this, we'd need to build up a list of the functions and their parameters for which this change has been implemented and check the type of the parameter passed if hard-coded, ignore when variable, constant or output of function call. Can't use Reflection here as a lot of these were changed in PHP 8 and earlier PHP versions will not give the right information.
Mind: there are a lot of PRs in php-src to go through to find all the changes.
- For this, we'd need to build up a list of the functions and their parameters for which this change has been implemented and check the type of the parameter passed if hard-coded, ignore when variable, constant or output of function call. Can't use Reflection here as a lot of these were changed in PHP 8 and earlier PHP versions will not give the right information.
Aside from the RFCs, there are also the changes which were made outside of the RFC process and are listed in:
Claimed
- Ensure correct signatures of magic methods
Status: WIP, includes working on new upstream utility class to handle LSP in PHPCSUtils
Owner: @jrfnl - Treat namespaced names as single token
Status: WIP. This needs quite a lot of work, but PHPCSUtils will support helpers in the (near) future.
Owner: @jrfnl
Important note: in PHPCS, this change is "undone" in the 3.x branch and backfilled in the 4.x branch.
Changes which we'll need to account for in sniffs:NewConstants- the new token constants
Status: PR PHP 8.0: NewConstants: add some more new constants #1248ForbiddenNames- deal with reserved keywords now being allowed in namespace declarations.
Status: PR PHP 8.0 | ForbiddenNames: don't report reserved names in namespace declarations #1402- New sniff to check the whitespace around namespace separators. Whitespace and comments within namespaced names are no longer allowed.
Status: Nowhere near as easy as it sounds...., but ready, waiting for PHPCSUtils alpha4 before pulling - New sniff to detect use of the
T_STRINGtokens and throw an error that that is no longer sufficient to find identifier names.
This sniff will only be useful for a very limited public of sniff writers and other tooling authors who use the PHP Tokenizer extension. Even so, for that type of code, this is a significant change and a sniff to alert the user about it will be useful.
Status: WIP, this will probably need quite some code samples and defensive coding to prevent false positives when the tokens are examined individually (multi-part condition, cases inswitchetc). - Other than that and outside the scope of this issue, the code within most sniffs within PHPCompatibility itself will need to be updated to allow for the impact of this change. See issue PHP 8.0 compatibility: adjust sniffs to allow for new "namespaced name" tokens. #1226 for more details about that.
- Abstract trait method validation
Enforce signature of abstract trait methods.
Status: The "abstract private methods" part has been pulled as NewPHPCompatibility.FunctionDeclarations.AbstractPrivateMethodssniff #1149. Rest still needs to be evaluated for sniffability.
Owner: @jrfnl - Variable Syntax Tweaks
Fixes variable syntax edge cases.
=> Interpolated and non-interpolated strings has been pulled as PHP 8.0 | NewPHPCompatibility.Syntax.InterpolatedStringDereferencingsniff #1242 (@elazar).
=> Magic constant dereferencing sniff has been pulled as PHP 8.0: NewPHPCompatibility.Syntax.NewMagicConstantDereferencingsniff #1233 (@jrfnl).
=> Constant dereferencability has been pulled as PHP 5.6 / 8.0: NewConstantDereferencing: add support for constant array / object dereferencing #1263 (@elazar)
=> Class constant dereferencability has been pulled as PHP 8.0: NewNestedStaticAccess: add support for class constant dereferencing #1262 (@elazar).
=> "Arbitrary expression support for new and instanceof" still needs to be evaluated for sniffability.
Has PR
- Attributes - PR PHP 8.0 | New
NewAttributessniff #1279
Covers the following four RFCs:- Shorter Attribute Syntax Change
- Shorter Attribute Syntax
Use @@ instead of <<>> for attributes in PHP 8.0 - Attribute Amendments
Group Syntax, Rename PhpAttribute, Target Validation, Repeatable - Attributes (v2)
Add structured metadata to declarations (classes, functions, properties, constants) for internal and userland use-cases.
- Named Arguments - PR ✨ PHP 8.0 | New
NewNamedParameterssniff #1423
This RFC proposes introducing named arguments. - Nullsafe operator - PR PHP 8.0 : NewOperators account for nullsafe object operator #1210
Add new ?→ operator that skips null values - Allow trailing comma in closure use lists - PR PHP 8.0: NewTrailingComma: add check for trailing comma in closure use lists #1190
- Configurable string length in getTraceAsString() - PR PHP 8.0: NewIniDirectives: account for configurable string length in getTraceAsString() #1191
- Remove inappropriate inheritance signature checks on private methods - PR PHP 8.0: New
PHPCompatibility.FunctionDeclarations.ForbiddenFinalPrivateMethodssniff #1201
Proposes that inappropriate inheritance checks are removed for private methods
Review notes: The change in the inheritance checks themselves cannot be sniffed reliably as in nearly all cases the parent class and the child class won't be declared in the same file.
The only sniffable change I can see is the warning now thrown forfinal privatemethod declarations. (@jrfnl) - Match expression v2 - PRs PHP 8.0/8.1 | ForbiddenNames: detect use of new keywords when used as names #1415 (ForbiddenNames) + PHP 8.0: NewConstants: add some more new constants #1248 (NewConstants) + PHP 8.0: NewClasses: add yet more new classes #1246 (NewClasses) + PHP 8.0 | Keywords/NewKeywords: detect the new
matchkeyword (RFC) #1597 (NewKeywords)
Introduce match expression
Also see upstream issue PHP 8.0 | Add support for match expressions squizlabs/PHP_CodeSniffer#3037 - Constructor Property Promotion - PR ✨ PHP 8.0: New
PHPCompatibility.Classes.NewConstructorPropertyPromotionsniff #1417, PHP 8.0 | TypeDeclaration sniffs: examine properties declared in the constructor correctly #1447
Adds a short-hand syntax to combine declaration of properties and the constructor. - Unbundle ext/xmlrpc - PR PHP 8.0: account for removed extension XMLRPC #1161
- Non-capturing catches - PR PHP 8.0: New
PHPCompatibility.ControlStructures.NewNonCapturingCatchsniff #1151
Allow catching exceptions without a variable - Mixed type v2 - PR PHP 8.0: account for new mixed param/return/property type #1217 + PHP 8.0/8.1 | ForbiddenNames: detect use of new keywords when used as names #1415 (ForbiddenNames)
Add the mixed type - Add str_starts_with and str_ends_with to PHP - PR PHP 8.0: NewFunctions: handle 11 new functions #1197
- Allow trailing comma in parameter list - PR PHP 8.0: new
PHPCompatibility.FunctionDeclarations.NewTrailingCommasniff #1164 - Object-based token_get_all() alternative - PR PHP 8.0: NewClasses: handle 3 new classes #1211
Adds an object-based token_get_all() alternative, which is more ergonomic and uses less memory. - Stringable - PR PHP 8.0: NewInterfaces: add new Stringable interface to the sniff #1183
Allow usingstring|Stringableto expressstring|object-with-__toString(). - Allow ::class on objects - PR PHP 8.0: NewMagicClassConstant: detect ::class on objects #1166
Adds support for$object::class. - Static return type - PR PHP 8.0: NewReturnTypeDeclarations: allow for "static" return type #1152
Adds support forstaticas a return type. - Union Types v2 - PR PHP 8.0 | Add support for and detection of union types in param, return and property types #1444
A proposal to add union types - DOM Living Standard API - PR PHP 8.0 | NewInterfaces: add support for DOM living standard APIs related interfaces (RFC) #1595
Upgrade DOM API to latest standard version - JIT - PR PHP 8.0 | NewIniDirectives: recognize JIT related directives (RFC) #1598
Just in Time Compiler. - Weak maps - PR PHP 8.0: NewClasses: handle 3 new classes #1211
Add aWeakMapclass - str_contains - PR PHP 8.0: NewFunctions: handle 11 new functions #1197
Adds a new function to return whether or not a string is contained within another. - get_debug_type - PR PHP 8.0: NewFunctions: handle 11 new functions #1197
Adds a new function to return the true type name of a variable, automatically resolving class names. - Add support for CMS - PR PHP 8.0: NewFunctions/Constants: account for new OpenSSL CMS support #1182
Exposes CMS API from OpenSSL
Reviewed and concluded non-sniffable
- Don't automatically unserialize Phar metadata outside getMetadata()
Review: Unless and until PHPCompatibility would start examining method calls with object variable resolution, there is nothing in this RFC (or the related PR/commit) which is sniffable. - Always available JSON extension
Review: The only thing which would be sniffable would be to detect calls toextension_loaded('json')and the likes. Those calls are no longer necessary, but as those will continue to work without notices, this is not a PHPCompatibility issue.
Process
If anyone starts work on updating PHPCompatibility to handle any of these issues, please either update the above list (if you can) or leave a comment below, so one of the maintainers can update the list.
Once PHP 8.0 comes out, individual issues should be opened for the changes which remain at that point in time.
Metadata
Metadata
Assignees
Labels
PHP: 8.0Status: to be implementedType: enhancementType: metaRepo strategy/structure relatedRepo strategy/structure related