Skip to content
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

empty string passed to substr_compare produces warnings in AbstractPhpdocTypesFixer #6323

Closed
marcin-pragmagotech opened this issue Mar 2, 2022 · 1 comment · Fixed by #6327
Labels

Comments

@marcin-pragmagotech
Copy link

Hi, this problem came up when using ECS but refers to php-cs-fixer so I report here.

PHP version: 7.2
php-cs-fixer version: 3.6.0 (checked via PHP_CS_FIXER_IGNORE_ENV=-1 php vendor/symplify/easy-coding-standard/vendor/bin/php-cs-fixer -v)

PHP Warning:  substr_compare(): The start position cannot exceed initial string length in /var/www/symfony/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/src/AbstractPhpdocTypesFixer.php on line 105

Some empty strings are passed to the normalizeType() method so \substr_compare($type, '[]', -\strlen('[]')) produces warnings.

@SpacePossum
Copy link
Contributor

Hi and thanks for reporting 👍

I assume this code is brought inline by some compiler/optimizer, which is pretty cool TBH, wonder where that happens.
Anyway, the code seems to be coming from here:
https://github.com/symfony/polyfill/blob/v1.24.0/src/Php80/Php80.php#L101

I've made a PR to patch the issue here: symfony/polyfill#394

nicolas-grekas added a commit to symfony/polyfill that referenced this issue Mar 4, 2022
…ack (SpacePossum)

This PR was squashed before being merged into the 1.23-dev branch.

Discussion
----------

[Php80] Fix str_ends_with() when needle is longer than haystack

Little bug, found in PHP-CS-Fixer/PHP-CS-Fixer#6323

https://3v4l.org/oHUKH

```php
<?php
error_reporting(E_ALL);
$needle = '[]';
echo \substr_compare('', $needle, -\strlen($needle));
```

show issues for

```
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.17, 7.3.0 - 7.3.4
Warning: substr_compare(): The start position cannot exceed initial string length in /in/oHUKH on line 4
```

Looking at the test matrix I assume the tests will run latest 7.2 which is not effected,
~so I naively changed it here in this draft to see if my test indeeds fails on the CI (I don't have an easy 7.2.17 or 7.1.0 env. at hand at the moment)~ @ see shivammathur/setup-php#570

Commits
-------

09a94a5 [Php80] Fix str_ends_with() when needle is longer than haystack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants