Introduction To Object-Oriented Programming With PHP – Part 2

Before beginning this portion, you may be interested in the following:

  1. How to Setup a LOCAL development Environment
  2. How to Setup a VIRTUAL Development Environment
  3. Introduction to this course in general
  4. Part 1 of Introduction to Object-Oriented Programing in PHP

Terminology

As I said in part 1, I believe terminology is key to understanding how the particular technology works. With all the resources online, if you understand the terminology, you can use the internet to help you figure out how to do just about anything. With that in mind, here are the new terms for part 2.

Polymorphism

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface

One good article online is: http://code.tutsplus.com/tutorials/understanding-and-applying-polymorphism-in-php–net-14362

The two main ways polymorphism is used in OOP:

Interface

  • Interface, specifies which methods a class must implement.
  • All methods in interface must be public.
  • Multiple interfaces can be implemented by using comma separation
  • Interface may contain a CONSTANT, but may not be overridden by implementing class

Abstract

An abstract class is a mix between an interface and a class. It can define functionality as well as interface (in the form of abstract methods). Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.

Type Hinting

Type referring to the variable type, such as Integer or String. Type Hinting is telling a method which Type of variable to accept. This is not the same as Type Casting, which is forcing a variable to be a specified type.

Namespaces

  • Help create a new layer of code encapsulation
  • Keep properties from colliding between areas of your code
  • Only classes, interfaces, functions and constants are affected
  • Anything that does not have a namespace is considered in the Global namespace (namespace = “”)
  • must be declared first (except ‘declare)
  • Can define multiple in the same file
  • You can define that something be used in the “Global” namespace by enclosing a non-labeled namespace in {} brackets.
  • Use namespaces from within other namespaces, along with aliasing

Files used in class

Full PHP Script used in presentation:

https://github.com/sketchings/oop-basics

Conclusion / Evaluation

If you are interested in taking this as a hands on workshop, I will be presenting this series at different venues, mostly in the Portland area. Most are free, so please drop me an email and I will let you know about upcoming events.

If you HAVE taken the class, please fill out the evaluation so I can continue to improve this and other lessons.

Leave a Reply

Your email address will not be published. Required fields are marked *