Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.phalconphp.com/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!



49.4k
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.phalconphp.com/discussion/1231/volt-access-to-object-property-using-variable

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



4.1k
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.