Don't use inverted logic to execute statements. It raises the change that you'll miss the single !
operator and think it does the opposite of what it's doing.
<?php
if($user->is_session_empty()) {
echo '<p id="login">Click <a href="login">here</a> to log in</p>';
}
?>
Use a function for more clarity, and keep statements on the first indent.
<?php
function foo($user) {
if($user->is_logged_in()) {
return;
}
echo '<p id="login">Click <a href="login">here</a> to log in</p>';
}
foo($user);
?>
For logic in templates use endif
instead of { }
.
<?php if($user->is_session_empty()): ?>
<p id="login">Click <a href="login">here</a> to login.</p>
<?php endif; ?>
Readability of source code is an ambiguous guideline. What is readable for one person is not so readable for another. It's better to focus on maintainable code. That is code where you can navigate quickly, is kept clean and short. Objects, functions and files all have a single purpose.
There is no correct answer to your question.