PATCH: variable namespaces and scopes
| From: | Hans-Peter Oeri | Date: | Thu, 11 Oct 2001 08:58:12 +0000 |
| Subject: | PATCH: variable namespaces and scopes | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1675@lists.php.net to get a copy of this message | ||
Hi!
I was suggesting the incorporation of namespaces and changeable
variable prefixes. The attached patch against the latest snapshot should
be seen as a discussion base. The changes should be fully backwards
compatible (if I didn't forget something).
Explanation:
------------
I introduce three standard namespaces: APPLICATION, CONFIG, RUNTIME that
correspond to the variable prefixes $, #, %. The variable suffix for # and
% is now optional.
The attribute var_namespaces establishes these associations by default.
I'm free, however, to associate any (one character, no other special
meaning) prefix with one or multiple namespaces. In the supplied example,
I define:
prefix "+" for a newly created namespace "KREIS"
prefix "&" for namespace APPLICATION with fallback "CONFIG"
Each variable assignment or config file load may desginate the desired
namespace (the old behaviour being the default space)
For included files, all assignments now have "local", "global" and
"parent" scope. In order to reduce runtime overhead, the deeper namespaces
are only created if and when needed. This means, if I don't assign
variables in an included file, no save-restore overhead.
Tech:
-----
All variables are now in the attribute _vars, by namespace and nesting
level (the latter may be different for every namespace! See above:
created only when needed!).
As I'm not sure what the frequent extract calls should achieve (as the
variables were referenced using the _tpl_vars array even before), I left
them there, extracting from namespace "APPLICATION". They could probably
be eliminated, though.
ATTENTION:
----------
This patch is surely not final. It changes the example files.
It may or may not work, blow up your screen or spam your friends. Use at
your own risk.
The variable prefix list is currently open... get "i" as a prefix and "if"
does not work anymore.
Further action:
---------------
Please give me feedback. I think it's a good idea and should not impact
performance of smarty, be backwards compatible etc etc. Of course, mixing
spaces and nesting levels can become tricky, but that game is up to the
template writer (he/she does not HAVE to use it).
I'm eagerly awaiting your responses!
Don't conform!
IkKampfCaspar75