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

fix "strpos empty needle" warning #321

Conversation

nicoder
Copy link
Contributor

@nicoder nicoder commented Jun 17, 2020

fixes issue #320

a warning was issued in PositionCalculator#findPositionWithinString
when calling strpos on an empty value:

Warning: strpos(): Empty needle in
src/PHPSQLParser/positions/PositionCalculator.php on line 138

=> return false earlier in that case, to then throw an exception

fixes issue greenlion#320

a warning was issued in `PositionCalculator#findPositionWithinString`
when calling `strpos` on an empty value:

```
Warning: strpos(): Empty needle in
src/PHPSQLParser/positions/PositionCalculator.php on line 138
```

=> return `false` earlier in that case, to then throw an exception
@greenlion
Copy link
Owner

You should use backticks around help - the parser requires keywords used as identifiers to be quoted with backticks.

@greenlion greenlion closed this Oct 1, 2020
@greenlion greenlion reopened this Oct 1, 2020
@greenlion
Copy link
Owner

greenlion commented Oct 1, 2020

Test case fails on 5.4 with syntax error

PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting
identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in
/home/travis/build/greenlion/PHP-SQL-Parser/tests/cases/parser/issue320Test.php
on line 55
@nicoder
Copy link
Contributor Author

nicoder commented Oct 4, 2020

sorry, I did not see that failure at the time.

I adapted the test so it passes on PHP 5.4.

@greenlion
Copy link
Owner

I am pretty busy with other projects right now, but I'll give this a cursory test ASAP and merge. Thanks for the contribution!

@czoIg
Copy link
Contributor

czoIg commented Jul 6, 2022

Will this be merged?
In PHP >=8.0 the interpretation of var_dump(strpos('string', '')) is changed from

Warning: strpos(): Empty delimiter in /home/user/scripts/code.php on line 3
bool(false)

to

int(0)

https://onlinephp.io/c/ddb55

and it may end up with some unexpected results...

@greenlion greenlion merged commit c365130 into greenlion:master Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants