squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

PSR1 SideEffectsSniff sees declare() statements as side effects #502

Closed cryptiklemur closed 9 years ago

cryptiklemur commented 9 years ago

RFC for reference: https://wiki.php.net/rfc/scalar_type_hints_v5

Doesn't necessarily need to be fixed now, but should definitely be fixed before 7.0 (assuming the RFC passes).

When adding declare(strict_types=1); causes phpcs to throw a warning on the PSR-2 Standard.

  1 | WARNING | [ ] A file should declare new symbols (classes,
    |         |     functions, constants, etc.) and cause no other
    |         |     side effects, or it should execute logic with
    |         |     side effects, but should not do both. The first
    |         |     symbol is defined on line 23 and the first side
    |         |     effect is on line 3.
aik099 commented 9 years ago

I guess declare function call should be allowed in general, because it also allows for PHP script to listen for ticks.

cryptiklemur commented 9 years ago

Yeah, thats another area i've seen it happen.

gsherwood commented 9 years ago

I've got this sniff to ignore declare statements now, so shouldn't matter what happens with the RFC.

cryptiklemur commented 9 years ago

So... Fixed? Thanks :)

gsherwood commented 9 years ago

Yep, fixed now.