{"id":457,"date":"2010-01-06T21:34:13","date_gmt":"2010-01-06T21:34:13","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=457"},"modified":"2010-01-06T21:34:34","modified_gmt":"2010-01-06T21:34:34","slug":"extends-class","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/06\/extends-class\/","title":{"rendered":"Extends class"},"content":{"rendered":"<p>Extends a class within php, as described in more detail <a href=\"http:\/\/php.net\/manual\/en\/keyword.extends.php\">here<\/a>.  Basically is making a second class extended from the first class with either making amendments to some of the functions or adding some, this makes the second class the version 2 from the first class (version 1).<\/p>\n<p>The extended class can still call the parent (version 1) class via the <\/p>\n<pre lang=\"php\">\r\nparent::<function etc to call>\r\n<\/pre>\n<p>syntax, which basically means, calling the parent class to do something, for example the parent class may setup the variables of a array whilst the extended version 2 class may sort them into alphabetical order.<\/p>\n<p>Here some code that may make more sense.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\r\n\/* the base class, version 1 as such of a class *\/\r\nclass BaseClass {\r\n    function HiFromMe()\r\n    {\r\n\techo \"\\nHi from the base class\\n\";\r\n    }\r\n    \r\n    function BaseFunction()\r\n    {\r\n\techo \"\\nHi from base function\\n\";\r\n    }\r\n}\r\n\r\n\/* the extended class, this extends from the base class to make it a better (version 2) class *\/\r\nclass ExtendedClass extends BaseClass {\r\n    function HiFromMe()\r\n    {\r\n\techo \"\\nHi from the extended class\\n\";\r\n    }\r\n    \r\n    function CallBaseFunction()\r\n    {\r\n\techo \"\\nCalling base (parent) class\";\r\n\t\/\/ need to put parent:: which means call the parent class\r\n\tparent::BaseFunction();\r\n    }\r\n}\r\n\r\n$base = new BaseClass();\r\n\r\n$base->HiFromMe();\r\n$base->BaseFunction();\r\n\r\n$extended = new ExtendedClass();\r\n\r\n$extended->HiFromMe();\r\necho \"\\nYou can still call the base functions because you extended it\";\r\n$extended->BaseFunction();\r\necho \"\\nTo call from within a function\";\r\n$extended->CallBaseFunction();\r\n?>\r\n\r\nand the output would be... \r\n\r\n<pre lang=\"bash\">\r\nHi from the base class\r\n\r\nHi from base function\r\n\r\nHi from the extended class\r\n\r\nYou can still call the base functions because you extended it\r\nHi from base function\r\n\r\nTo call from within a function\r\nCalling base (parent) class\r\nHi from base function\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Extends a class within php, as described in more detail here. Basically is making a second class extended from the first class with either making amendments to some of the functions or adding some, this makes the second class the version 2 from the first class (version 1). The extended class can still call the &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/06\/extends-class\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Extends class<\/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":[17],"tags":[49],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-php","tag-extends"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":3,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}