Wednesday , 12 December 2018
Magic Methods

Magic Methods – PHP OOP Tutorial

PHP provides some magic methods that run when an event occurs. You’ve already seen an example of a magic method with the __construct() method. This method runs when a user creates an instance of the Pet class.  Let’s take a look at some of the other magic methods we can use in our classes. Using Magic Methods In your pet.class.php …

Read More »
Interfaces

Interfaces – PHP OOP Tutorial

In this tutorial, you’ll learn how to create interfaces and why you should use them. They are very similar to abstract classes. At the end of this tutorial, we’ll discuss the differences and the benefits of each one. We’ll be creating something similar to our recipe and cookie class in our abstraction tutorial. Creating Interfaces Create a file called index.php …

Read More »
Abstract Classes

Abstract Classes – PHP OOP Tutorial

Today, we’ll be discussing what abstract classes are and how we could use them. There will be times where you’ll create a class that you don’t want anyone to use directly, but instead extend it. Let’s take a closer look at this Creating Abstract Classes We’re going to deviate from our Pet class for a bit. Mostly because we don’t …

Read More »
Static Methods and Properties

Static Methods and Properties – PHP OOP Tutorial

Let’s learn how to create static methods and properties. Anything that’s static is basically something that can be accessed without needing an instantiation of the class. You also have the advantage of having a value that is consistent through each instance of the class. Let’s take a look at this. Creating Static Properties Inside our Pet Class, add this bit of …

Read More »
Constants

Constants – PHP OOP Tutorial

Constants are variables that don’t change value during the lifetime of a program. Defining constants in classes are a bit different than defining constants outside of a class. Defining Constants In our CanadianPet class, add this bit of code. [crayon-5c11526c7bc90276239131/] To define a constant, we use the const keyword. We then follow it by the name of the constant and …

Read More »
Scope Resolution Operator

Scope Resolution Operator – PHP OOP Tutorial

The scope resolution operator may sound intimidating, but it’s actually quite simple to use. What it basically does is it allows you to access static, constant, or overridden methods and properties of a class. We haven’t discussed static and constant properties and methods yet. We will soon in a another tutorial, but for now, we can use it to access …

Read More »
Inheritance

Inheritance – PHP OOP Tutorial

Let’s talk about inheritance. We’ve talked about how to extend a class and covered encapsulation. Inheritance is when a class extends another class and inherits the properties and methods of that class. The main advantage to this is the ability to use a parent class and modify it for a special use without actually modifying the actual class itself. You …

Read More »
Constructor Method

Constructor Method – PHP OOP Tutorial

It’s always good practice to have things set up when someone creates an instance of your class instead of calling a bunch of functions to do so. Users should only have to call set methods when they need to update or change some properties in your class. The constructor method is the perfect solution to setting up your class for …

Read More »
Encapsulation

Encapsulation – PHP OOP Tutorial

Encapsulation may seem like an intimidating topic, but it’s actually quite simple. Object oriented programming is based on 3 principles which are encapsulation, inheritance, and polymorphism. In this tutorial, we’ll be talking about encapsulation and why it’s important to understand this principle. We’ll talk about the other 2 in future tutorials. What is encapsulation? So, what is the meaning behind …

Read More »
Extending Classes

Extending Classes – PHP OOP Tutorial

Let’s talk about extending classes for a moment. One of the benefits of using classes is that it’s easy to share your classes with other developers. They can extend the class if you allow them to.  So instead of going into your class and updating the code, they can create a different class that only changes a few things here …

Read More »
Properties and Methods

Properties and Methods – PHP OOP Tutorial

Now, that we’ve covered some of the basics about object oriented programming, let’s move onto the next step. We’re going to learn about properties and methods. We’ll learn about what they are and how to use them. Using Properties and Methods Open up your pet.class.php file and update our class to this. [crayon-5c11526c7f820803186746/] We create a variable named petName. We …

Read More »
Classes, Instances, Instances

Classes, Objects, Instances – PHP OOP Tutorial

Let’s get started by creating our first class and learn a little about what classes, objects, and instances really are. You’ll find that creating classes isn’t so hard. Create a new file called pet.class.php. You don’t have to append the .class after your file name, but it’s common practice to do that so other developers know that this file contains …

Read More »
PHP OOP Tutorial

Getting Started – PHP OOP Tutorial

Welcome! This PHP OOP tutorial series will help you get started with object oriented programming in PHP. If you’ve ever wanted to expand your knowledge, then you’ve come to right place. By learning how to use OOP, you open up new doors that will make your code more efficient and flexible. Before you get started This tutorial assumes you have …

Read More »
Conclusion

Conclusion – WordPress Theme Tutorial

Congratulations! You now know how to create a WordPress theme. Of course, your journey isn’t over yet. You should take it to the next level by learning how to create Plugins. You should understand that WordPress offers it’s APIs for both plugins and themes. For a list of WordPress’s APIs then click here. http://codex.wordpress.org/WordPress_APIs While we didn’t cover these APIs, …

Read More »
Custom Templates

Custom Templates – WordPress Theme Tutorial

By creating our own templates for certain pages, we make our theme dynamic and flexible. Though, in some situations you’ll want to create a template that WordPress isn’t aware of. For example, our page template is one way to display a page, but what if we wanted a full width page instead of one with widgets. We still want to …

Read More »