By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,345 Members | 2,408 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,345 IT Pros & Developers. It's quick & easy.

WHAT ARE THOSE DARN BRACES DOING IN THERE?

P: n/a
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(mosCountModules('right')) { ?>
<div id="mcontent">
<div class="padding">
<?php if(mosCountModules('top')) { ?>
<div id="newsflash"><div class="newsflash"><?
php mosLoadModules ('top');?></div>
</div><?php } ?>
<?php mosMainBody(); ?>
</div>
</div>
<?php } else { ?>

May 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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(mosCountModules('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.

May 17 '07 #2

P: n/a
On May 17, 12:29 pm, Schraalhans Keukenmeester <inva...@invalid.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(mosCountModules('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

May 17 '07 #3

P: n/a
cybervigilante <cy************@gmail.comwrote in
news:11**********************@k79g2000hse.googlegr oups.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=="yellow") {
echo "<h1>The butter is yellow!</h1>";
}
else {
echo "<h1>The butter is not yellow!</h1>";
}
?>
Example 2:

<?php
if($butter=="yellow") {?>
<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....


May 17 '07 #4

P: n/a
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(mosCountModules('right')) { ?>
<div id="mcontent">
<div class="padding">
<?php if(mosCountModules('top')) { ?>
<div id="newsflash"><div class="newsflash"><?
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(mosCountModules('right')) {
echo "<div id=\"mcontent\">";
echo "<div class=\"padding\">";
if(mosCountModules('top')) {
echo "<div id=\"newsflash\">";
echo "<div class=\"newsflash\">;
mosLoadModules ('top');
echo "</div></div>";
}
mosMainBody();
echo "</div></div>";
}else{
.........
?>

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

May 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.