Comments (6)
Thank you for the examples. I think I've fixed most of the issues in 7bd1d16, except for
File: /home/reedy/mediawiki/includes/GlobalFunctions.php
> Line 1420: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
Fixing that requires reflecting on user-defined classes without loading them, which php7cc currently doesn't do. I'll think about integrating a library like roave/better-reflection
for that, but it won't happen, most likely, as it will have an adverse performance impact.
from php7cc.
You are right, it just checks if a certain statement/call occurs before func_get_args
in a function, so it's very imprecise. I have some ideas on how to improve this, and having real world examples would be very helpful to validate these ideas.
from php7cc.
Cool. I'll go through the ones I've been given for MW/MW extensions, and try and get a list of "easy" to detect false positives, through to the more complex ones, but are still false +ve
Of course, a workaround for this, code wise, is just to stash what's returned by func_get_args
into a variable as the first line in a function. Not great, but could be useful sometimes
Will get back to you in a bit
Thanks!
from php7cc.
https://github.com/wikimedia/mediawiki
So from mediawiki core I reckon these below should be identifiable as false positives. Some are more complex than others, but some are trivially simple
Where variables that are manipulated aren't already named parameters in the function definition... Or noting related is touched
Hope these are useful to find some test cases :)
File: /home/reedy/mediawiki/img_auth.php
> Line 192: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/img_auth.php#L192
File: /home/reedy/mediawiki/tests/phpunit/maintenance/MaintenanceTest.php
> Line 82: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/tests/phpunit/maintenance/MaintenanceTest.php#L82
File: /home/reedy/mediawiki/tests/phpunit/includes/api/query/ApiQueryTestBase.php
> Line 43: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/tests/phpunit/includes/api/query/ApiQueryTestBase.php#L43
File: /home/reedy/mediawiki/includes/htmlform/HTMLForm.php
> Line 958: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/htmlform/HTMLForm.php#L958
File: /home/reedy/mediawiki/includes/api/ApiAuthManagerHelper.php
> Line 387: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/api/ApiAuthManagerHelper.php#L387
File: /home/reedy/mediawiki/includes/parser/CoreParserFunctions.php
> Line 98: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/parser/CoreParserFunctions.php#L98
File: /home/reedy/mediawiki/includes/filerepo/ForeignDBRepo.php
> Line 134: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/filerepo/ForeignDBRepo.php#L134
File: /home/reedy/mediawiki/includes/filerepo/ForeignDBViaLBRepo.php
> Line 93: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/filerepo/ForeignDBViaLBRepo.php#L93
File: /home/reedy/mediawiki/includes/libs/rdbms/database/DBConnRef.php
> Line 163: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/libs/rdbms/database/DBConnRef.php#L163
File: /home/reedy/mediawiki/includes/libs/rdbms/database/Database.php
> Line 3206: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/libs/rdbms/database/Database.php#L3206
File: /home/reedy/mediawiki/includes/libs/objectcache/MultiWriteBagOStuff.php
> Line 182: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/libs/objectcache/MultiWriteBagOStuff.php#L182
File: /home/reedy/mediawiki/includes/media/MediaTransformOutput.php
> Line 307: [Warning] Function argument(s) returned by "func_get_arg" might have been modified
func_get_arg(5);
> Line 309: [Warning] Function argument(s) returned by "func_get_arg" might have been modified
func_get_arg(4);
https://github.com/wikimedia/mediawiki/blob/master/includes/media/MediaTransformOutput.php#L307
https://github.com/wikimedia/mediawiki/blob/master/includes/media/MediaTransformOutput.php#L309
File: /home/reedy/mediawiki/includes/specialpage/SpecialPage.php
> Line 749: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/specialpage/SpecialPage.php#L749
File: /home/reedy/mediawiki/includes/GlobalFunctions.php
> Line 1420: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
> Line 3003: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
> Line 3041: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/GlobalFunctions.php#L1420
https://github.com/wikimedia/mediawiki/blob/master/includes/GlobalFunctions.php#L3003
https://github.com/wikimedia/mediawiki/blob/master/includes/GlobalFunctions.php#L3041
File: /home/reedy/mediawiki/includes/exception/MWExceptionHandler.php
> Line 156: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/exception/MWExceptionHandler.php#L156
File: /home/reedy/mediawiki/includes/skins/BaseTemplate.php
> Line 36: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/skins/BaseTemplate.php#L36
File: /home/reedy/mediawiki/includes/SiteConfiguration.php
> Line 587: [Warning] Function argument(s) returned by "func_get_arg" might have been modified
func_get_arg($i);
https://github.com/wikimedia/mediawiki/blob/master/includes/SiteConfiguration.php#L587
File: /home/reedy/mediawiki/includes/specials/SpecialEditWatchlist.php
> Line 103: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/specials/SpecialEditWatchlist.php#L103
File: /home/reedy/mediawiki/includes/specials/SpecialImport.php
> Line 580: [Warning] Function argument(s) returned by "func_get_args" might have been modified
func_get_args();
https://github.com/wikimedia/mediawiki/blob/master/includes/specials/SpecialImport.php#L580
from php7cc.
Sweet. I think (not tested yet) you've fixed most of the SNR problems here, and a couple of "false positives" because of lack of knowledge of the actual code is ok.
In this case, we could easily get rid of the warning by swapping the code around
function wfMessage( $key /*...*/ ) {
$message = new Message( $key );
// We call Message::params() to reduce code duplication
$params = func_get_args();
array_shift( $params );
if ( $params ) {
call_user_func_array( [ $message, 'params' ], $params );
}
return $message;
}
to
function wfMessage( $key /*...*/ ) {
$params = func_get_args();
$message = new Message( $key );
// We call Message::params() to reduce code duplication
array_shift( $params );
if ( $params ) {
call_user_func_array( [ $message, 'params' ], $params );
}
return $message;
}
Which would clear the warning too.
Thanks! :)
from php7cc.
I don't know if you've tested it again against MediaWiki/some extensions... But I will do so and report back :)
from php7cc.
Related Issues (20)
- False positive: Cannot redeclare global function
- False positive: Namespace declaration statement has to be the very first statement
- False Positive: call static method on FQCN string
- PHP Fatal error: Cannot access private property HOT 1
- False Positive: [Error] Syntax error, unexpected T_SWITCH, expecting T_STRING on line 55. Processing aborted.
- Command "php7cc" is not defined. HOT 1
- Failed to catch: Fatal error: Cannot use $this as parameter in ... HOT 1
- Global composer config HOT 3
- Globbing patterns in Exclude HOT 1
- Is possible to turn specifics checks? HOT 1
- Backward incompatible changes for PHP7 too few function arguments are not detected HOT 3
- Unhelpful "Closing delimiter foo not found" message HOT 3
- Output result into a txt file HOT 2
- space between = and & fools the checker where =& would be caught
- Unquoted string as index or general not detected
- PHP nullable typehinting not supported now
- [Warning] "yield" usage in expression context HOT 1
- Error without a file: [Error] file_get_contents(): Filename cannot be empty. Processing aborted.
- Should "does not cause an error in PHP 7" be an warning? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php7cc.