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

Uncaught TypeError: str_repeat() expects parameter 2 to be integery, null given #272

Closed
ibennetch opened this issue Dec 11, 2019 · 7 comments
Assignees
Labels

Comments

@ibennetch
Copy link
Member

Highlighting a query causes an error about str_repeat with current master.


Fatal error: Uncaught TypeError: str_repeat() expects parameter 2 to be integer, null given in /Users/isaacbennetch/Documents/svn/pma/sql-parser/src/Utils/Formatter.php:497
Stack trace:
#0 /Users/isaacbennetch/Documents/svn/pma/sql-parser/src/Utils/Formatter.php(497): str_repeat('    ', NULL)
#1 /Users/isaacbennetch/Documents/svn/pma/sql-parser/src/Utils/Formatter.php(671): PhpMyAdmin\SqlParser\Utils\Formatter->formatList(Object(PhpMyAdmin\SqlParser\TokensList))
#2 /Users/isaacbennetch/Documents/svn/pma/sql-parser/src/Utils/CLI.php(89): PhpMyAdmin\SqlParser\Utils\Formatter::format('select\ncase whe...', Array)
#3 /Users/isaacbennetch/Documents/svn/pma/sql-parser/bin/highlight-query(30): PhpMyAdmin\SqlParser\Utils\CLI->runHighlight()
#4 {main}
  thrown in /Users/isaacbennetch/Documents/svn/pma/sql-parser/src/Utils/Formatter.php on line 497

This is the content of case.sql

case when count(id)>0
  then 'Yes'
  else 'No'
end
from products where 1;

This works correctly with the QA branch, but git bisect doesn't help me. I've tested with both PHP 7.1.23 and PHP 7.4.0.

MauricioFauth added a commit that referenced this issue Dec 15, 2019
Related to #272

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
@MauricioFauth
Copy link
Member

The commit 1a99634 fixes the uncaught TypeError, but I don't think it is a proper fix.

This issue started to happen because we enabled the PHP strict mode. Before null was being implicit converted to int.
Looks like sql-parser only expects an END after a BEGIN. It doesn't handle the CASE statement well enough.

array_pop() returns null if $blocksIndentation is empty or is not an array.

// Indenting BEGIN ... END blocks.
if ($prev->type === Token::TYPE_KEYWORD && $prev->keyword === 'BEGIN') {
$lineEnded = true;
$blocksIndentation[] = $indent;
++$indent;
} elseif ($curr->type === Token::TYPE_KEYWORD && $curr->keyword === 'END') {
$lineEnded = true;
$indent = array_pop($blocksIndentation);
}

I think we should close this issue and open a new one related to the CASE statement issue. What do you think @ibennetch ?

@ibennetch
Copy link
Member Author

ibennetch commented Dec 15, 2019

I tend to agree; it seems that your commit suppresses the actual error but we should still make a new issue to address the underlying shortcomings with CASE statements.

Good research and conclusion. @MauricioFauth do you mind creating that issue?

@MauricioFauth
Copy link
Member

Thank you. No problem, I can open the issue.

@MauricioFauth MauricioFauth self-assigned this Dec 15, 2019
@williamdes
Copy link
Member

what about QA branch?

@MauricioFauth
Copy link
Member

This TypeError only affects master.

@williamdes
Copy link
Member

Okay, because of the php version?

@MauricioFauth
Copy link
Member

No, because of declare(strict_types=1);.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants