12.
ArrayAccess: Treat your Object like an Array
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
2 Comments
I don't quite get why an Interface provides 'superpowers' to a class.The
interface itself doesn't implement the methods, and the methods we add
don't seem to do much, they are not called by battle.php line 77?
Hey Arno,
Because interfaces are the lowest level thing in OOP, *they* work behind the scene. It's not enough to just add those method. If you add all that implementation we added here - you won't be able to treat objects of the class like arrays. Interface is required, and so exactly interface tell the PHP how it can work with those objects. Yes, implementation also improtant, but without interfaces that implementation is just a piece of code that will never be called by PHP.
On line 77, we don't... but on 78 we do :) There's where we treat our $battleResult object as an array, i.e. call "$battleResult['winningShip']".
I hope this clarify things for you :)
Cheers!
"Houston: no signs of life"
Start the conversation!