I want to do something like this:
<?php
function addScript($name, $url) {
$scripts[$name] = $url;
}
function displayScripts() {
foreach ($scripts as $name => $url) {
echo '<!-- Script: '.$name.' -->';
echo '<script src="'.$url.'"></script>'
}
}
The trick is: When the User want to add a Script in their classes.php, they just call addScript('jQuery','http...');
When the page is generated, the function displayScripts(); will be called and will throw all Scripts in the head of the file.
For obvious reasons I normally would just pass the $scripts array, but I don't want the user to do that. Also how would displayScripts() know about the $scripts array anyway?
I want that the user only calls addScript('jQuery','http...'); and no logic from my code.
The Problem is, that the array $scripts should something like global, but as far as I know, you should avoid global $var.
Does anyone has an idea how to do this?