I am reading some WordPress plugin code, pardon my french, and even though I have coded a lot of stuff in anything from C to JavaScript, including PHP, I am not sure what kind of logic is accomplished with following:
<?php
function dcontact_options_page() {
if($_GET['action'] == 'edit_group') {
dcontact_action_edit_group();
return;
}
elseif($_GET['action'] == 'edit_form') {
dcontact_action_form_settings();
return;
}
elseif(isset($_POST['set_order'])) {
$result = dcontact_action_set_order();
}
else if(isset($_POST['new_group'])) {
$result = dcontact_action_new_group();
}
else if($_GET['action'] == 'delete_group') {
$result = dcontact_action_delete_group();
}
if(!isset($result['message']) && isset($_GET['message'])) $result['message'] = urldecode($_GET['message'])
?>
<div class="wrap">
<div class="icon32" id="icon-options-general"><br></div>
<!-- More HTML AND PHP code blocks -->
<!-- And then suddenly... -->
<?php
} /// What's this? End of function definition? PHP chokes on this with syntax error.
///...
?>
I am no stranger to mixing PHP and verbatim output, and I also did my fair share of entering and exiting PHP blocks in the middle of say if
statements, but this tops it. Can anyone explain what the guy was trying to accomplish? Does the code imply that if the if
condition evaluates to true
then whole lot of markup is written out (and more PHP is executed), but then the function definition ends, suddenly? Maybe it's what the function does? I mean, I would have used a HEREDOC
syntax for readability.
And to sum it up, my command line PHP 5.4.7 preprocessor chokes on the last }
. And I can't say I blame it. Haven't seen spaghetti code like this in some time now.