yiisoft / yii2-twig

Yii 2 Twig extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
136 stars 61 forks source link

Template class completely broken #113

Closed hofrob closed 5 years ago

hofrob commented 5 years ago

Please anyone who is working on this take a look at the class yii\twig\Template

$object instanceof ElementInterface

ElementInterface is not imported. Nor does it exist in any of the dependencies.

self::_includeElementInTemplateCaches($object);

This method does not exist.

$object instanceof Object

Since PHP 7.2 object is a reserved word. The Yii2 class Object is not imported anyways.

parent::displayWithErrorHandling($context, $blocks);

This class does not extend another class. Calling parent::something() always fails.

$this->getDebugInfo()

This method does not exist.

Honestly we are a little bit puzzled how anyone can actually use this extension.

machour commented 5 years ago

I can confirm that the 2.2.x branch looks really odd..

I don't see that much oddness in 2.1.1, could you try downgrading to that version and see what's what? https://github.com/yiisoft/yii2-twig/tree/2.1.1

koxu1996 commented 5 years ago

@hofrob @machour I use this extension in my personal project, so I can confirm it's fully working. As I mentioned the code was copied from craftcms and adjusted to pass all tests. It seems these three lines are irrelevant:

if ($object instanceof ElementInterface) {
    self::_includeElementInTemplateCaches($object);
}

... but weird code inside is not executed - instanceof returns false. It's really interesting that you can provide any class name, even non-existing one and PHP won't leave you error nor warning.

To sum up extension is not broken and it'is working fine, but contain few unnecessary lines which doesn't matter. I'll prepare PR to get rid of them.

@hofrob nice catch btw.

hofrob commented 5 years ago

Thanks for the quick replys! Will try 2.1.1 and report back. At first glance this does look better.

The version we used had the erroraenous comparison instanceof Object (which causes getters to be executed twice) and I was about to do a PR until I saw yii\twig\Template in the master branch.

If I have something worth contributing, I will do that.