HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

GetValue or val?

Which function should I use to get a value from a collection or array?
I see both val and GetValue (and their recursive counterparts) being used.

^ This tells me GetValue will be deprecated at some point, or is it the other way around?

Also, kind of unrelated, since Vanilla 2.3 will require php5.4, are there plans switch to the nicer array() syntax []?
There are tools to perform this conversion automatically.


  • This is really down to the new naming convention. Functionally they are same.

    Personally I don't endorse Depreciating it for a long time.

    Over use of either can be a problem, becuase of the efficiency of array_key_exists/property_exists may pose scalability issues.

    I have thought of testing alternative algorithms to make it more inefficient at scale, testing all hypothetical.

    grep is your friend.

  • Also, kind of unrelated, since Vanilla 2.3 will require php5.4, are there plans switch to the nicer array() syntax []?

    There is nothing stopping you from using it. I really don't see the point in trawling through code changing it for no reason. Also it is subjective whether it is nicer.

    grep is your friend.

  • R_JR_J Ex-Fanboy Munich Admin

    @Linc said:
    To latch onto that last point: We hate GetValue and wish we'd never done it, for exactly that reason. We're standardizing on arrays to store/pass data moving forward to remove the ambiguity and move away from the need for that function.


  • Having a default fallback if the value is not set is very convenient, though.

    Maybe a simpler function that just tests for isset() could be introduced, that can be used when you know you're only dealing with arrays.

  • LincLinc Detroit Admin
    edited September 2014

    We have moved to val(). We're no longer accepting new code using GetValue(). They are functionally equivalent, but val() is better optimized in addition to matching the new naming standard.

  • @Linc It looks through testing that the unnecessary &$Collection in GetValue almost doubles execution time. This was purely for the $Remove param.

    Definitely depreciating $Remove is a good idea. It is poor fit for this function anyway. I have not seen anyone use it.

    grep is your friend.

Sign In or Register to comment.