The rest is not the PHP3 I recognize to be honest, let alone the modern stuff. Remember include() literally just included the code right there, inline, so you could include in functions and gain the function's scope:
function render($data) {
switch ($data['foo']) {
case 'bar': include('bar.inc'); break;
case 'baz': include('baz.inc'); break;
}
}
That's your template router with all the template's data pre-loaded in the template's scope, be it ever so filthy.
All of those variables are global, there's no way to establish an interface between the caller and the callee without using functions. You could certainly have a shared understanding of what variables have been injected into a global, but this is awkward, and requires you to do cleanup after each template instantiation to avoid leaking values between templates, which can cause subtle bugs.
> Remember include() literally just included the code right there, inline, so you could include in functions and gain the function's scope:
I've talked about this approach elsewhere in thread, it is not nestable without building a way to "call" templates on top of require/include, and when you do that you'll need to undefined the render function to do it as well, which creates additional complexity. At that point, the original premise of just using raw PHP isn't very true, because you are now building a framework or templating system around it.
Also, you have to contend with the magic "render" function not being globally defined by something. It's messy.
> Um. Can you give me an example to pad that out a bit?
Your example of using a render() function is already an example of this. You can parameterize render() to provide data to the template from the caller without utilizing untyped globals, and without having to clean the globals up after the template has rendered.
> Wait, you're only talking about the superglobals, right?
Yes. Globals are globals. PHP's super global distinction isn't really relevant to whether you are tainting the execution environment when you pass data to a script.
The point is, as I elaborate elsewhere, PHP is very awkward to use as a proper templating system.
$_SERVER, $_POST, $_GET.
The rest is not the PHP3 I recognize to be honest, let alone the modern stuff. Remember include() literally just included the code right there, inline, so you could include in functions and gain the function's scope:
That's your template router with all the template's data pre-loaded in the template's scope, be it ever so filthy.