{"id":18611,"date":"2013-09-17T10:11:40","date_gmt":"2013-09-17T08:11:40","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=18611"},"modified":"2013-09-17T10:11:40","modified_gmt":"2013-09-17T08:11:40","slug":"php-self-vs-static","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2013\/09\/17\/php-self-vs-static\/","title":{"rendered":"PHP: self:: vs. static::"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>I am seeing more and more PHP code with <em>static::<\/em> key used for method calls instead of <em>self::<\/em>. \u00a0Today I&#8217;ve finally found some time to examine the novelty. \u00a0The page that is useful for more details is <a href=\"http:\/\/www.php.net\/manual\/en\/language.oop5.late-static-bindings.php\">PHP&#8217;s late static binding<\/a>. \u00a0This functionality is available since PHP 5.3.0 so you might as well start using it.<\/p>\n<p>I am a bit protective of my code, so <em>self::<\/em> feels like a safer, more natural option. \u00a0But after thinking about it for a bit, and discussing with my colleagues, I came to the conclusion that I should be using <em>static::<\/em> instead of <em>self::<\/em>. \u00a0It provides cleaner inheritance and minimizes code copy-pasting.<\/p>\n<p>&nbsp;<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>I am seeing more and more PHP code with static:: key used for method calls instead of self::. \u00a0Today I&#8217;ve finally found some time to examine the novelty. \u00a0The page that is useful for more details is PHP&#8217;s late static binding. \u00a0This functionality is available since PHP 5.3.0 so you might as well start using &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2013\/09\/17\/php-self-vs-static\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PHP: self:: vs. static::<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,18,62],"tags":[3083,38],"keyring_services":[],"class_list":["post-18611","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","category-technology","tag-oop","tag-php"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":28567,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/05\/09\/phpmetrics-static-analysis-tool-for-php\/","url_meta":{"origin":18611,"position":0},"title":"PhpMetrics &#8211; static analysis tool for PHP","author":"Leonid Mamchenkov","date":"May 9, 2018","format":false,"excerpt":"PhpMetrics is yet another tool in the ever growing list of the static code analyzers for PHP.\u00a0 Compared to the rest, I think this one is the easiest to install and run.\u00a0 And it produces the most eye candy reports ever.\u00a0 The generated report is in the HTML format, with\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2018\/05\/phpmetrics-500x253.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":27105,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/12\/11\/php-static-analysis-tool-discover-bugs-in-your-code-without-running-it\/","url_meta":{"origin":18611,"position":1},"title":"PHP Static Analysis Tool &#8211; discover bugs in your code without running it!","author":"Leonid Mamchenkov","date":"December 11, 2016","format":false,"excerpt":"Ond\u0159ej Mirtes shares the idea behind the creation of\u00a0PHPStan - a static analysis tool for PHP: Compiled languages need to know about the type of every variable, return type of every method etc. before the program runs. This is why the compiler needs to make sure that the program is\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27279,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/01\/30\/sharing-constants-between-php-classes\/","url_meta":{"origin":18611,"position":2},"title":"Sharing constants between PHP classes","author":"Leonid Mamchenkov","date":"January 30, 2017","format":false,"excerpt":"When writing larger applications, it is often useful to have some constants defined, which can then be shared between different parts of the application. \u00a0There are several ways to do this, and there is no real rocket science here. However, the question is: what's the best way to do so?\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27245,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/01\/16\/phpmetrics-a-static-analysis-tool-for-php\/","url_meta":{"origin":18611,"position":3},"title":"PhpMetrics &#8211; a static analysis tool for PHP","author":"Leonid Mamchenkov","date":"January 16, 2017","format":false,"excerpt":"PHPMetrics is yet another tool for static analysis of your PHP codebase. \u00a0It aims to provide a simpler and easier to understand report, than all those other tools in the PHP ecosystem today.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/01\/animated-demo-annoted-500x329.gif?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":28519,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/04\/25\/php-static-analysis\/","url_meta":{"origin":18611,"position":4},"title":"PHP Static Analysis","author":"Leonid Mamchenkov","date":"April 25, 2018","format":false,"excerpt":"Here are a couple of new tools in addition to previously mentioned PHPStan: Psalm by Vimeo.\u00a0 The cool thing about this static analyzer is that it supports both PHP 5.6 and PHP 7, unlike PHPStan which requires PHP 7.\u00a0 (Yeah, I know PHP 5.6 has reached the\u00a0end of its active\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27641,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/05\/29\/php-smart-analyzer\/","url_meta":{"origin":18611,"position":5},"title":"PHP Smart Analyzer","author":"Leonid Mamchenkov","date":"May 29, 2017","format":false,"excerpt":"PHP Smart Analyzer (or PHPSA for short) is yet another item in a growing list of tools for PHP code static analysis. \u00a0It's in an early alpha state, but looking at the list of goals, it's quite promising. If that's up your valley, have a look also at PHPQA and\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/05\/php-smart-analyzer-500x129.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/18611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=18611"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/18611\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=18611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=18611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=18611"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=18611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}