Giter Club home page Giter Club logo

Comments (6)

sstalle avatar sstalle commented on August 18, 2024 1

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.

sstalle avatar sstalle commented on August 18, 2024

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.

reedy avatar reedy commented on August 18, 2024

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.

reedy avatar reedy commented on August 18, 2024

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.

reedy avatar reedy commented on August 18, 2024

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.

reedy avatar reedy commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.