cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Diffrent volt partial() in php 5.6/7.0

Open FlexIDK opened this issue 10 years ago • 22 comments

Expected and Actual Behavior

In PHP 5.6

Volt: partial("email/tag_open", {'type': 'p'}) - $type is local var {{ type }} - not set partial("email/tag_open", {}) - $type inside - not set

In PHP 7

Volt: partial("email/tag_open", {'type': 'p'}) - $type is global var {{ type }} - last state set partial("email/tag_open", {}) - $type inside - last state set

Details

  • Phalcon version: 3.0.1
  • PHP Version: 5.6.24-0+deb8u1 / 7.0.10-1~dotdeb+8.1
  • Operating System: Debian 8.5
  • Installation type: Compiling from source

Refs

  • https://github.com/phalcon/zephir/issues/1621

FlexIDK avatar Aug 29 '16 12:08 FlexIDK

PHP 5 allowed us to create intermediate symbol tables per render, in php7 that is not possible, we have to research more about it.

andresgutierrez avatar Aug 31 '16 15:08 andresgutierrez

I would like to suggest this fixing ASAP, as this is braking all the partial system in the views. (quite important thing)

This happens only on php7, as @andresgutierrez described, thought - php5 (with phalcon 3) is all good.

Also it is happening with .phtml, not only with Volt.

janisbiz avatar Sep 25 '16 12:09 janisbiz

It's also driving the loop context crazy :

{% for d in data %}
    {{ dump(loop.first) }} // true 
    // there is a {% for t in tags %} inside it
    {% include "header" with ['active': loop.first, 'tags': d.tags] %} 
    {{ dump(active) }} // true 
    {{ dump(loop.first) }} // false 
{% endfor %}

challet avatar Dec 22 '16 19:12 challet

some news about it? someone knows when it will be fixed? what branch ? or date? i've identified this problem in phalcon 3.0.0, but now i'm migrating to phalcon 3.0.3!

jl91 avatar Jan 26 '17 19:01 jl91

Im guessing if someone would know then he would do PR with fix. We have to wait until @andresgutierrez will do something about this.

Jurigag avatar Jan 26 '17 19:01 Jurigag

Can confirm this is still a problem, particularly the loop context that @challet referenced. I can put together a test case if needed, as this is causing me headaches.

jellisii avatar Jul 11 '17 17:07 jellisii

Can confirm as now. (23.11.2017). Due to this issue cannot upgrade two of my projects to php 7+ :( Same behavior is with .phtml, so @sergeyklay Volt label can be removed, as it's affecting all kind of views.

janisbiz avatar Nov 23 '17 07:11 janisbiz

I'll try to sort out

sergeyklay avatar Nov 24 '17 06:11 sergeyklay

Can we get a status update regarding this issue? Is it being addressed and if so, when might we expect to see the fix?

kgrammer avatar Jan 25 '18 14:01 kgrammer

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Jul 08 '18 12:07 stale[bot]

With Phalcon 4 dropping PHP5 support, I believe this issue is becoming even more important. Is there any way one could possibly help to move this along?

thnoack avatar Jul 09 '18 13:07 thnoack

Since this issue has not been fixed, I don't think it should have been closed by Mr. Stale Bot...

kgrammer avatar Jul 09 '18 14:07 kgrammer

As the bug fixing can take some time, here is my workaround in the hope it helps someone: extend \Phalcon\Mvc\View\Engine\Volt and use it instead of the original class when creating voltService:

namespace My\Fix;

/*
 * This class is a workaround for a bug in zephir
 * Remove it when the bug is fixed, see https://github.com/phalcon/zephir/issues/1621
 */
class Volt extends \Phalcon\Mvc\View\Engine\Volt
{
    public function render($templatePath, $_params__, $_mustClean__ = false)
    {
        if ($_mustClean__) {
            ob_clean();
        }
        $compiler = $this->getCompiler();
        $compiler->compile($templatePath);
        $_compiledTemplatePath_ = $compiler->getCompiledTemplatePath();
        unset($compiler);
        unset($templatePath);

        if (is_array($_params__)) {
            foreach ($_params__ as $_key_ => $_value_) {
                $$_key_ = $_value_;
            }
        }
        require $_compiledTemplatePath_;
        if ($_mustClean__) {
            $this->_view->setContent(ob_get_contents());
        }
    }
}

The idea behind the fix is simple - I've just "copy-pasted" code from the zephir sources of the Volt class to PHP - in PHP it works as expected.

When the bux gets fixed simply replace \My\Fix\Volt with \Phalcon\Mvc\View\Engine\Volt and delete this class.

zacek avatar Jul 16 '18 07:07 zacek

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Oct 14 '18 07:10 stale[bot]

As I commented when Mr. Stale Bit attempted to close this issue last time, since this issue has not been fixed, I don't think it should have been closed by Mr. Stale Bot...

And with that said, when might we expect this issue to be addressed?

kgrammer avatar Oct 14 '18 17:10 kgrammer

Thank you @kgrammer

As for when, not sure. I have a few issues I need to check first for this week and I will check this out soon. I have to identify first where it comes from and whether we need to make changes to Zephir.

niden avatar Oct 15 '18 13:10 niden

Unfortunately, @niden I have the same problem. #13551

yesworld avatar Oct 25 '18 16:10 yesworld

@niden, any news?

yesworld avatar Nov 13 '18 07:11 yesworld

@yesworld Sorry I haven't had time to check this out. I will try but it won't be until the end of next week till I have some free time.

niden avatar Nov 14 '18 14:11 niden

Thanks @zacek that's a great little work-around until this issue is resolved!

harrywebster avatar Nov 20 '18 14:11 harrywebster