Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

2.1-beta1: Compler: global array becomes _data array #3

Open
skruppy opened this issue Sep 4, 2011 · 0 comments
Open

2.1-beta1: Compler: global array becomes _data array #3

skruppy opened this issue Sep 4, 2011 · 0 comments

Comments

@skruppy
Copy link

skruppy commented Sep 4, 2011

Reproduce

(This is a copy of http://bugs.invenzzia.org/task/180 )

Create a template accessing a global variable in some way, assigned some how (I can't see any special conditions to trigger that bug).

<?php
    $tpl = new Opt_Class;
    $tpl->allowArrays = true;
    $tpl->allowObjects = true;
    $tpl->register(Opt_Class::PHP_FUNCTION, 'dump', 'var_dump');
    Opt_View::assignGlobal('foo', 'Hello World');
    // [...]
?>
[...]
{dump($global.foo)}
[...]

Result

All global variables are read as null because the compiler thinks it's a normal assigned variable, not a global one.

null
[...]
<?php echo htmlspecialchars(var_dump($ctx->_data['global']['foo'])); ?>
[...]

Expected

If I hack the compiled template manually, $ctx->_global actually contains my desired variables, meaning the compiler should create the following.

[...]
<?php echo htmlspecialchars(var_dump($ctx->_global['foo'])); ?>
[...]

Workaround

A workaround, which doesn't actually cure the problem source, but make it work some how. Add a line as shown below in the file Opt/Class.php, in the class Opt_View, the function _parse.

<?php
    // [...]
    $ctx = new Opt_InternalContext;
    $ctx->_data = &$this->_data;
    $ctx->_global = &self::$_global;
    $ctx->_vars = &self::$_vars;
    $ctx->_procs = &self::$_procedures;
+   $ctx->_data['global'] = &self::$_global; // This is a workaround
    // [...]
?>
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant