{"id":759,"date":"2022-08-30T15:06:42","date_gmt":"2022-08-30T15:06:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-magic-methods-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:06:42","modified_gmt":"2022-08-30T15:06:42","slug":"problem-about-magic-methods-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-magic-methods-collection-of-common-programming-errors\/","title":{"rendered":"problem about magic-methods-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bc10c7edd7524e1a05de670a3f0399a4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWill<br \/>\nphp oop magic-methods<br \/>\n[edit] updated the title to more accurately reflect the problemThe problem I am trying to solve is this: I need to know if a method was called via parent:: and while I can use debug_backtrace it seems like there must be a better way to do this.I&#8217;ve been looking into late static binding but perhaps I don&#8217;t understand it well enough to fathom a solution.The method in question is __call so I can&#8217;t simply pass in an extra parameter as its an err<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/740009a6e917d24ecdf90e706e5a6514?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nVince<br \/>\nphp oop design-patterns singleton magic-methods<br \/>\nOn many of my websites, I use a homemade PHP class called &#8220;Logger&#8221; (basically, it&#8217;s intended for logging informations into log files, and organizing these files by date : year\/month&#8230; automatically).I&#8217;m using it by creating an instance of Logger in my bootstrap file (included everywhere) :require &#8216;lib\/Logger.class.php&#8217;; $mainLogger = new Logger(&#8216;.\/my_log_folder&#8217;);This forces me to set $mainLogger global in every function that need to log something, and also check if the logger is instantiated before call to any method :function foo($bar){global $mainLog<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/ULJGD.jpg?s=32&amp;g=1\" \/><br \/>\nrfc1484<br \/>\nphp magic-methods<br \/>\nPossible Duplicate:Are Magic Methods Best practice in PHP? These are simple examples, but imagine you have more properties than two in your class.What would be best practice?a) Using __get and __setclass MyClass {private $firstField;private $secondField;public function __get($property) {if (property_exists($this, $property)) {return $this-&gt;$property;}}public function __set($property, $value) {if (property_exists($this, $property)) {$this-&gt;$property = $value;}} }$myC<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9dcb46c0895d6a55ac3f5f71ad8a5dc2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRon<br \/>\nphp doctrine2 zend-framework2 zend-db magic-methods<br \/>\nI read about a magic getter- and setter function which supersede the huge plie of standard getters and setters. (Link)I altered the function of Miles because I&#8217;m using AnnotationForms and don&#8217;t want the underscore in the variables like $_name. I updated the magic functions but when trying to call e.g. getName() I get:Fatal error: Cal<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/xBwfL.jpg?s=32&amp;g=1\" \/><br \/>\nFrancisco Presencia<br \/>\nphp bugs specifications magic-methods<br \/>\nI have experienced something that I think it&#8217;s a bug, but I&#8217;m not sure. So I come here to ask to the people who know more about this than me, is this a PHP bug? Look at the following lines:<\/p>\n<h1>Tests<\/h1>\n<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:39:21. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Will php oop magic-methods [edit] updated the title to more accurately reflect the problemThe problem I am trying to solve is this: I need to know if a method was called via parent:: and while I can use debug_backtrace it seems like there must be a better way to do this.I&#8217;ve been looking into late [&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,8],"tags":[],"class_list":["post-759","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-zend-framework"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/759","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=759"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":8980,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions\/8980"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}