I am creating my first plugin ever and I found my self having to call the same option variables within various parts of the same page therefore I sought for a solution and stumbled upon global variables which seems to be working for me, however after reading a few articles people seem to be against using global variables and also, I'm not entirely sure if I'm using them the correct way.
Here is what I have;
/************************
* Variables
************************/
global $bClass, $cClass, $dClass, $cExpiry;
$bClass = $cClass = $dClass = $cExpiry = get_option('myoption');
Then since I use a single option to save relevant variables in an array, I would echo the value like this
jquery
expires: <?php global $cExpiry; echo $cExpiry['cExpiry']; ?>,
and then I would also use it in other functions within the same page.
So, it works for me, however I am still wondering whether I am doing it right.
update Thanks for the explanation guys, I ended up using local variables and also found a mistake in my code;
Since I have all my variables saved in a single option, I just used a single local variable;
$options = get_option('myoption');
Then I would get access to the array by placing the variable inside brackets
<?php echo $options['var1']; ?>
Whereas before I was doing $bClass = $cClass = $dClass = $cExpiry = get_option('myoption');
which is bad.