sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Need to explicitely set $parser->list->idx = 0;

Open corbolais opened this issue 3 years ago • 3 comments

Hello devs,

Thanks for this excellent validating parser.

Trying to iterate over the list of Tokens, it does not work as assumed: I first need to explicitely set

    $parser->list->idx = 0;

Only then the iteration is working (for me):

    while ( NULL !== $token = $parser->list->getNextOfType(PhpMyAdmin\SqlParser\Token::TYPE_COMMENT) ) {
    [...]
    }

Bug or feature? Did I wrongly assume a different behaviour?

The docs don't specify anything in that regard (nor much on anything else). Any intention to improve on documentation besides "Use the Source.."?

Thank you for clarification.

corbolais avatar Nov 21 '20 11:11 corbolais

Hello @corbolais

Thank you !

This is a good question, maybe @ibennetch or @devenbansod would have the answer ?

That said a code sample would help me search for you an answer

The docs don't specify anything in that regard (nor much on anything else). Any intention to improve on documentation besides "Use the Source.."?

We are open for propositions to improve our documentation ;)

williamdes avatar Nov 21 '20 23:11 williamdes

I unfortunately don't know the answer off the top of my head, but we will try to get an answer for you.

About the documentation, I agree that it needs to be improved. It hasn't been much of a priority, in part because we haven't realized the project has gained some usage outside of phpMyAdmin. This is something we can work towards improving.

ibennetch avatar Nov 22 '20 13:11 ibennetch

Hi @corbolais What where you trying to do ? Can you provide a full example ?

williamdes avatar Sep 12 '21 06:09 williamdes

Hi @williamdes

I remember trying to solve an issue that involved iterating over a list. The document stated the obvious, the rest I glimpsed from the source.

There was an error thrown however and to solve this it was required to initialize the index like so:

$parser->list->idx = 0;

I wanted to let you guys know this, just in case.

Of the top off my head I'm ignoring whether the requirement to init the index was due to some specific PHP version.

Cheers and greetings to Brittany, France!

A la prochaine..

corbolais avatar Jan 22 '23 20:01 corbolais

Bonjour @corbolais 👋🏻 That you for letting us know, I think we should better document such specific things But maybe it could be pre initialized to 0

/cc @iifawzi I think you also did have this issue

williamdes avatar Jan 30 '23 18:01 williamdes

I have had this issue in mind for a while, we need to double-check why and if this's happening. we need to investigate more, I will try to find some time to figure this out later

iifawzi avatar Jan 30 '23 19:01 iifawzi