Jump to content

variable standards?


CyberShot

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.