ArrayAccess: Treat Your Object Like an Array

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    Let's do something else that's not possible.
  • 0:11
    battleResult is an object. But use your imagination.
  • 0:16
    Its only real job is to hold these 3 properties.
  • 0:20
    Plus it does have 1 extra method, is there is a winner?
  • 0:24
    But for the most part, it's kind of a glorified associative array.
  • 0:29
    Let's get crazy and treat the object like an array.
  • 0:33
    Say battleResults, ['winningShip', -> getName].
  • 0:38
    That shouldn't work, but let's refresh and try it.
  • 0:45
    Oh, yes, cannot use object of type Model/BattleResult as an array.
  • 0:50
    It's right, we're breaking the rules.
Loading ...