Note to self… in PHP you might want to avoid defining a function within a case section of a switch statement, it can cause some crazy problems.
In PHP 5.0.4, this will NOT work:
<?php
$a = true;
switch($a) {
case true:
echo ‘In switch(true)<br />’;
function fun()
{
echo ‘In fun<br />’;
}
fun();
break;
}
?>
The End
This WILL Work:
<?php
function fun()
{
echo ‘In fun<br />’;
}
$a = true;
switch($a) {
case true:
echo ‘In switch(true)<br />’;
fun();
break;
}
?>
The End
And so will this:
<?php
switch(true) {
case true:
echo ‘In switch(true)<br />’;
function fun()
{
echo ‘In fun<br />’;
}
fun();
break;
}
?>
The End
Uhh crazy.