I am not sure what you are trying to achieve (a test/exercise?), but make sure $a and $b are not *already* defined somewhere in header.php . There might be a variable name collision and overriding it can cause all sorts of oddities. That’d be my guess.
Thanks for the reply schestowitz. No the actual function i was trying to use was
<head>
<?php
$current_tab = 'home';
function get_tab($tab,$tab_href,$tab_title) {
global $current_tab;
if ($current_tab == $tab) {
$tab_class = 'tabselected';
} else {
$tab_class = 'tab';
}
echo "
< a href='$tab_href' class='$tab_class'>$tab_title</a >";
}
?>
</head>
<body>
<?php
get_tab('home','/','Welcome');
get_tab('news','/articles/','News');
get_tab('tools','/tools/','Tools');
get_tab('support','/support/','Support');
get_tab('contact','/contact/','Contact');
?>
</body>
$current_tab works fine outside of the function – if i try and echo $current_tab within the function as the link text for instance, nothing is printed so it’s like it just hasn’t passed into the function, if i echo it in the body tags however it prints fine – so i don’t think its a variable collision, unless i’m misunderstanding what you mean by that.
My understanding of php isn’t fantastic, so i tired to use a much simpler function for testing purposes just so I could be sure it wasn’t get_tab() .
Thanks for your suggestion though, any more ideas? …pretty please
I know bumps are annoying, but does anyone have any ideas whatsoever? Im still stumped 🙁
Thankyou in advance
In case anyone else has this problem, the only work around i could think of was to pass the global variable into the function when calling the function ie:
<head>
<?php
$current_tab = 'home';
function get_tab($tab,$tab_href,$tab_title,$current_tab) {
if ($current_tab == $tab) {
$tab_class = 'tabselected';
} else {
$tab_class = 'tab';
}
echo "
< a href='$tab_href' class='$tab_class'>$tab_title</a >";
}
?>
</head>
<body>
<?php
get_tab('home','/','Welcome',$current_tab);
?>
</body>
This probably isn’t very good coding, but it does work.