Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Internal Control of Object Creation
Lab: Introduction to PHP Object-Oriented Programming (OOP) for WordPress
Video Runtime: 15:07
When you create a new object, i.e. instantiate it with the keyword new
, PHP gives you a constructor. You can use this constructor to control what happens when the object is created.
Why would you want to do that?
An object should be created in a known starting state. This approach makes sure the object is ready to use. You pass in the starting information and then let the object initialize itself. You can let it setup and set the properties as well as run the initialization processes.
The other reason is that the implementation, i.e. the external application code (outside of the object), should know very little about how to use and work with the object. It should have to set up the object. It should be done for you when you use the object. You want to hide away (abstract) the complexity.
You’ll also learn about a shorthand method of using a variable to point to the property, e.g. $this->{$property} = $value;
. This technique saves you code and redundancy.
To view the rest of this write-up, please log in or Go Pro.
You will grow in this profession when you incrementally and systematically stretch yourself....bit-by-bit.
Episodes
Total Lab Runtime: 03:04:55
- 1 Lab Introductionfree 08:27
- 2 What is Object-Oriented Programming (OOP)?free 14:14
- 3 What is an object?free 13:30
- 4 Meet the Class Blueprintpro 04:53
- 5 Creating an Objectpro 07:57
- 6 Defining Characteristicspro 10:54
- 7 Putting the Object to Workpro 13:56
- 8 Hiding Away the Complexitypro 22:40
- 9 Working within the Object with $thispro 15:41
- 10 Internal Control of Object Creationpro 15:07
- 11 Class Constantspro 08:58
- 12 Class Staticpro 17:49
- 13 What OOP is Notpro 19:11
- 14 Practical Examplespro 04:52
- 15 Wrap it Uppro 06:46