Join Jon Peck for an in-depth discussion in this video Implementing static methods, part of Object-Oriented Programming with PHP.
- View Offline
- Exercise Files
Static methods are similar to regular methods in a number of ways.…The naming convention is the same, they can have a visibility scope, and static…methods can return values.…However, static methods cannot use the pseudo variable $this to get properties, as…it refers to the current object.…If you want to try anyway, you can, but you will get a fatal error.…Instead, use the self keyword, which refers to the current class.…This sounds a bit abstract,…so I'll demonstrate a static method by implementing an address type id validator.…
I'm going to open the Address class, and then start declaring a static method.…Like static properties,…I'll need to include the static keyword.…Static public function isValidAddressTypeId with one argument ($address_type_id).…Add the documentation, Determine if an address type is valid. We'll take an…integer and return boolean.…
To validate, check to see if the address _type_id is in the array keys of valid…address types. return array_key_exists. The key is the address_type_id. The array…
- 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.