- [Instructor] Now that we've learned about…the constructor method, let's talk about…its companion, the destructor method.…The way that we define the destructor method…is similar to what we did with the constructor method.…Inside our class, we define a new method,…whose name is __destruct().…We want to make sure that that's a public method,…so we mark it with public at the beginning,…and unlike construct, destruct takes no argument.…Inside the construct method defintion,…you could put any code that you want to be called…whenever an instance is destroyed.…
This is most useful for performing logging…or other cleanup actions.…It can be used together with construct…as a set of setup and teardown methods,…although in truth, you're going to use construct…much more frequently than you will destruct,…and the reason why is just the nature of…how we use objects in PHP.…Most of the time we instantiate a new object,…we work with it throughout the script,…and then at the end, we return the result back to the user,…and we don't worry about what happens to those objects,…
Author
Released
11/17/2017- Defining classes
- Calling methods
- Class inheritance
- Extending and overriding classes
- Accessing and controlling access to properties and methods
- Static properties and methods
- Magic methods: constructor, destructor, and clone
- Creating a PHP OOP project
Skill Level Intermediate
Duration
Views
Related Courses
-
PHP: Accessing Databases with PDO and MySQLi
with David Powers3h 47m Intermediate -
Consuming RESTful APIs in PHP with Guzzle
with Justin Yost2h 12m Intermediate
-
Introduction
-
Welcome1m 3s
-
-
1. Overview and Project Setup
-
What is OOP?5m 21s
-
Project setup3m 1s
-
-
2. Object Basics
-
Define a class5m 52s
-
Instances6m 13s
-
Class properties9m 56s
-
Class methods5m 12s
-
Refer to an instance3m 54s
-
-
3. Class Inheritance
-
What is inheritance?3m 26s
-
Define a subclass7m 27s
-
Extend and override7m 7s
-
Challenge: Inheritance3m 11s
-
Solution: Inheritance8m 10s
-
-
4. Object Access Control
-
Visibility modifiers9m 18s
-
Beware of overloading5m 37s
-
Setter and getter methods4m 46s
-
Challenge: Access control2m 51s
-
Solution: Access control8m 33s
-
-
5. Static Properties and Methods
-
The static modifier7m 12s
-
Inherited static behaviors5m 45s
-
Class constants4m 43s
-
Refer to the parent class7m 19s
-
Late static bindings7m 12s
-
Challenge: Static references3m 30s
-
Solution: Static references7m 45s
-
-
6. Magic Methods
-
Constructor method4m 46s
-
Constructor arguments7m 51s
-
Destructor method4m 34s
-
Clone method6m 9s
-
Assignment by reference4m 20s
-
Compare objects4m 8s
-
-
7. A PHP OOP Project
-
Project introduction5m 57s
-
Challenge: The bicycle class2m 53s
-
Solution: The bicycle class6m 36s
-
From instances to HTML6m 46s
-
Read from a CSV file7m 44s
-
Improve parseCSV5m 43s
-
From a CSV file to instances2m 33s
-
-
Conclusion
-
Next steps36s
-
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Destructor method