By Sunshiney on
I see that in some instances, isset is used <?php if (isset($tabs2)): print $tabs2; endif; ?> and in other instances, no isset is used: <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
What I don't understand is when to use isset and when not to...
Can someone explain?
I do know that isset with if mean "if the tabs variables is set".... or at least, that is what I think it means...
Comments
=-=
this may help: http://www.php.net/isset
Though without knowing from where you are pulling your references in theme code, I can't help.
It may be that some themes are doing some more advanded settings in administer -> themes -> configure
case in point: acquia slate, acquia marina, and others have exposed settings that many themes do not.
found both in the
found both in the page.tpl.php of different themes. Simply trying to decide which to use in my custom theme. Saw it after studying themes and thought, whoah....which syntax is the proper one?
Yep, I've see the php reference. But, I'm thinking (maybe incorrectly) that the if ($tabs2): print....also returns true if variable is set. So that brings me right back to which one... ?
What are exposed settings?
isset is safer when running
isset is safer when running with php strict warnings on, although not always what you want - as a variable can be an empty string.
It's now recommended for Drupal code to throw not even a php notice, and developers that care run with E_ALL php notices enabled.
So there is a distinction between just
if($var)(adequate, but lazy) andisset($var)(use only if that's really what you mean) and!empty($var)( like if() but safe from PHP warnings).fwiw, please also stop using the if() : ... endif; construct.
I know a bunch of themes do that ... but i don't think it's a great structure
http://drupal.org/node/129634
.dan. is the New Zealand Drupal Developer working on Government Web Standards
If you know a variable is
If you know a variable is defined (because you did so explicitly), then there's no need for isset or empty.
The check whether a string is empty, do a strict compare with the empty string, avoid empty() and nonstrict compares.
!empty is what I use.
!empty is my preferred choice.