We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Accessing object attributes that are numbers

Hello guys, I'm wondering if is it possible to access a value that is indexed by a number as an atrrib

Following this: https://docs.phalcon.io/vi/3.2/volt#variables

{{ post.title }} {# for $post->title #}
{{ post['title'] }} {# for $post['title'] #}

In my case, "title" is an integer! and is not an array, so I can't do {{ some['42'] }}

Thanks!



77.7k
Accepted
answer
edited Feb '18

Having pure numbers as object property names is a bad practice... you should avoid it if you can.

But it's possible, here's a previous thread about this: https://forum.phalcon.io/discussion/1231/volt-access-to-object-property-using-variable

Agree with @lajos.. if you really really need to do it just cast to array.



13.8k
edited Feb '18

Thanks for reply, yes is it a bad practice, but what about if I have not control to the source of the data?

As i remember volt doesn't allow to access like this. Just add filter to volt.