You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 return statements 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.
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 int being contravariant with float and array being co-variant with ?array or array|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.
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.
Aside from the RFCs, there are also the changes which were made outside of the RFC process and are listed in:
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:
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_STRING tokens 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 in switch etc).
Always available JSON extension Review: The only thing which would be sniffable would be to detect calls to extension_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.
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
Reevaluate the current level of various engine notices/warnings
Notes:
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.
Proposes to change non-strict comparisons between strings and numbers to behave more reasonably.
Make all sorts in PHP stable by default
Notes after initial RFC review (by @jrfnl):
Notes for implementation:
returnstatements within the closure.This case will have the least chance of successfully determining the type.
Convert throw statement into an expression
Resolve inconsistent handling of abstract and non-abstract methods during inheritance.
Resolve inconsistent handling of abstract and non-abstract methods during inheritance.
Notes after initial RFC review (by @jrfnl):
intbeing contravariant withfloatandarraybeing co-variant with?arrayorarray|false.Proposes to make implicit array keys consistent.
Consistently throw TypeError for parameter parsing failures of internal functions.
Notes:
Mind: there are a lot of PRs in php-src to go through to find all the changes.
Aside from the RFCs, there are also the changes which were made outside of the RFC process and are listed in:
Claimed
Status: WIP, includes working on new upstream utility class to handle LSP in PHPCSUtils
Owner: @jrfnl
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 constantsStatus: PR PHP 8.0: NewConstants: add some more new constants #1248
ForbiddenNames- 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
Status: Nowhere near as easy as it sounds...., but ready, waiting for PHPCSUtils alpha4 before pulling
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 in
switchetc).Enforce signature of abstract trait methods.
Status: The "abstract private methods" part has been pulled as New
PHPCompatibility.FunctionDeclarations.AbstractPrivateMethodssniff #1149. Rest still needs to be evaluated for sniffability.Owner: @jrfnl
Fixes variable syntax edge cases.
=> Interpolated and non-interpolated strings has been pulled as PHP 8.0 | New
PHPCompatibility.Syntax.InterpolatedStringDereferencingsniff #1242 (@elazar).=> Magic constant dereferencing sniff has been pulled as PHP 8.0: New
PHPCompatibility.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
NewAttributessniff #1279Covers the following four RFCs:
Use @@ instead of <<>> for attributes in PHP 8.0
Group Syntax, Rename PhpAttribute, Target Validation, Repeatable
Add structured metadata to declarations (classes, functions, properties, constants) for internal and userland use-cases.
NewNamedParameterssniff #1423This RFC proposes introducing named arguments.
Add new ?→ operator that skips null values
PHPCompatibility.FunctionDeclarations.ForbiddenFinalPrivateMethodssniff #1201Proposes 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 for
final privatemethod declarations. (@jrfnl)matchkeyword (RFC) #1597 (NewKeywords)Introduce match expression
Also see upstream issue PHP 8.0 | Add support for match expressions squizlabs/PHP_CodeSniffer#3037
PHPCompatibility.Classes.NewConstructorPropertyPromotionsniff #1417, PHP 8.0 | TypeDeclaration sniffs: examine properties declared in the constructor correctly #1447Adds a short-hand syntax to combine declaration of properties and the constructor.
PHPCompatibility.ControlStructures.NewNonCapturingCatchsniff #1151Allow catching exceptions without a variable
Add the mixed type
PHPCompatibility.FunctionDeclarations.NewTrailingCommasniff #1164Adds an object-based token_get_all() alternative, which is more ergonomic and uses less memory.
Allow using
string|Stringableto expressstring|object-with-__toString().Adds support for
$object::class.Adds support for
staticas a return type.A proposal to add union types
Upgrade DOM API to latest standard version
Just in Time Compiler.
Add a
WeakMapclassAdds a new function to return whether or not a string is contained within another.
Adds a new function to return the true type name of a variable, automatically resolving class names.
Exposes CMS API from OpenSSL
Reviewed and concluded non-sniffable
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.
Review: The only thing which would be sniffable would be to detect calls to
extension_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.