We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

For loop variable being compiled incorrectly

The url variable inside the loop is being compiled to $this->url. I've only noticed it doing this when trying to use the variable name url.

    {% for url in urls %}
        <loc>{{ url.loc }}</loc>
        <lastmod>{{ url.lastmod }}</lastmod>
        <changefreq>{{ url.changefreq }}</changefreq>
        <priority>{{ url.priority }}</priority>
    {% endfor %}

Compiles to:

    <?php foreach ($urls as $url) { ?>
        <loc><?php echo $this->url->loc; ?></loc>
        <lastmod><?php echo $this->url->lastmod; ?></lastmod>
        <changefreq><?php echo $this->url->changefreq; ?></changefreq>
        <priority><?php echo $this->url->priority; ?></priority>
    <?php } ?>


Variables are first checked if their name is a service registered in the application, in this case, "url" is the url resolver service, you will have the same behavior if you use: "di", "view", "router", "dispatcher", "flash", "session", "modelsManager", etc.