-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix PHPStan undefined variable errors at level 3 #11189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
f86194a
8b93b41
30d971c
9d9dd59
e6bbbfc
eef6fa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ | |
| include WP_CONTENT_DIR . '/advanced-cache.php'; | ||
|
|
||
| // Re-initialize any hooks added manually by advanced-cache.php. | ||
| if ( $wp_filter ) { | ||
| if ( ! empty( $wp_filter ) ) { | ||
| $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); | ||
| } | ||
| } | ||
|
|
@@ -141,6 +141,7 @@ | |
| * @global string $table_prefix The database table prefix. | ||
| */ | ||
| if ( ! isset( $GLOBALS['table_prefix'] ) ) { | ||
| assert( isset( $table_prefix ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I don't understand this part, What u want to achieve here? phpstan's crying because if ( ! isset( $GLOBALS['table_prefix'] ) ) {
`$GLOBALS['table_prefix'] = $table_prefix ?? null;`
}Tested till php7.0, so should not break with any versions from last century... :D
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is for PHPStan, yes. Conventional wisdom is that The goal of using assert() was to reduce the cyclomatic complexity raised by @siliconforks in #11189 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx, in my opinion it's better to rly solve the issue instead of hiding it (may undefined variable). I think my recommendation above should be fine for that 👼 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Where is the actual issue, though? I don't see any issue here. By the time this code runs, both Is there some way that either
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand from the custom bootstrap code used by @Ninos, it's possible that Honestly, this would be extremely unlikely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @siliconforks the "issue" here is, that a variable can be undefined, which is at least a notice, but so an error. Also if it makes no sense to not set any of both variables (gobal or "local"), the code can throw a notice/error, from runtime perspective, this is some small anomaly :D In my opinions, it's cleaner code to not get any notices & errors, even if something is missconfigured or failed. It's not much improvements, but adding some small |
||
| $GLOBALS['table_prefix'] = $table_prefix; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May use
isset()instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be not the same though. Before it was checking for a truthy value, which is what
! empty()does. On the other hand,isset()would return true for an empty array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, true! I'm just trying to avoid non-strict type functions like
empty():D Following should also be possible, but what u prefer :-)if ( $wp_filter ?? null ) {