{"id":63,"date":"2006-09-10T15:37:45","date_gmt":"2006-09-10T05:37:45","guid":{"rendered":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/"},"modified":"2006-09-10T15:39:55","modified_gmt":"2006-09-10T05:39:55","slug":"how-object-oriented-is-php","status":"publish","type":"post","link":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/","title":{"rendered":"How Object Oriented is PHP?"},"content":{"rendered":"<p><strong>How OO is PHP?<\/strong><\/p>\n<p>How \u201cobject-oriented\u201d is PHP? Your answer to that question probably depends on your particular litmus tests for object-orientedness. In this sidebar, we offer a whirlwind tour of features that typically show up in OOP languages and briefly discuss the extent to which PHP supports them. Some of these issues are explored more broadly in the section \u201cAdvanced OOP Features,\u201d later in this chapter. (Note: This sidebar is really only of interest to developers who are coming to PHP from a different OO language; everyone else may want to skip this game of buzzword bingo.)<\/p>\n<p><strong>Single inheritance<\/strong><br \/>\nPHP allows a class definition to inherit from another class, using the extends clause. Both member variables and member functions are inherited.<\/p>\n<p><strong>Multiple inheritance<\/strong><br \/>\nPHP offers no support for multiple inheritance and no notion of interface inheritance as in Java. Each class inherits from, at most, one parent class (though a class may implement many interfaces).<\/p>\n<p><!--more--><br \/>\n<strong>Constructors<\/strong><br \/>\nEvery class can have one constructor function, which in PHP is called __construct(). Note that there are two underscore characters at the front of that function name. Because prior to PHP5 (under Zend Engine 1), a class's constructor function had the same name as the class, PHP still allows (but discourages) that strategy for purposes of backward compatibility. Constructors of parent classes are not automatically called but must be invoked explicitly. <\/p>\n<p><strong>Destructors<\/strong><br \/>\nPHP supports explicit destructor functions as of version 5. The destructor function of a class is always called __destruct().<\/p>\n<p><strong>Encapsulation\/access control<\/strong><br \/>\nPHP supports public, private, and protected variables and member functions as of version 5. Polymorphism\/overloading<\/p>\n<p>PHP supports polymorphism in the sense of allowing instance of subclasses to be used in place of parent instances. The correct member function will be dispatched to at runtime. There is no support for method overloading, where dispatch happens based on the method's signature\u2014 each class only has one member function of a given name. However, PHP's weak typing and support for variable numbers of arguments makes workarounds possible. See the section \u201cSimulating polymorphism\u201d later in this chapter (in the section \u201cAdvanced OOP Features\u201d). <\/p>\n<p><strong>Early versus late binding<\/strong><br \/>\nTwo equally good answers are: 1) The question doesn't arise, due to PHP being loosely typed, and 2) All binding is late. In PHP, values are typed but variables are not, so there is no question about what method to call when the variable is of a different type than the value. <\/p>\n<p><strong>Static (or class) functions<\/strong><br \/>\nPHP offers static member variables and static methods as of version 5. It is also possible to call member functions via the Classname::function() syntax.<\/p>\n<p><strong>Introspection<\/strong><br \/>\nPHP offers a wide variety of functions here, including the capability to recover class names, member function names, and member variable names from an instance. (See the section \u201cIntrospection Functions,\u201d later in this chapter.) <\/p>\n<p><em>From Chapter 20 - Object-Oriented Programming with PHP, PHP5 and MySQL Bible.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How OO is PHP? How \u201cobject-oriented\u201d is PHP? Your answer to that question probably depends<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How Object Oriented is PHP?  | Tech Leadership Advice &amp; Resources<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Object Oriented is PHP?  | Tech Leadership Advice &amp; Resources\" \/>\n<meta property=\"og:description\" content=\"How OO is PHP? How \u201cobject-oriented\u201d is PHP? Your answer to that question probably depends\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Leadership Advice &amp; Resources\" \/>\n<meta property=\"article:published_time\" content=\"2006-09-10T05:37:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2006-09-10T05:39:55+00:00\" \/>\n<meta name=\"author\" content=\"Isabel Nyo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isabel Nyo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\"},\"author\":{\"name\":\"Isabel Nyo\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab\"},\"headline\":\"How Object Oriented is PHP?\",\"datePublished\":\"2006-09-10T05:37:45+00:00\",\"dateModified\":\"2006-09-10T05:39:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\"},\"wordCount\":485,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab\"},\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\",\"url\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\",\"name\":\"How Object Oriented is PHP? | Tech Leadership Advice &amp; Resources\",\"isPartOf\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#website\"},\"datePublished\":\"2006-09-10T05:37:45+00:00\",\"dateModified\":\"2006-09-10T05:39:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eisabainyo.net\/weblog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Object Oriented is PHP?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#website\",\"url\":\"https:\/\/eisabainyo.net\/weblog\/\",\"name\":\"Career Resources for Professionals in Tech\",\"description\":\"Books, worksheets, templates, frameworks and other useful resources for Chief Technology Officers (CTOs), VPs of Engineering &amp; Technology Directors\",\"publisher\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eisabainyo.net\/weblog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab\",\"name\":\"Isabel Nyo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3d4b1a4e0f425adb39b242b0d62c5fac07c82f8314a24631f1d16f47bdf006d8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3d4b1a4e0f425adb39b242b0d62c5fac07c82f8314a24631f1d16f47bdf006d8?s=96&d=mm&r=g\",\"caption\":\"Isabel Nyo\"},\"logo\":{\"@id\":\"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/image\/\"},\"description\":\"My interests: Web Development, Web Design, Web Applications, Web 2.0, AJAX, Search Engine Optimisation, Latest Technologies and more..\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Object Oriented is PHP?  | Tech Leadership Advice &amp; Resources","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/","og_locale":"en_US","og_type":"article","og_title":"How Object Oriented is PHP?  | Tech Leadership Advice &amp; Resources","og_description":"How OO is PHP? How \u201cobject-oriented\u201d is PHP? Your answer to that question probably depends","og_url":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/","og_site_name":"Tech Leadership Advice &amp; Resources","article_published_time":"2006-09-10T05:37:45+00:00","article_modified_time":"2006-09-10T05:39:55+00:00","author":"Isabel Nyo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Isabel Nyo","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#article","isPartOf":{"@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/"},"author":{"name":"Isabel Nyo","@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab"},"headline":"How Object Oriented is PHP?","datePublished":"2006-09-10T05:37:45+00:00","dateModified":"2006-09-10T05:39:55+00:00","mainEntityOfPage":{"@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/"},"wordCount":485,"commentCount":0,"publisher":{"@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab"},"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/","url":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/","name":"How Object Oriented is PHP? | Tech Leadership Advice &amp; Resources","isPartOf":{"@id":"https:\/\/eisabainyo.net\/weblog\/#website"},"datePublished":"2006-09-10T05:37:45+00:00","dateModified":"2006-09-10T05:39:55+00:00","breadcrumb":{"@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/eisabainyo.net\/weblog\/2006\/09\/10\/how-object-oriented-is-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eisabainyo.net\/weblog\/"},{"@type":"ListItem","position":2,"name":"How Object Oriented is PHP?"}]},{"@type":"WebSite","@id":"https:\/\/eisabainyo.net\/weblog\/#website","url":"https:\/\/eisabainyo.net\/weblog\/","name":"Career Resources for Professionals in Tech","description":"Books, worksheets, templates, frameworks and other useful resources for Chief Technology Officers (CTOs), VPs of Engineering &amp; Technology Directors","publisher":{"@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eisabainyo.net\/weblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/33457dd19f1ad9bbd4b0cb50c54dfcab","name":"Isabel Nyo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3d4b1a4e0f425adb39b242b0d62c5fac07c82f8314a24631f1d16f47bdf006d8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3d4b1a4e0f425adb39b242b0d62c5fac07c82f8314a24631f1d16f47bdf006d8?s=96&d=mm&r=g","caption":"Isabel Nyo"},"logo":{"@id":"https:\/\/eisabainyo.net\/weblog\/#\/schema\/person\/image\/"},"description":"My interests: Web Development, Web Design, Web Applications, Web 2.0, AJAX, Search Engine Optimisation, Latest Technologies and more.."}]}},"_links":{"self":[{"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eisabainyo.net\/weblog\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}