{"id":3695,"date":"2014-03-29T08:04:34","date_gmt":"2014-03-29T08:04:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/cast-subclass-to-another-subclass-collection-of-common-programming-errors\/"},"modified":"2014-03-29T08:04:34","modified_gmt":"2014-03-29T08:04:34","slug":"cast-subclass-to-another-subclass-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/cast-subclass-to-another-subclass-collection-of-common-programming-errors\/","title":{"rendered":"cast subclass to another subclass-Collection of common programming errors"},"content":{"rendered":"<p>You don&#8217;t cast classes, you cast references to <em>instances<\/em> of classes. And note that if you have an instance of one subclass and cast it to another subclass, that will cause a runtime error. You can only cast something to be something that it is (e.g., you can cast an <code>OpenRequest<\/code> as a <code>Request<\/code>, because all <code>OpenRequest<\/code>s are <code>Request<\/code>s); if you try to cast it to be something that it isn&#8217;t (casting an <code>OpenRequest<\/code> as a <code>CloseRequest<\/code>, for instance), that will fail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You don&#8217;t cast classes, you cast references to instances of classes. And note that if you have an instance of one subclass and cast it to another subclass, that will cause a runtime error. You can only cast something to be something that it is (e.g., you can cast an OpenRequest as a Request, because [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3695","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3695"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3695\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}