CyberShot Posted April 19, 2011 Share Posted April 19, 2011 I am working in wordpress. I am using a switch statement to call a php page. It looks like this $slider_type = $options['type']; switch($slider_type) { case "Half Page Slider" : include('nivo-default.php'); break; case "Full Page Slider" : include('nivo-fullpage.php'); break; default: include('nivo-fullpage.php'); } The code works fine. My question is this. I want to use the exact same code to call the css file that runs each page. So instead of inlcuding a php page, I would replace that with the css call. So is it a bad idea to use the variables in the head section and then again in the page a little further down? or should I change the names? What is the best coding practice here? Quote Link to comment https://forums.phpfreaks.com/topic/234198-variable-standards/ Share on other sites More sharing options...
mens Posted April 19, 2011 Share Posted April 19, 2011 I don't think there's an exact standard for this, but the best practice is always to improve performance and efficiency; so only defining variables(with the same values) once would save memory, so it would be the best practice. Quote Link to comment https://forums.phpfreaks.com/topic/234198-variable-standards/#findComment-1203754 Share on other sites More sharing options...
CyberShot Posted April 19, 2011 Author Share Posted April 19, 2011 that makes sense. What about the default in the switch statement? for this switch, I really don't need a default. So how do I handle that? Quote Link to comment https://forums.phpfreaks.com/topic/234198-variable-standards/#findComment-1203757 Share on other sites More sharing options...
spiderwell Posted April 19, 2011 Share Posted April 19, 2011 if you dont need it, dont use it. Quote Link to comment https://forums.phpfreaks.com/topic/234198-variable-standards/#findComment-1203764 Share on other sites More sharing options...
mens Posted April 19, 2011 Share Posted April 19, 2011 Well, it depends on the contents of the variable and what you are going to use it for. If it needs to be filtered and/or modified in some way, assigning a new variable to it would be best. This is only so you can use the original contents again, for some other purpose. Then, you would then destroy the newly assigned variable after you used it to save memory. But if the type and form of the contents doesn't matter, using the original variable would be preferred. Most of these "standards", or so-called ones, come into play at a microsecond scale. At normal levels, the only reason you would actually need to destroy variables to free up memory, is when you are working with large arrays or lists(something maybe such as a file/image). I don't see any variables being introduced into the example switch statement you provided, though, so I cannot propose anything for that? Quote Link to comment https://forums.phpfreaks.com/topic/234198-variable-standards/#findComment-1203766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.