You need the singleton pattern for this. I found this on PHP.net:
// saves content safely into an internal id.
// I would like to have endfunction :(
// it is so much more understandable.
// https://bugs.php.net/bug.php?id=24100
function set_content($text){
static $id;
if(!$id):
$id = uniqid();
// set safe id
get_content($id);
endif;
$GLOBALS{$id} = $text;
}
// retrieves the content from the internal id.
function get_content($sid = false){
static $id;
if($sid && !$id): // we received save id. So we not get overwritten.
$id = $sid;
return "";
endif;
return $id ? $GLOBALS{$id} : "";
}
// html append. Add \n for readabiliy.
function html_a (){
$args = func_get_args();
set_content(get_content() . $args{0} . "\n");
}