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

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

@skruppy

Description

@skruppy

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
    // [...]
?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions