Join Jon Peck for an in-depth discussion in this video Setting constant values, part of Object-Oriented Programming with PHP.
- View Offline
- Exercise Files
There's a strong possibility that you're already familiar with constants. …They are common place in procedural code. …As a natural extension, it's possible to add a constant to a class, which can be …good for code organization. …A class constant is like a property with a value that never changes. …Constants are useful for defining things like error codes, data structure names, …and values that have no need to change at runtime, if ever. …By associating a constant with a class, a developer can add context rather than …having to resort to long, complicated names. …While constants use the same PHP label naming convention, best practice dictates …that constant names are all in capital letters separated by underscores. …Constants can only contain simple values, so strings, booleans and integers will …work, but an array will not. …To define a constant within a class, start with the keyword "const," followed by the …name with no dollar sign ($), an assignment operator, and a value. …Let's add constant to the address class to store the address type IDs. …
- 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.