SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Colon used in IF statement instead of '{' - why?

    Hi everyone,

    I'm analysing some open source applications to increase my understanding of OOP. Right now I'm analysing Wordpress, and I've come across a few strange coding styles... for example the following:

    Code:
    if (! isset($wp_did_header)):
    if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) {
    	if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
    	else $path = 'wp-admin/';
    
    	require_once( dirname(__FILE__) . '/wp-includes/classes.php');
    	require_once( dirname(__FILE__) . '/wp-includes/functions.php');
    	require_once( dirname(__FILE__) . '/wp-includes/plugin.php');
    	wp_die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress &rsaquo; Error");
    }
    Can anybody explain why a colon ':' was used in the initial IF statement rather than curly brackets?

    It's trivial, but I can't seem to find an answer on Google.

    Thanks!

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its just style...thats a wierd use of it(if thats the whole bit of code)

    In that example, neither a { or a : is needed as the if statement only does 1 thing...

    But, i use them when i writing a conditional in html/php mixed, compare the two..

    PHP Code:

    <? if(true) { ?>
       <div>stuff</div>
    <? ?>

    // vs.

    <? if(true) : ?>
       <div>stuff</div>
    <? endif; ?>
    It just seems a little more readable that way...but to use it in regular code, not mixed with output, it is wierd...

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Saul

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •