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

"strpos(): Empty needle" warning when SQL query refers to a help table #320

Open
nicoder opened this issue Jun 17, 2020 · 0 comments
Open

Comments

@nicoder
Copy link
Contributor

nicoder commented Jun 17, 2020

hi,

when running this code example:

<?php

namespace PHPSQLParser;
require_once dirname(__FILE__) . '/../vendor/autoload.php';

$sql = 'SELECT * from help';
echo $sql . "\n";
try {
    $parser = new PHPSQLParser($sql, true);
} catch (\Exception $e) {
    echo "caught";
}

the following PHP warning is displayed:

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

Ideally the library would be able to parse such a query since MySQL can.

Alternatively it would be nice to avoid the warning.

nicoder added a commit to nicoder/PHP-SQL-Parser that referenced this issue Jun 17, 2020
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 pushed a commit that referenced this issue Jul 6, 2022
* fix "strpos empty needle" warning

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

* adapt test to make it compatible with PHP 5.4

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
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

No branches or pull requests

1 participant