{"id":15166,"date":"2015-06-01T05:01:39","date_gmt":"2015-05-31T19:01:39","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=15166"},"modified":"2015-05-31T16:03:10","modified_gmt":"2015-05-31T06:03:10","slug":"php-abstract-class-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-abstract-class-primer-tutorial\/","title":{"rendered":"PHP Abstract Class Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/oopsabstract.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Abstract Class Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/phpabstract.jpg\" title=\"PHP Abstract Class Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Abstract Class Primer Tutorial<\/p><\/div>\n<p>PHP can be written with a functional approach or an Object Oriented (OOPS) approach, and today, we show some OOP approach ideas such as &#8230;<\/p>\n<ul>\n<li>an abstract class &#8220;via <i>abstract class [className] { }<\/i>&#8220;<\/li>\n<li>another polymorphic (syntax) idea &#8220;via <i>public function __call() { }<\/i>&#8221; (continuing on from yesterday&#8217;s <a target=_blank title='Xcode Objective-C Polymorphic Array Primer Tutorial' href='#xopapt'>Xcode Objective-C Polymorphic Array Primer Tutorial<\/a> ideas)<\/li>\n<li>inheritance &#8220;via class [childClassName] <i>extends [parentClassName]<\/i> { }<\/i>&#8220;<\/li>\n<li>constructor function &#8220;via <i>function __construct() { }<\/i>&#8220;<\/li>\n<li>class attributes &#8220;via <i>function __get($name) { return $this->$name; }<\/i> and <i>function __set($name, $value) { $this->$name = $value; }<\/i>&#8220;<\/li>\n<li>special function &#8220;via <i>public function __autoload() { }<\/i>&#8220;<\/li>\n<li>cloning objects &#8220;via syntax like <i>$mypublication = clone $mybook;<\/i>&#8220;<\/li>\n<li>destructor function &#8220;via <i>function __destruct() { }<\/i>&#8221; &#8230; that has nothing to do, as is often the case<\/li>\n<\/ul>\n<p>We found the book &#8220;PHP and Web Development&#8221; by Luke Welling and Laura Thomson, chapter 6, very good for research purposes on this topic.<\/p>\n<p>So for today&#8217;s PHP source code <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/oopsabstract.php_GETME\" title='oopsabstract.php'>oopsabstract.php<\/a> and its associated <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/oopsabstract.php\" title='Click picture'>live run<\/a> we have an abstract class called &#8220;publication&#8221; that helps out classes for &#8220;book&#8221; and &#8220;magazine&#8221; (because so much of these class&#8217;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 &#8220;book&#8221; has an &#8220;author&#8221; data member while a &#8220;magazine&#8221; has a &#8220;publisher&#8221; data member.  Either can have a &#8220;published date&#8221; and we use some &#8220;polymorphic&#8221; approach to the month part of this date to allow a user to enter the second month of the year as &#8220;Feb&#8221; or &#8220;02&#8221; or &#8220;2&#8221; or &#8220;February&#8221; (for example).  At the end we end up with one object called &#8220;$mybook&#8221; and  one object called &#8220;$mymagazine&#8221;, and we clone &#8220;$mypublication&#8221; via &#8220;$mybook&#8221; to write out the interactive HTML form and footer parts of the web page this PHP creates.<\/p>\n<hr>\n<p id=''>Previous relevant <a target=_blank title='PHP Polymorphic Thoughts Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/php-polymorphic-thoughts-primer-tutorial\/'>PHP Polymorphic Thoughts Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/add.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Polymorphic Thoughts Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/phppoly.gif\" title=\"PHP Polymorphic Thoughts Primer Tutorial\" id='ppi' onmouseover=\" this.src=this.src.replace('.jpg','.xgif').replace('.gif','.xjpg').replace('.x','.');   \" \/><\/a><p class=\"wp-caption-text\">PHP Polymorphic Thoughts Primer Tutorial<\/p><\/div>\n<p>We have mentioned the word &#8220;polymorphic&#8221; at this blog &#8230; and we weren&#8217;t sneezing m&#8217;lord &#8230; and you may wonder with the avid PHP fan base here why we don&#8217;t talk about &#8220;polymorphism&#8221; regarding PHP?<\/p>\n<p>Or maybe not &#8230; but if you are still here &#8230; it is because PHP does not worry about the type of a variable in its function (or class&#8217;s method) parameter list &#8230; why should it? &#8230; it is sooooo generous &#8230; but seriously &#8230; you either like this, as you go through the world of programming and coding, or not &#8230; happens that I love it &#8230; because I like substitution and interpretation &#8230; but maybe you don&#8217;t &#8230; anyway &#8230; the cute <a target=_blank title='Polymorphism information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Polymorphism'>&#8220;polymorphic&#8221;<\/a> strengths of other OOP languages such as C++ (refer to  <a target=_blank title='Xcode Objective-C Polymorphic Array Primer Tutorial' href='#xopapt'>Xcode Objective-C Polymorphic Array Primer Tutorial<\/a> as shown below) is compensated, in a kludgy way, admittedly, with PHP, via the use of the family of functions like &#8230;<\/p>\n<ul>\n<li><a target=_blank title='is_callable() and access to other like minded function information' href='http:\/\/php.net\/manual\/en\/function.is-callable.php'>is_callable()<\/a> (or function_exists() or method_exists())<\/li>\n<li><a target=_blank title='is_numeric() and access to other like minded function information' href='http:\/\/php.net\/manual\/en\/function.is-numeric.php'>is_numeric()<\/a><\/li>\n<li><a target=_blank title='is_string() and access to other like minded function information' href='http:\/\/php.net\/manual\/en\/function.is-string.php'>is_string()<\/a><\/li>\n<li><a target=_blank title='is_array() and access to other like minded function information' href='http:\/\/php.net\/manual\/en\/function.is-array.php'>is_array()<\/a><\/li>\n<li><a target=_blank title='is_bool() and access to other like minded function information' href='http:\/\/php.net\/manual\/en\/function.is-bool.php'>is_bool()<\/a><\/li>\n<\/ul>\n<p>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&#8217;er, that it &#8230; just feel like saying <a target=_blank title='ss' href='http:\/\/www.urbandictionary.com\/define.php?term=suffering+succotash'>&#8220;suffering succotash&#8221;<\/a>.<\/p>\n<p>Anyway, try out a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/add.php\" title=\"Click picture\">live run<\/a> or see the PHP source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/add.php_GETME\" title='add.php'>add.php<\/a><\/p>\n<p>Hope you get a little bit of an inkling of a notion out of today&#8217;s thoughts.<\/p>\n<hr>\n<p id='xopapt'>Previous relevant <a target=_blank title='Xcode Objective-C Polymorphic Array Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=4763'>Xcode Objective-C Polymorphic Array Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Objective-C\/PolymorphicArray\/Polymorphic_Array.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Xcode Objective-C Polymorphic Array Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/Objective-C\/PolymorphicArray\/Polymorphic_Array.jpg\" title=\"Xcode Objective-C Polymorphic Array Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Xcode Objective-C Polymorphic Array Primer Tutorial<\/p><\/div>\n<p>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&#8217;s see what Wikipedia says about it below. <\/p>\n<blockquote><p>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.<\/p>\n<p>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.<\/p><\/blockquote>\n<p>In this primer  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/C\/Objective-C\/PolymorphicArray\/Polymorphic_Array.jpg'>tutorial<\/a> we see how Xcode can supervise an Objective-C Desktop Application project to define a <a target=_blank title='Dynamic Array information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Polymorphism_(computer_science)'>Polymorphic Array<\/a>, and call the methods this array points to.<\/p>\n<p>Previous <a target=_blank title='C++ XCode OOP Polymorphic Array Tutorial' href='#prevpoly'>C++ XCode OOP Polymorphic Array Tutorial<\/a> is of interest for compare and contrast purposes and is shown further below.<\/p>\n<p>Regarding this Objective-C Polymorphic Array tutorial topic I really like <em>\u201cObjective-C\u201d<\/em> Visual Quickstart Guide by <em>Steven Holzner<\/em>.<\/p>\n<p>Also like this <a target=_blank title='Polymorphic Array tutorial by Well House Consultants Ltd.' href='http:\/\/www.wellho.net\/resources\/ex.php4?item=c233\/petite.cpp'>link<\/a> with regard to Polymorphic Arrays.<\/p>\n<p>Here are links to programming source code which shows some use of a Polymorphic Array, which you should rename to <a target=_blank title='main.m' href='http:\/\/www.rjmprogramming.com.au\/C\/Objective-C\/PolymorphicArray\/main.m_GETME'>main.m<\/a><\/p>\n<p>Link to Objective-C more information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Objective-C' title='Link to Objective-C more information'>via Wikipedia, where quote above came from.<\/a>.\n<\/p>\n<hr \/>\n<p id='prevpoly'>Previous <a target=_blank title='C++ XCode OOP Polymorphic Array Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=1573'>C++ XCode OOP Polymorphic Array Tutorial<\/a> is of interest for compare and contrast purposes and is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/PolymorphicArray\/\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"C++ XCode OOP Polymorphic Array Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/PolymorphicArray\/PolymorphicArray.jpg\" title=\"C++ XCode OOP Polymorphic Array Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">C++ XCode OOP Polymorphic Array Tutorial<\/p><\/div>\n<p>Here is a tutorial that introduces you to some more aspects of OOP &#8230; oops, forgot to say what OOP stands for &#8230; Object Oriented Programming &#8230; specifically regarding <a target=_blank title='Polymorphism as discussed by Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Polymorphism_%28computer_science%29'>Polymorphic Arrays<\/a>.<\/p>\n<blockquote><p>Object-oriented programming (OOP) is a programming paradigm that represents concepts as &#8220;objects&#8221; 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.<\/p><\/blockquote>\n<p>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 &#8230; 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).<\/p>\n<p>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 <a target=_blank title='MultiCulturalism discussion on Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Multiculturalism'>MultiCulturalism<\/a> perhaps?<\/p>\n<p>Let&#8217;s see some  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/PolymorphicArray\/'>C++ using XCode<\/a> for this &#8230;<\/p>\n<p>Link to Object Oriented Programming information &#8230; <a target=_blank title='OOP' href='http:\/\/en.wikipedia.org\/wiki\/Object-oriented_programming'>from Wikipedia from which quote above comes<\/a>.<br \/>\nLink to Object Oriented Programming inventor information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Kristen_Nygaard' title='Object Oriented Programming inventor ... thanks to Wikipedia, again.'>Kristen Nygaard<\/a>.<br \/>\nAlso like this <a target=_blank title='Polymorphic Array tutorial by Well House Consultants Ltd.' href='http:\/\/www.wellho.net\/resources\/ex.php4?item=c233\/petite.cpp'>link<\/a> with regard to Polymorphic Arrays.<br \/>\nLink to some downloadable programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/PolymorphicArray\/main.cpp_GETME' title='Download me'>main.cpp<\/a> for use.\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d1573' onclick='var dv=document.getElementById(\"d1573\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=C%2B%2B\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d1573' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4763' onclick='var dv=document.getElementById(\"d4763\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Objective-C#content\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4763' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d15140' onclick='var dv=document.getElementById(\"d15140\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=PHP\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d15140' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d15166' onclick='var dv=document.getElementById(\"d15166\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=object\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d15166' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP can be written with a functional approach or an Object Oriented (OOPS) approach, and today, we show some OOP approach ideas such as &#8230; an abstract class &#8220;via abstract class [className] { }&#8220; another polymorphic (syntax) idea &#8220;via public &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-abstract-class-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,28,37],"tags":[210,608,849,875,932,997,1319],"class_list":["post-15166","post","type-post","status-publish","format-standard","hentry","category-elearning","category-oop","category-tutorials","tag-class","tag-inheritance","tag-object","tag-oop","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15166"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=15166"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15166\/revisions"}],"predecessor-version":[{"id":15169,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15166\/revisions\/15169"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=15166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=15166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=15166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}