Skip to content

Conversation

gharlan
Copy link
Member

@gharlan gharlan commented Jul 12, 2025

Static variables with static content (e.g., static string or static array) appear to be slower than non-static variables or without any variables.

Also note that code without static variables is better for static analysis. That's why we get two new entries for phpstan baseline where phpstan knows for sure now how the array is structured.

@coveralls
Copy link

coveralls commented Jul 12, 2025

Coverage Status

coverage: 94.755% (-0.03%) from 94.78%
when pulling 7b57a17 on gharlan:static-var
into 8092394 on PHP-CS-Fixer:master.

@gharlan gharlan changed the title chore: do not use static variables for static content chore: remove useless static variables for static content Jul 12, 2025
@keradus keradus changed the title chore: remove useless static variables for static content chore: remove useless static variables for const content Jul 12, 2025
@gharlan

This comment was marked as outdated.

Copy link
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(partial review, just to give some direction)

@keradus
Copy link
Member

keradus commented Jul 15, 2025

good job @gharlan , thank you

@keradus keradus enabled auto-merge (squash) July 15, 2025 15:14
static $castTokens = [\T_ARRAY_CAST, \T_BOOL_CAST, \T_DOUBLE_CAST, \T_INT_CAST, \T_OBJECT_CAST, \T_STRING_CAST, \T_UNSET_CAST];

return $castTokens;
return [\T_ARRAY_CAST, \T_BOOL_CAST, \T_DOUBLE_CAST, \T_INT_CAST, \T_OBJECT_CAST, \T_STRING_CAST, \T_UNSET_CAST];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think, should we deprecate the methods getCastTokenKinds, getClassyTokenKinds and getObjectOperatorKinds and introduce public constants instead?
(if yes, I would do this in a new pull request)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh - no.
ie, deprecating sounds OKish, but new way doesn't sound good out of the blue.
I believe Token class is cluttered and I want to avoid introducing new elements to it without high-overview plan how to clean the class in total. [ie, avoid multiple migration steps]

@keradus keradus merged commit 56adb61 into PHP-CS-Fixer:master Jul 15, 2025
30 of 31 checks passed
@gharlan gharlan deleted the static-var branch July 15, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants