Thread: TalkPHP Project
View Single Post
Old 06-22-2008, 11:23 AM   #90 (permalink)
Ross
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default

Regarding ternary operators I usually use this methodology:

If an if statement has only one simple function use a ternary operator. For others use a full if. For example:

PHP Code:
// Use ternary
if(defined('CONST'))
$x = (defined('CONST')) ? true false;
(!
defined('CONST')) ? exit : null;

// Use full if
if(defined('CONST') && isset($_SERVER['HTTP_REFERRER']))
if(
strlen(strtoupper($_SERVER['HTTP_REFERRER'])) < 1)

// Improper ternary style (imo)
defined('CONST') ? nullnull;
// Correct
(defined('CONST')) ? nullnull
Ross is offline  
Reply With Quote