WHAT ARE THOSE DARN BRACES DOING IN THERE?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cybervigilante

    WHAT ARE THOSE DARN BRACES DOING IN THERE?

    My PHP is rusty, but I'm trying to follow Joomla code and I keep
    seeing reverse braces inside php blocks that look to me like they'll
    break the interpreter. The code works. What am I missing here? Is this
    something new to php5 or some preproccessor or something?

    Stuff like this:

    <?php } else { ?>

    or this. where you see that left brace right before the ? I haven't
    done php in a while. Am I forgetting something obvious?

    <?php if(mosCountModu les('right')) { ?>
    <div id="mcontent">
    <div class="padding" >
    <?php if(mosCountModu les('top')) { ?>
    <div id="newsflash"> <div class="newsflas h"><?
    php mosLoadModules ('top');?></div>
    </div><?php } ?>
    <?php mosMainBody(); ?>
    </div>
    </div>
    <?php } else { ?>

  • Schraalhans Keukenmeester

    #2
    Re: WHAT ARE THOSE DARN BRACES DOING IN THERE?

    At Thu, 17 May 2007 12:17:40 -0700, cybervigilante let his monkeys type:
    My PHP is rusty, but I'm trying to follow Joomla code and I keep
    seeing reverse braces inside php blocks that look to me like they'll
    break the interpreter. The code works. What am I missing here? Is this
    something new to php5 or some preproccessor or something?
    >
    Stuff like this:
    >
    <?php } else { ?>
    >
    or this. where you see that left brace right before the ? I haven't
    done php in a while. Am I forgetting something obvious?
    >
    <?php if(mosCountModu les('right')) {
    ?>
    <div id="mcontent">
    See it like this:
    if the condition is true:
    { // block opening brace
    ?step out of PHP
    <div blabla etc. // output html code
    <?PHP // step back into php
    } // end the code block
    else // condition not met
    { // begin other code block

    etc etc.

    HTH
    Sh.

    Comment

    • cybervigilante

      #3
      Re: WHAT ARE THOSE DARN BRACES DOING IN THERE?

      On May 17, 12:29 pm, Schraalhans Keukenmeester <inva...@invali d.spam>
      wrote:
      At Thu, 17 May 2007 12:17:40 -0700, cybervigilante let his monkeys type:
      >
      My PHP is rusty, but I'm trying to follow Joomla code and I keep
      seeing reverse braces inside php blocks that look to me like they'll
      break the interpreter. The code works. What am I missing here? Is this
      something new to php5 or some preproccessor or something?
      >
      Stuff like this:
      >
      <?php } else { ?>
      >
      or this. where you see that left brace right before the ? I haven't
      done php in a while. Am I forgetting something obvious?
      >
      <?php if(mosCountModu les('right')) {
      ?>
      <div id="mcontent">
      >
      See it like this:
      if the condition is true:
      { // block opening brace
      ?step out of PHP
      <div blabla etc. // output html code
      <?PHP // step back into php
      } // end the code block
      else // condition not met
      { // begin other code block
      >
      etc etc.
      >
      HTH
      Sh.
      thanks. I had a feeling it was some trick I didn't normally see, or
      that I'd forgotten. Still a tad unclear. Why do they have the ?right
      at the beginning of the code block, after the }, when they could just
      have a code block? Or do you mean when the HTML is done it literally
      steps back to that position, right before the ending ?like a return
      statement. Or is the ?there just to keep the interpreter happy?
      I'm just unfamiliar with this construction. It isnt' in any of the php
      primers that were gathering dust on my shelf ;')

      Jim

      Comment

      • Good Man

        #4
        Re: WHAT ARE THOSE DARN BRACES DOING IN THERE?

        cybervigilante <cybervigilante @gmail.comwrote in
        news:1179435524 .505510.163270@ k79g2000hse.goo glegroups.com:

        thanks. I had a feeling it was some trick I didn't normally see, or
        that I'd forgotten. Still a tad unclear. Why do they have the ?right
        at the beginning of the code block, after the }, when they could just
        have a code block? Or do you mean when the HTML is done it literally
        steps back to that position, right before the ending ?like a return
        statement. Or is the ?there just to keep the interpreter happy?
        I'm just unfamiliar with this construction. It isnt' in any of the php
        primers that were gathering dust on my shelf ;')
        This may help clear things up for you... both examples perform EXACTLY
        the same (untested!)

        Example 1:

        <?php
        if($butter=="ye llow") {
        echo "<h1>The butter is yellow!</h1>";
        }
        else {
        echo "<h1>The butter is not yellow!</h1>";
        }
        ?>


        Example 2:

        <?php
        if($butter=="ye llow") {?>
        <h1>The butter is yellow!</h1>
        <?php } else { ?>
        <h2>The butter is not yellow!</h2>
        <?php } ?>


        Example 1 uses PHP to spit out the HTML; Example 2 goes in and out of
        PHP so that the coder can just type straight HTML without having PHP do
        it.

        There are times when example 2 is preferred (huge blocks of HTML code)
        but in general example 1 is the way to go I think....




        Comment

        • Thiamath

          #5
          Re: WHAT ARE THOSE DARN BRACES DOING IN THERE?

          On May 17, 9:17 pm, cybervigilante <cybervigila... @gmail.comwrote :
          My PHP is rusty, but I'm trying to follow Joomla code and I keep
          seeing reverse braces inside php blocks that look to me like they'll
          break the interpreter. The code works. What am I missing here? Is this
          something new to php5 or some preproccessor or something?
          >
          Stuff like this:
          >
          <?php } else { ?>
          >
          or this. where you see that left brace right before the ? I haven't
          done php in a while. Am I forgetting something obvious?
          >
          <?php if(mosCountModu les('right')) { ?>
          <div id="mcontent">
          <div class="padding" >
          <?php if(mosCountModu les('top')) { ?>
          <div id="newsflash"> <div class="newsflas h"><?
          php mosLoadModules ('top');?></div>
          </div><?php } ?>
          <?php mosMainBody(); ?>
          </div>
          </div>
          <?php } else { ?>
          Sorry for my english...
          That braces are part of "embeeded control structures".
          The point is to embeed control structures into HTML code instead of
          embeed HTML code inside PHP code.
          Your example translated to pure PHP code:

          <?php
          if(mosCountModu les('right')) {
          echo "<div id=\"mcontent\" >";
          echo "<div class=\"padding \">";
          if(mosCountModu les('top')) {
          echo "<div id=\"newsflash\ ">";
          echo "<div class=\"newsfla sh\">;
          mosLoadModules ('top');
          echo "</div></div>";
          }
          mosMainBody();
          echo "</div></div>";
          }else{
          .........
          ?>

          Is intended to avoid abuse of the "echo" sentence, etc.

          Comment

          Working...