PHP Abstract Class Primer Tutorial

PHP Abstract Class Primer Tutorial

PHP Abstract Class Primer Tutorial

PHP can be written with a functional approach or an Object Oriented (OOPS) approach, and today, we show some OOP approach ideas such as …

  • an abstract class “via abstract class [className] { }
  • another polymorphic (syntax) idea “via public function __call() { }” (continuing on from yesterday’s Xcode Objective-C Polymorphic Array Primer Tutorial ideas)
  • inheritance “via class [childClassName] extends [parentClassName] { }“
  • constructor function “via function __construct() { }
  • class attributes “via function __get($name) { return $this->$name; } and function __set($name, $value) { $this->$name = $value; }
  • special function “via public function __autoload() { }
  • cloning objects “via syntax like $mypublication = clone $mybook;
  • destructor function “via function __destruct() { }” … that has nothing to do, as is often the case

We found the book “PHP and Web Development” by Luke Welling and Laura Thomson, chapter 6, very good for research purposes on this topic.

So for today’s PHP source code oopsabstract.php and its associated live run we have an abstract class called “publication” that helps out classes for “book” and “magazine” (because so much of these class’s functionality is the same, and so, can be more efficiently written into this abstract class, just the once), differentiating between the two by the idea a “book” has an “author” data member while a “magazine” has a “publisher” data member. Either can have a “published date” and we use some “polymorphic” approach to the month part of this date to allow a user to enter the second month of the year as “Feb” or “02” or “2” or “February” (for example). At the end we end up with one object called “$mybook” and one object called “$mymagazine”, and we clone “$mypublication” via “$mybook” to write out the interactive HTML form and footer parts of the web page this PHP creates.


Previous relevant PHP Polymorphic Thoughts Primer Tutorial is shown below.

PHP Polymorphic Thoughts Primer Tutorial

PHP Polymorphic Thoughts Primer Tutorial

We have mentioned the word “polymorphic” at this blog … and we weren’t sneezing m’lord … and you may wonder with the avid PHP fan base here why we don’t talk about “polymorphism” regarding PHP?

Or maybe not … but if you are still here … it is because PHP does not worry about the type of a variable in its function (or class’s method) parameter list … why should it? … it is sooooo generous … but seriously … you either like this, as you go through the world of programming and coding, or not … happens that I love it … because I like substitution and interpretation … but maybe you don’t … anyway … the cute “polymorphic” strengths of other OOP languages such as C++ (refer to Xcode Objective-C Polymorphic Array Primer Tutorial as shown below) is compensated, in a kludgy way, admittedly, with PHP, via the use of the family of functions like …

The beauty and elegance of C++ about this is to be admired, but the brevity of PHP is also admirable, as one function, admittedly a long function/method can handle the whole shebang, given the right shebang’er, that it … just feel like saying “suffering succotash”.

Anyway, try out a live run or see the PHP source code you could call add.php

Hope you get a little bit of an inkling of a notion out of today’s thoughts.


Previous relevant Xcode Objective-C Polymorphic Array Primer Tutorial is shown below.

Xcode Objective-C Polymorphic Array Primer Tutorial

Xcode Objective-C Polymorphic Array Primer Tutorial

Have you heard of Objective-C? It is a great object-oriented programming language that builds that object orientation on top of a C programming base. Sounds good (even better than good), and Objective-C is the language of iOS Mobile Apps, so it is definitely in the category of up and coming programming languages. Let’s see what Wikipedia says about it below.

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch.

Originally developed in the early 1980s, it was selected as the main language used by NeXT for its NeXTSTEP operating system, from which OS X and iOS are derived.[1] Generic Objective-C programs that do not use the Cocoa or Cocoa Touch libraries, or using parts that is ported or reimplemented for other systems can also be compiled for any system supported by GCC or Clang.

In this primer tutorial we see how Xcode can supervise an Objective-C Desktop Application project to define a Polymorphic Array, and call the methods this array points to.

Previous C++ XCode OOP Polymorphic Array Tutorial is of interest for compare and contrast purposes and is shown further below.

Regarding this Objective-C Polymorphic Array tutorial topic I really like β€œObjective-C” Visual Quickstart Guide by Steven Holzner.

Also like this link with regard to Polymorphic Arrays.

Here are links to programming source code which shows some use of a Polymorphic Array, which you should rename to main.m

Link to Objective-C more information … via Wikipedia, where quote above came from..


Previous C++ XCode OOP Polymorphic Array Tutorial is of interest for compare and contrast purposes and is shown below.

C++ XCode OOP Polymorphic Array Tutorial

C++ XCode OOP Polymorphic Array Tutorial

Here is a tutorial that introduces you to some more aspects of OOP … oops, forgot to say what OOP stands for … Object Oriented Programming … specifically regarding Polymorphic Arrays.

Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.

To me, the beauty of OOP is that it can relate to the nouns in our life. Think of an object that you can touch, like a wristwatch … it has features like its type of design, its size, its weight (ie. its properties), and it has objects that go to make it up, like cogs and wheels (ie. its components), and it has its related classes of objects like clock, alarm clock, oven timer etcetera (ie. its characteristics), and its more fundamental essence, the class of watch (ie. its inheritance).

In this tutorial we touch on Polymorphic Arrays and the use of an Abstract Base Class and Two Subclasses which contribute to the types within this array. Has some similarities to MultiCulturalism perhaps?

Let’s see some C++ using XCode for this …

Link to Object Oriented Programming information … from Wikipedia from which quote above comes.
Link to Object Oriented Programming inventor information … Kristen Nygaard.
Also like this link with regard to Polymorphic Arrays.
Link to some downloadable programming code … rename to main.cpp for use.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, OOP, Tutorials and tagged , , , , , , . Bookmark the permalink.

7 Responses to PHP Abstract Class Primer Tutorial

  1. For newest news you have to go to see world-wide-web and on the web I
    found this site as a best web site for most up-to-date updates.

  2. Messty Angel says:

    I like what you guys are up also. Such clever work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website :)

  3. Luke Thomson says:

    I know this webste provies quality based posts annd otger information, is there any other site which provides these kinds of data inn quality?Also visit my page Make it Rain The Love of Money Cheat Tool

  4. Warren Ogden says:

    Thank you for sharing superb informations. Your web-site is so cool. I am impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched everywhere and simply couldn’t come across. What a great web site.

  5. Wow! This can be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Fantastic. I am also an expert in this topic therefore I can understand your effort.

  6. Great information. Lucky me I discovered your website by accident (stumbleupon). I have book marked it for later!

  7. Some really choice articles on this internet site , saved to fav.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>