September 5, 2007 4:59pm
Reading through the WordPress source, I found some syntax I didn't recognize.if ( !function_exists('wp_set_current_user') ) :A hunt revealed that this was an example of PHP's alternative syntax for control structures. You can replace an opening brace with a colon on some control structures, the closing brace with an
function wp_set_current_user($id, $name = '') {
global $current_user;
if ( isset($current_user) && ($id == $current_user->ID) )
return $current_user;
$current_user = new WP_User($id, $name);
return $current_user;
}
endif;end*;, where * is the control structure, and have blocks of multiple lines. Why would one use this? One example in the WordPress is a conditional function definition, which, okay, that's unusual, so maybe the unusual syntax makes it stand out, but in general I think using this is a terrible idea.
October 11th, 2007 at 10:38am
[...] previously dismissed PHP’s alternative syntax for control structures, but after spending some time working on themes for WordPress and Habari, I’ve come to [...]