On occasion, I try to follow good coding practices (har har har) and use functions in my PHP code. But I’ve noticed that Snippets don’t like functions... at least my Snippets tend to die if I have a function in them. This construct fails, for example:
<?php
$x = get_msg();
return $x; // the Snippet still dies if I use print $x;
function get_msg() {
return 'This is my Snippet';
}
?>
Is this because a Snippet is called as a function? I’m confused... I do have one Snippet that has a function that works... I just don’t know why. It uses the following construct:
<?php
$msg = myfunc();
print $msg;
//-------------------------------------------------------------------------------------
function myfunc() {
$x = 'something'
return $x;
}
?>
Can someone shed some light on what’s going on?
Thanks!