Whilst I was testing DocBlox on the Solar Framework I found a bug in the part of the application where I match the curly brace pairs of structures (like classes, functions, methods, etc). Every time a variable was imported in a string using the {$var} notation my algorithm thought that the function/method had ended at the closing brace of that string.
To my surprise I found out that the issue was caused by the fact that the Tokenizer has three different tokens for recognizing an opening curly brace and only one for a closing curly brace.
Should you ever be in a position that you want to find curly brace pairs in your code you can test for the following:
- a single ‘{‘ (thus without token type)
- an array whose first element (thus token type) is T_CURLY_OPEN (representing the sequence ‘{$’) or
- an array whose first element (thus token type) is T_DOLLAR_OPEN_CURLY_BRACES (representing the sequence ‘${‘)
- a single ‘}’
It took me quite some time to find out what went wrong here and I hope this blog post will help someone to find the answer to his problem.
Thank you for reading!