Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Why do get methods return by reference?
  • Can someone explain the reason that the get methods (e.g. in viewmodel, view and Orm models) return by reference? - e.g. function & __get($key) {} It's a little bit of a pain to work with methods which do this as you cannot return the result of an expression but rather have to assign it to a variable and return that. For this reason, I am wondering if the drawbacks outweigh the benefits.
  • Pretty simple reason, otherwise you couldn't do this:
    $view->array['key'] = 'something';
    

    As the array is returned by reference you can deal with it just like an actual object property. So yes the benefits far outweight the drawback you described.
  • I see now and it makes perfect sense. Thanks for the clarification.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion