Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ilgityildirim opened this issue May 10, 2016 · 25 comments
Labels
bug A bug report status: medium Medium
Milestone

Comments

@ilgityildirim
Copy link

ilgityildirim commented May 10, 2016

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.

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

It's fixed in current 2.0.x repo.

@ilgityildirim
Copy link
Author

Thanks @Jurigag will take a look at it

@sergeyklay
Copy link
Contributor

sergeyklay commented May 10, 2016

@ilgityildirim Hello. Could you pease check two vesions. Current Phalcon's master branch (2.0.11) and my PR #11765. It seems there is two ways to fix it

@ilgityildirim
Copy link
Author

@sergeyklay #11765 didn't fix the issue however 2.0.10 fixed it. Seems the best option is to downgrade for the moment.

@sergeyklay
Copy link
Contributor

So issue related to the v2.0.11 or v2.0.10?

@sergeyklay
Copy link
Contributor

@ilgityildirim

@sergeyklay sergeyklay added this to the 2.0.12 milestone May 10, 2016
@ilgityildirim
Copy link
Author

@sergeyklay issue is related to v2.0.11

@vikilaboy
Copy link

I have the same issue on v2.0.11

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

Did you tried this #11765 ?

@vikilaboy
Copy link

Yes but doesn't work. Also i've upgraded to 2.1.x and it works and there's with call_user_func_array ( https://github.com/phalcon/cphalcon/blob/2.1.x/phalcon/mvc/view/engine/volt.zep#L293 ) but 2.0.x breaks other things like validators so for now i can't make the upgrade

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

What. You mean in 2.1.x with call_user_func_array it works fine ? Then i don't know what's going on.

@vikilaboy
Copy link

Yeah, as you can in see :( Also I changed manualy in volt.zep, recompiled and problem still exists :(

@sergeyklay
Copy link
Contributor

sergeyklay commented May 10, 2016

Well, @ilgityildirim @vikilaboy @Jurigag I'm totally confused 😄
We have callMacro method with:

  • call_user_func and required second param (the v2.0.10)
  • call_user_func_array and required second param (the v2.0.11)
  • call_user_func and optional second param (Fixed Volt::callMacro #11765)

What option doesn't work?

@vikilaboy
Copy link

2.0.10 works well. 2.1.x also :)
So 2.0.11 doesn't work

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

What ? How the hell 2.1.x works if it's second case which @sergeyklay wrote.

Then i would understand why i got some problems with functions/filters i guess maybe.

You are checking 2.1.x with php 5 or php 7 ?

@vikilaboy
Copy link

PHP 5.6.20-1~dotdeb+zts+7.1 (cli) (built: Apr 1 2016 04:20:28)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

@vikilaboy
Copy link

Anyway I switched back to 2.0.10 until this will be fixed. I'll also try to fix this..
Thanks to all !

@sergeyklay
Copy link
Contributor

@vikilaboy Could you please check #11765? Just clone my repo and compile Phacon from 2.0.x branch

@vikilaboy
Copy link

vikilaboy commented May 10, 2016

Checked out to branch 2.0.x, compile and the result is with the same issue. Am I doing something wrong ?

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

No. You need to clone @sergeyklay repo 2.0.x

It's not merged YET.

@vikilaboy
Copy link

vikilaboy commented May 10, 2016

I'm getting the same problem :(.
This is my macro:

{%- macro formRow(form, tag, attributes = '', col = 6) %}
    {% set defaultClass = 'form-control ' %}

    {% if attributes is iterable %}
        {% for key, value in attributes %}
            {% set attr[key] = value %}
        {% endfor %}
    {% else %}
        {% set attr['class'] = defaultClass ~ attributes %}
    {% endif %}

    <div class="form-group">
        <label class="col-sm-2 control-label" for="{{ tag }}">{{ form.getLabel(tag) }}:</label>

        <div class="col-sm-{{ col }}">
            {{ form.render(tag, attr) }}
        </div>
    </div>
{%- endmacro %}

and is called like this

{{ formRow(formLogin, 'password') }}

where formLogin is the form object and 'password' is tag key

@Jurigag
Copy link
Contributor

Jurigag commented May 10, 2016

Did you cloned right repo ?

@vikilaboy
Copy link

https://github.com/sergeyklay/cphalcon.git - compiled also on branch master and 2.0.x

@sergeyklay
Copy link
Contributor

Okay. I'll try to sort out today

@sergeyklay
Copy link
Contributor

@vikilaboy @ilgityildirim
Thanks for your report. This issue has been fixed in 2.0.x branch. We will release v2.0.12 in coming days with this bug fix.

@niden niden added the bug A bug report label Dec 23, 2019
@niden niden added status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

5 participants