Join Jon Peck for an in-depth discussion in this video Cloning and comparing objects, part of Object-Oriented Programming with PHP.
- View Offline
- Exercise Files
Sometimes, you will want to make a copy of an object.…There are many reasons to do this, including making a backup before performing an…operation, or as a shortcut for defining a similar object.…To create a copy of an object, use the clone keyword. As a demonstration, make a…copy of the park address, open the demo script, and navigate to the bottom. Add…the following lines:…echo <h2>Cloning AddressPark</h2> $address_park_clone = clone $address_park. And…then, we'll debug the clone.…
To check the differences between clones, I'm going to compare two objects.…Comparing objects is a lot like comparing primitives, such as strings and floats.…I can use the comparison operator, double equals (==), which will check to see if…the properties are the same.…If I need to be more strict, I can use the identity operator, triple equals…(===), to also check if both objects are instances of the same class.…At the end of the script, add echo $ address_park_clone_ is. And then, a ternary…statement. $address_park == $address_park_clone ? :…
- 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.