RE: [php-49] Using colon instead of curly-braces { } with conditionals

From: Mark S.
Sent on: Thursday, March 19, 2009 9:09 PM

I tested the <?php endif ?> in Aptana, and it does actually highlight the matching if statement correctly, which is cool.

 

Though neither Aptana or Netbeans 6.5 would fold the code in either the END_ or } method when it’s split up by html.

 

I use endif only if I’m forced to stick some PHP into a mainly HTML document. I thin it’s easier to read than a mysterious lone }. Just my 2 cents.

 

MS

 


From: [address removed] [mailto:[address removed]] On Behalf Of m.
Sent: Thursday, March 19, 2009 6:01 PM
To: [address removed]
Subject: Re: [php-49] Using colon instead of curly-braces { } with conditionals

 

As expressed in the comments the colon syntax best fits when mixing HTML and PHP and control strucutres.

 

I don't know if this is the most efficient way to do this but I often use:

 

<?php if($some_array){ foreach($array as $k => $v): ?>

<div>

  <h1>some title</h1>

  <p><?php echo $k?>: <?php echo $v?></p>

</div>

<?php endforeach;}?>

 

(wow that was a pain to tap out on an iPhone)

  
On Mar 19, 2009, at 5:43 PM, David Malouf <[address removed]> wrote:

Came across this blog entry and it got me wondering...
http://www.codediesel.com/php/the-benefits-of-the-colon-syntax-for-control-structures/

The premise of the article is that when code gets big and nested, using curly-braces can get troublesome.  Instead, PHP can handle a colon followed by an END__

For example:
    if ($something == 'true') :
        $aBunchOfCodeHere = 'yes';
    endif;


Using NetBeans (like Eclipse and I'm assuming other IDEs) means I can 'see' what conditional/line each closing-curly-brace  }   is associated with.

Since I'm curious, though, I'm wondering if there is ever a time when any of y'all use the colon method?


David






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by David Malouf ([address removed]) from The Seattle PHP Meetup Group.
To learn more about David Malouf, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by m. ([address removed]) from The Seattle PHP Meetup Group.
To learn more about m., visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA

Our Sponsors

  • TUNE

    Meeting space and food

  • PluralSight

    PluralSight subscriptions for developer training

  • Siteground

    Information coming Soon

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy