Reputation: 2428
I recently moved one ancient PHP app originally from year 2004 to a freshly installed Linux host. Originally it was written in PHP4 but it worked without any modifications on PHP5.
Now there is problem with rendering Pear HTML_Template_IT with PHP7 and Phar. Non-working code looks like this
<?php
require_once("HTML/Template/IT.php");
class Layout_normal
{
function __construct($views)
{
$this->views = $views;
$Tt = new HTML_Template_IT("../tpl");
$Tt->loadTemplatefile("layoutNormal.tpl");
foreach($views as $view => $data)
{
if($view == "main") {
$Tt->setVariable("PAGE", $data);
}
elseif($view == "help")
{
$Tt->setCurrentBlock("help");
$Tt->setVariable("HELP", $data);
$Tt->parseCurrentBlock();
}
elseif($view == "pagename") $Tt->setVariable("PAGENAME", $data);
elseif($view == "active") $active = $data;
elseif($view == "module") $module = $data;
}
$Tt->setVariable("MENU", $this->getMenu($view));
$Tt->setVariable("TOPMENU", $this->getMenu($view));
$this->page = $Tt->get();
}
// some more methods here
}
?>
From that code variable {{PAGE}} was rendered as expected, but {{MENU}} and {{TOPMENU}} does not render. This same code works in old PHP5 environment.
Upvotes: 0
Views: 104
Reputation: 2428
The reason was that when current block was set to "help" $Tt->setCurrentBlock("help");
it was never returned from there. So adding last line in here fixed the problem:
elseif($view == "help")
{
$Tt->setCurrentBlock("help");
$Tt->setVariable("HELP", $data);
$Tt->parseCurrentBlock();
$Tt->setCurrentBlock("__global__"); // <- THIS DID THE MAGIC
}
In PHP5 you didn't need to set __global__
back to current block, but after updating to PHP7 and newer version of Pear (Phar, API version 1.1.1 to be exact) you need to do that.
Upvotes: 0