cphalcon: Passing an object to Volt macro; "PHP Fatal error: Cannot use object of type stdClass as array"

I updated my server yesterday evening. Today morning I realized I haven’t gotten any visitor since yesterday evening. I decided to visit my site and I found it unable to display the pages.

There is a problem with Volt’s macro feature after an update. Volt code

{%-macro list(var) %}
    dump(var)
{%-endmacro %}

Generated PHP code

<?php $this->_macros['list'] = function($__p = null) {
    if (isset($__p[0])) {
        $var = $__p[0];
    } else {
        if (isset($__p["var"])) {
            $var = $__p["var"];
        } else {
            throw new \Phalcon\Mvc\View\Exception("Macro 'list' was called without parameter: var");
        }
    }  ?>
    dump(var)
<?php }; $this->_macros['list'] = \Closure::bind($this->_macros['list'], $this); ?>

This code generates following error;

PHP Fatal error:  Cannot use object of type stdClass as array in /var/www/file.volt.php on line 2

If you’re like me, added listing etc. via macros, there is chance you will experience the same issue (unless I’m guessing you use arrays instead of objects, not that I have tried it though).

Just wanted to leave it here and hoping for a fix with next version. I’ll be down-grading Phalcon now.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 25 (13 by maintainers)

Most upvoted comments

Okay. I’ll try to sort out today