The beauty of string parsing, parting shot

Did you know that {$array} is tokenized as

<?php
 
array (
   
0 => 'T_CURLY_OPEN',
   
1 => '{',
  ),
  array (
   
0 => 'T_VARIABLE',
   
1 => '$array',
  ),
 
'}',
?>

however ${array} gets parsed into

<?php
 
array (
   
0 => 'T_DOLLAR_OPEN_CURLY_BRACES',
   
1 => '${',
  ),
  array (
   
0 => 'T_STRING_VARNAME',
   
1 => 'array',
  ),
 
'}',
?>

and then any { outside of strings is tokenized into the literal character {. In other words, there are three different tokens for the opening curly brace but there is only one token for the closing one.

Comments

the

the T_DOLLAR_OPEN_CURLY_BRACES isn't a token for just the opening curly brace , but for ... you know, nevermind, it's right there in the name.

that does not matter

if you try to find the matching pairs of { } it wont help you that a $ is stuck to {. I am complaining about you need to check three different tokens to get all { but only one to get all } -- that's just not right.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options