{"id":14,"date":"2008-12-23T18:57:38","date_gmt":"2008-12-24T02:57:38","guid":{"rendered":"http:\/\/kai.mactane.org\/blog\/?p=14"},"modified":"2008-12-23T18:57:38","modified_gmt":"2008-12-24T02:57:38","slug":"grousing-about-phps-limitations","status":"publish","type":"post","link":"https:\/\/kagan.mactane.org\/blog\/2008\/12\/23\/grousing-about-phps-limitations\/","title":{"rendered":"Grousing About PHP&#8217;s Limitations"},"content":{"rendered":"<p>Drat. I would like to chase back up the class hierarchy of a bunch objects, and then do something based on the second-from-the-top of that chain. (For example, when the chain goes <code>Word&nbsp;> Noun&nbsp;> Animal&nbsp;> Mammal&nbsp;>&nbsp;Human<\/code>, and I&#8217;ve instantiated a <code>Human<\/code>, I&#8217;d like that object to be able to tell that it&#8217;s a <code>Noun<\/code>.)<\/p>\n<p>Unfortunately, I&#8217;m doing this in PHP, and it&#8217;s not possible to get a class&#8217; parent&nbsp;&mdash; all you can do is find the parent of an instantiated object. So, in order to chase back up the class hierarchy, I&#8217;d have to instantiate one of each object type&#8230; and that would require coming up with parameters for each one, because these aren&#8217;t the sorts of things you can just create as anonymous items with no values.<\/p>\n<p>I tried creating a static <code>getParent()<\/code> method in the top-level object, but then when I do the static call on a subclass (e.g., <code>Human::getParent()<\/code>, which should return <code>Mammal<\/code>), it apparently calls <code>Word::getParent()<\/code> anyway (and that complains that it <em>has<\/em> no parent class&#8230;)<\/p>\n<p>I expect I&#8217;ll be running up against more and more of PHP&#8217;s limitations in the near future, now that I&#8217;ve gotten more accustomed to concepts like functional programming, introspection, and so on.<\/p>\n<p>A quick glance at <a href=\"http:\/\/www.ruby-doc.org\/core\/classes\/Class.html\">the Ruby Class documentation<\/a> makes it painfully obvious how easy this would be in Ruby. While native JavaScript doesn&#8217;t support such things, Prototype.js does&nbsp;&mdash; down <a href=\"http:\/\/www.prototypejs.org\/learn\/class-inheritance\">at the bottom of this page<\/a>, under &#8220;Special Class Properties&#8221;, it mentions the subclasses and superclass properties, and gives handy examples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Drat. I would like to chase back up the class hierarchy of a bunch objects, and then do something based on the second-from-the-top of that chain. (For example, when the chain goes Word&nbsp;> Noun&nbsp;> Animal&nbsp;> Mammal&nbsp;>&nbsp;Human, and I&#8217;ve instantiated a Human, I&#8217;d like that object to be able to tell that it&#8217;s a Noun.) Unfortunately, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,5],"_links":{"self":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":3,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":17,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions\/17"}],"wp:attachment":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}