Invenzzia »

IMPORTANT ANNOUNCEMENT

Due to the uncertain status of the Flyspray project, lack of new releases and moving the code repository to Github, we decided to shutdown this issue tracker by the end of January 2011. From that date, the bugs should be reported directly in Github project repositories.

List of repositories:

Open Power Template 2.x family

PLEASE PROVIDE THE TEMPLATES AND/OR PHP CODE IN THE TASK DESCRIPTION (Not URL-s to them). THAT ALLOWS US TO REPRODUCE THE PROBLEM! OTHERWISE WE ARE NOT ABLE TO HELP YOU!

Remember to hide all the security-related pieces of code from the task description, like passwords, server paths etc. for your own safety. Once we close the task, we cannot edit it anymore!
Tasklist

FS#180 - global array becomes _data array

Attached to Project: Open Power Template
Opened by Skruppy (Skrupellos) - Saturday, 03 September 2011, 20:06 GMT-8
Task Type Bug Report
Category Compiler
Status Unconfirmed
Assigned To No-one
Operating System OS-independent
Severity Medium
Priority Normal
Reported Version 2.1-beta1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 1
Private No

Details

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

~~~ snip test.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');
[...]
~~~ END snip test.php ~~~

~~~ snip test.tpl ~~~
[...]
{dump($global.foo)}
[...]
~~~ END snip test.tpl ~~~


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

~~~ snip webpage ~~~
null
~~~ END snip webpage ~~~

~~~ snip compiled template ~~~
[...]
<?php echo htmlspecialchars(var_dump($ctx->_data['global']['foo'])); ?>
[...]
~~~ END snip webpage ~~~


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

~~~ snip compiled template ~~~
[...]
<?php echo htmlspecialchars(var_dump($ctx->_global['foo'])); ?>
[...]
~~~ END snip webpage ~~~


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.

~~~ snip Class.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
[...]
~~~ END snip Class.php ~~~
This task depends upon

Comment by Skruppy (Skrupellos) - Sunday, 04 September 2011, 08:58 GMT-8
This bug is now copied to https://github.com/OPL/Open-Power-Template/issues/3 and will be handled there.

Loading...