Join Jon Peck for an in-depth discussion in this video Customizing object construction, part of Object-Oriented Programming with PHP.
- View Offline
- Exercise Files
Starting in PHP5, developers could use a magic method for initializing new…objects. Before they were used. It's called _ construct (), and this magic method is Optional.…It's flexible enough that even can be empty, which is the same as not having a…magic construct method at all.…If you don't need to initialize an object, don't use it, as it's just wasted…code. Developers shouldn't be paid by the line.…In the Address class, I'm going to use the magic construct method to set the creation time.…Let's open the Address class. Add the following after the properties, before the…Magic _get and _set methods.…
function __construct.…In its current form, this will have no functional effect, neither positive nor negative.…If you are declaring a class, and have no need to customize the constructor, leave it out.…In the case of your address, you want to set the time created upon…initialization. In between the brackets, add the following line: this…->time_created = time(). Save the address class, then rerun the demo.…
- Historical overview of object-oriented PHP
- Defining classes
- Creating a method/object context with $this
- Accessing classes without instantiation
- Creating a database class
- Extending and abstracting classes
- Cloning and comparing objects
- Error handling with exceptions
- Implementing design patterns, such as the factory and strategy patterns
Skill Level Intermediate
PHP with MySQL Beyond the Basicswith Kevin Skoglund10h 26m Intermediate
1. Introduction to Object-Oriented Programming
2. Creating Your First Object
3. Overloading with Magic Methods
Overloading property access6m 37s
4. Accessing Classes without Instantiation
5. Class Relationships and Interactions
6. Built-In PHP Objects
Customizing PHP exceptions4m 23s
7. Design Patterns
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.