Enter your Sign-on user name and password.

Forgot password?
  • Follow us on:
Loading video...

Start Learning Now

Our free lessons will get you started (Flash® 10 required).
Get immediate access to our entire library.

Sign up for Educator.com

Features Overview

  • Get on-demand access to our complete library
  • Search and jump to exactly what you need to learn
  • Track your progress
  • Download practice and lesson files
  • *Ask questions and get answers from our community & instructors

More Magic Methods

  • In PHP, any methods starting with ‘__’ are known as magic methods.
  • Magic methods have special functionality in the PHP language and are called automatically by PHP.
  • Object methods should not be given the same name as any PHP magic methods.
  • A destructor is an object method called automatically by PHP when an object is no longer being used or it has been unset (or set to NULL). They are used to ‘clean-up’ the state of an object before its destruction, such as closing any open file resources.
  • In PHP, destructors are magic methods and have the name __destruct().
  • __toString() is a magic method that is automatically called by PHP anytime an object variable is used in a string context. By defining this method, you can explicitly set how objects should be represented in string form.
  • In PHP, object properties and methods have a visibility associated with them that describes where they can be accessed from.
  • An object property or method can have one of three visibility values, known as access modifiers:
    • public – accessible inside OR outside class definition
    • private – accessible inside class definition ONLY
    • protected – accessible inside class definition OR by inherited classes (not covered in this course)
  • __get() is a magic method that is used to access inaccessible, or private, properties from code outside of a class’s definition.
  • __set() is a magic method that is used to set inaccessible, or private, properties from code outside of a class’s definition.
  • An alternative means of getting/setting private object properties is to create public getter and setter methods that provide the ability to get and set an object’s private properties. For example:
    • Getter for a 'lastName' property: public function getLastName() {...
    • Setter for a 'lastName' property: public function setLastName($lastName) {...
  • Additional Resources:

More Magic Methods

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

Advanced PHP Training with MySQL