Balanced¶
A pair of token is balanced when the opening token has a corresponding unique closing token.
Tokens that needs balancing :
parenthesis, with
(
and)
curly bracket, with
{
and}
variable delimiters with curly bracket, with
${
and}
square bracket, with
[
and]
single quotes, with
'
double quotes, with
"
oblic quotes, with
\`
Quotes are the same for opening and closing tokens.
The listed tokens must be nested: after an opening token, any new opening token must be closed before the first one can be closed.
Inside quotes, the brackets and parenthesis may be unbalanced, as the accountability is turned off. This is not the case for curly brackets,
Closing tokens are assigned to the last opening token: in case of mismatch, it produces a syntax error.
<?php
$x = ([;
$y = '])(['; // this is OK inside quotes
$y = "\
"; // the curly brackets must be balanced when they enclose a variable or valid PHP expression.
?>