Curly braces without pre-keyword do not cause parse error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Curly braces without pre-keyword do not cause parse error.

    I came across this today while thinking how I could put the Boyer-Moore string search algorithm into PHP.

    Wouldn't you expect the following to give you a parse error?

    Code:
    <?php
    
    echo "Ok ...";
    
    {
        echo "I'm inside rogue curly braces!";
    }
    ?>
    Strangely, it outputs both echo calls.

    Is this built-in behavior for something? Does this parse correctly for you? Am I loosing it?
  • prabirchoudhury
    New Member
    • May 2009
    • 162

    #2
    you are right.. php execute first anything inside the curly braces . it would be php build in behavior that only work on curly braces.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Yea, I stumbled onto that to a while back.

      Thought it was kind of odd at first, but it can be kind of useful to.
      It can help organize long procedural scripts. Especially if your editor has the sense to allow code folding on these independent blocks.

      I mean, considering that these sort of blocks can even contain functions and classes, this can be very helpful

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by Atli
        Yea, I stumbled onto that to a while back.

        Thought it was kind of odd at first, but it can be kind of useful to.
        It can help organize long procedural scripts. Especially if your editor has the sense to allow code folding on these independent blocks.

        I mean, considering that these sort of blocks can even contain functions and classes, this can be very helpful
        Exactly what I was thinking.

        I still want to know whether this is a bug or purposeful; I'll ask on php.net.

        Comment

        Working...