|
|
|
|
|
by rezonant
857 days ago
|
|
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?
> and requires you to do cleanup after each template instantiation to avoid leaking values between templates
In my render() example, isn't that "reaching the end of the function"? (Edit: Wait, you're only talking about the superglobals, right?)