Magic Methods: __toString(), __get, __set

Video loading...

Transcript language code: 

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 ...

Magic Methods: __toString(), __get, __set


In this tutorial, learn about PHP's built-in magic methods: __toString(), __get(), and __set().

Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.