Wi-Fizzle.com - Putting the fizzle in Wi-Fi since 2005 .. (yes, this was a poor choice for a domain name)

#278
PHP Note: Alternative if-statment syntax

Posted by dandriff on Monday June 30, 2008@02:10PM

In PHP, there is an alternative if-statement syntax. I didn't find it listed on the PHP.net control-structures documentation. It goes like this:

<?php
if (!function_exists('ptrfun'):
  /**
   * This isn't the real ptrfun() function like you would find in C.  This is
   * just a poorly named and subsequently rather stupid example function.
   *
   * @return int
   */
  function ptrfun() {
    // Return the integer which represents what the future unix-timestamp will
    // be one minute from now.
    return mktime() + 60;
  }
endif;
?>

Okay. The above example seems horrid, confusing, and overcomplicated. Here is the 'real' example with less chatter:


<?php
if (...):
  // {Whatever code you want goes in here}.
endif;
?>

**This note was added for my own personal reference.**