Magic Methods: __toString(), __get, __set

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:08
    If I give you an object, could you print it?
  • 0:11
    What I mean is, in battle.php, after we determine the winners, we echo $ship1->getName.
  • 0:18
    Which is of course a string.
  • 0:21
    But, could we just print ship1 and ship2?
  • 0:24
    Does it make sense to print an object?
  • 0:27
    The answer is no.
  • 0:31
    Try to battle.
  • 0:38
    You get a very clear error that says,
  • 0:41
    Object of class Model\RebelShip could not be converted to string.
  • 0:47
    Remember this error.
Loading ...