{"id":273,"date":"2014-02-05T02:21:44","date_gmt":"2014-02-05T02:21:44","guid":{"rendered":"http:\/\/aurelio.audero.it\/blog\/?p=273"},"modified":"2024-12-24T02:15:22","modified_gmt":"2024-12-24T02:15:22","slug":"why-people-think-php-sucks","status":"publish","type":"post","link":"https:\/\/www.audero.it\/blog\/2014\/02\/05\/why-people-think-php-sucks\/","title":{"rendered":"Why People Think PHP Sucks!"},"content":{"rendered":"<p>A long time has been passed since the first release of PHP. Over the years the language has been improved a lot, in terms of performance and features, thanks to the work of many contributors. At the same time, also its adoption among developers is grown dramatically. Looking at the latest statistics, <a href=\"https:\/\/w3techs.com\/technologies\/overview\/programming_language\" target=\"_blank\" rel=\"noopener\">PHP is used on the 81.7% of all websites<\/a>; an outstanding result. Nonetheless, several top companies and developers have always looked at PHP as a kind of bad, silly, and for snotty kids language.<\/p>\n<p>In this highly opinionated article, I&#8217;ll try to explain some of the reasons behind these judges. I&#8217;ve collected them over the time, talking with other developers and reading some articles spread on the web.<br \/>\n<!--more--><\/p>\n<p><b>Note:<\/b> Some of you might be really bothered after reading this article. I understand you, but I think that, as developers of the same community, we have to understand what people complain about our language of choice, and how we can improve the language itself. Moreover, knowing what people think are the weak points of PHP, we might prepare ourselves in explaining others which of them are just false myths caused by the misinformation.<\/p>\n<h2>Introduction<\/h2>\n<p>As I said, PHP is widely used over the web as a backend language and its grown is increasing very fast. In fact, until few months ago its usage was at ~75%, a gain of the 6% in a relatively small amount of time. If you&#8217;ve been a PHP developer for a while now, you know that it&#8217;s usually hated by a lot of colleagues and it&#8217;s felt as a language that a serious company can&#8217;t employ. Sometimes I think PHP is as hated as (older versions of) Internet Explorer by web designers. After all, as <cite>Bjarne Stroustrup<\/cite>, who designed and implemented the C++ language, said <q>There are only two kinds of programming languages: those people always bitch about and those nobody uses.<\/q><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"782\" data-permalink=\"https:\/\/www.audero.it\/blog\/2014\/02\/05\/why-people-think-php-sucks\/php-elephants\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-elephants.jpg\" data-orig-size=\"600,321\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-elephants.jpg\" src=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-elephants.jpg\" alt=\"PHP elephants\" width=\"600\" height=\"321\" class=\"aligncenter size-full wp-image-782\" srcset=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-elephants.jpg 600w, https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-elephants-300x161.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Now that you should have enough context, we can delve into the discussion. So, without further ado, let&#8217;s discuss the main points PHP is blamed of.<\/p>\n<h2>Spaghetti Code<\/h2>\n<p>The topic discussed in this article is so well-known that a lot talks have been given about it. One of these talks, that I had the chance to attend few months ago, was <a href=\"https:\/\/speakerdeck.com\/nesquick\/whats-wrong-with-php-4\" target=\"_blank\" rel=\"noopener\"><cite>What&#8217;s wrong with PHP?<\/cite><\/a> by Ole Michaelis. In his talk, he asserted that the main reason behind this hate is the spaghetti code that old developers (those coming from PHP 3) or beginner developers have written over the time. He also included the version of himself at the beginning of his career and, to be honest, I have to include myself too. You know, everyone is a beginner at the start. Apart from this consideration, I strongly disagree with his analysis. In fact, the same kind of spaghetti code can be written in other &#8220;more enterprise&#8221; languages like Java. An example? I don&#8217;t have to look much far from myself. Not so much years ago, I developed a website using Java EE, because at my University people usually use it, and my JSP pages were full of spaghetti code (being Italian, I love spaghetti!).<\/p>\n<p>Apart from the jokes, the point is that PHP can&#8217;t be blamed of encouraging beginners to write bad code. In every language you can find this practice because it&#8217;s usually the style beginners have. Moreover, today PHP has the same high level tools (<a href=\"https:\/\/getcomposer.org\/\" target=\"_blank\" rel=\"noopener\">Composer<\/a>, <a href=\"https:\/\/phpmd.org\/\" target=\"_blank\" rel=\"noopener\">PHPMD<\/a>, <a href=\"https:\/\/github.com\/squizlabs\/PHP_CodeSniffer\" target=\"_blank\" rel=\"noopener\">PHPCS<\/a>) and frameworks (<a href=\"https:\/\/phpunit.de\/\" target=\"_blank\" rel=\"noopener\">PHPUnit<\/a>, <a href=\"https:\/\/twig.symfony.com\/\" target=\"_blank\" rel=\"noopener\">Twig<\/a>, <a href=\"https:\/\/symfony.com\/\" target=\"_blank\" rel=\"noopener\">Symphony<\/a>, <a href=\"https:\/\/framework.zend.com\/\" target=\"_blank\" rel=\"noopener\">Zend Framework<\/a>) that you can find in other praised languages. In conclusion, my take is that this is surely one of the false myths we have to fight.<\/p>\n<h2>A Not-Enterprise Language<\/h2>\n<p>Many developers say PHP can&#8217;t be used on serious, high volume, and resource intensive websites. In my opinion, this is another false myth. PHP is reliably used by a lot of top companies like Facebook, Wikipedia, Yahoo, YouPorn (<a href=\"https:\/\/x.com\/AurelioDeRosa\/status\/342710072721408001\" target=\"_blank\" rel=\"noopener\">I tweeted about this<\/a>) and much more, for their products. And if these companies can use PHP, your company can use it too. No other words are needed.<\/p>\n<h2>Design<\/h2>\n<p>This is one of the most hot and frequent point I heard from PHP&#8217;s haters. Because the subject is really broad, I&#8217;ll cover just some of them, splitting the discussion in sections.<\/p>\n<h3>Inheritance<\/h3>\n<p>One of the most frequent complaints I hear about PHP is about its inheritance model. Developers are confused about the inheritance type exposed by PHP. Until few years ago, if anyone had asked me &#8220;What type of inheritance is allowed in PHP?&#8221; I would have firmly and rapidly answered &#8220;Single!&#8221;. Then, after <a href=\"https:\/\/www.sitepoint.com\/using-traits-in-php-5-4\/\" target=\"_blank\" rel=\"noopener\">the introduction of traits in PHP 5.4<\/a>, I continue to answer in the same way but just&#8230;less firmly. Let&#8217;s talk clearly: PHP <em>has<\/em> single inheritance but traits allow for a sort of multiple inheritance. So, if people are right or not on this point depends on your point of view. On my side I can&#8217;t say they are totally wrong.<\/p>\n<h3>Functions Naming Inconsistencies<\/h3>\n<p>As a PHP developer you should be aware of the lot of inconsistencies the language exposes. Let&#8217;s see some examples:<\/p>\n<ul>\n<li>Array functions starting with array_ and not: <code>array_merge<\/code> vs <code>arsort<\/code>, <code>array_flip<\/code> vs <code>shuffle<\/code><\/li>\n<li>Underscored vs Not underscored names: <code>htmlentities<\/code> vs <code>html_entity_decode<\/code>, <code>htmlspecialchars_ decode<\/code> vs <code>htmlspecialchars<\/code><\/li>\n<li>To vs 2: <code>bin2hex<\/code>, <code>deg2rad<\/code>, <code>strtolower<\/code>, <code>strtotime<\/code><\/li>\n<li>Arguments order: <code>strpos($haystack, $needle)<\/code> vs <code>array_search($needle, $haystack)<\/code><\/li>\n<li>Object+verb vs verb+object: <code>str_shuffle<\/code> vs <code>create_function<\/code><\/li>\n<\/ul>\n<p>I have to admit that I agree with this point. It&#8217;s not very easy to remember all these exceptions and I think this should not be necessary. Fortunately for us we have IDE that help us with functions name, but I really hope in a refactoring to achieve a more consistent naming sooner or later.<\/p>\n<h3>Other Design Oddities<\/h3>\n<p>This section lists some other PHP&#8217;s oddities, in random order, that people complain about that I&#8217;ve heard:<\/p>\n<ul>\n<li>PHP is the unique language where the ternary operator (<code>?<\/code>) is left associative<\/li>\n<li>Silly error messages like the famous <code>T_PAAMAYIM_NEKUDOTAYIM<\/code><\/li>\n<li>The plethora of aliases that lead to confusion: <code>sizeof<\/code>\/<code>count<\/code>, <code>is_int<\/code>\/<code>is_integer<\/code>, <code>implode<\/code>\/<code>join<\/code>, <code>die<\/code>\/<code>exit<\/code><\/li>\n<li>The <a href=\"https:\/\/www.php.net\/manual\/en\/types.comparisons.php\" target=\"_blank\" rel=\"noopener\">PHP type comparison tables<\/a><\/li>\n<\/ul>\n<h2>Conclusions<\/h2>\n<p>There a lot of other stuff I could have mentioned that I&#8217;ve heard or read, but continuing the list is pointless and, honestly, I can&#8217;t remember them all. The fact is that we should be aware that PHP isn&#8217;t perfect and it has several points to improve. Nonetheless, we should also be able to point out what are false myths.<\/p>\n<p>If after reading this article you feel sad about your favourite language, don&#8217;t mind. As <a href=\"https:\/\/speakerdeck.com\/aurelioderosa\/people-dont-give-a-f-star-star-k-of-javascript-codemotion-madrid-2013\" target=\"_blank\" rel=\"noopener\">I said in my talk<\/a> few months ago <q>People want to perform tasks, not listen you talking about programming languages. So, use the one you feel more comfortable with and just release the next big thing.<\/q><\/p>\n<p>People usually love to have an &#8220;enemy&#8221; or something to complain about. But, as we&#8217;ve seen in this article, some of the things that other developers charge to PHP are just false myths or bullshits (as <a href=\"https:\/\/www.slideshare.net\/slideshow\/death-to-bullshit-now-with-80-more-bullshit\/25849640\" target=\"_blank\" rel=\"noopener\">Brad Frost loves to talk about<\/a>). So, as far as you&#8217;re happy with PHP, as I am, continue to use it. I hope you enjoyed the article and that it gave you the chance to ponder about some PHP oddities and how you can protect your language of choice.<\/p>\n<p>To conclude, in case you&#8217;re curious to read articles where people complain about PHP, here is a short list:<\/p>\n<ul>\n<li><a href=\"http:\/\/phpsadness.com\/\" target=\"_blank\" rel=\"noopener\">PHP Sadness<\/a><\/li>\n<li><a href=\"https:\/\/eev.ee\/blog\/2012\/04\/09\/php-a-fractal-of-bad-design\/\" target=\"_blank\" rel=\"noopener\">PHP: a fractal of bad design<\/a><\/li>\n<li><a href=\"https:\/\/www.quaxio.com\/wtf\/php.html\" target=\"_blank\" rel=\"noopener\">PHP turtles<\/a><\/li>\n<li><a href=\"https:\/\/web.archive.org\/web\/20170731175134\/http:\/\/www.phpwtf.org:80\/\" target=\"_blank\" rel=\"noopener\">PHP WTF<\/a><\/li>\n<\/ul>\n<p>Good read!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A long time has been passed since the first release of PHP. Over the years the language has been improved a lot, in terms of performance and features, thanks to the work of many contributors. At the same time, also its adoption among developers is grown dramatically. Looking at the latest statistics, <a href=\"https:\/\/w3techs.com\/technologies\/overview\/programming_language\" target=\"_blank\" rel=\"noopener\">PHP is used on the 81.7% of all websites<\/a>; an outstanding result. Nonetheless, several top companies and developers have always looked at PHP as a kind of bad, silly, and for snotty kids language.<\/p>\n<p>In this highly opinionated article, I&#8217;ll try to explain some of the reasons behind these judges. I&#8217;ve collected them over the time, talking with other developers and reading some articles spread on the web.<\/p>\n","protected":false},"author":1,"featured_media":285,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7,2],"tags":[47,11],"class_list":["post-273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-discussions-opinions","category-php","tag-php","tag-web"],"jetpack_featured_media_url":"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2014\/02\/php-logo.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9Or4e-4p","jetpack-related-posts":[{"id":14,"url":"https:\/\/www.audero.it\/blog\/2013\/05\/09\/how-to-change-the-default-view-in-zend-framework-1\/","url_meta":{"origin":273,"position":0},"title":"How to Change the Default View in Zend Framework 1","author":"Aurelio De Rosa","date":"May 9, 2013","format":false,"excerpt":"In this article I'll give you a little tip about a situation which often arises during the development of a website or a web application based on the Zend Framework 1. I'll explain how you can change the default view of a given action.","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/www.audero.it\/blog\/category\/php\/"},"img":{"alt_text":"Zend Framework banner","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/05\/zend-framework-banner.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":329,"url":"https:\/\/www.audero.it\/blog\/2014\/09\/19\/resources-beginner-front-end-developers\/","url_meta":{"origin":273,"position":1},"title":"Resources for Beginner Front-end Developers","author":"Aurelio De Rosa","date":"September 19, 2014","format":false,"excerpt":"Few weeks ago I received an email from a developer asking me for suggestions on how to delve into the front-end world. After having replied to this email, I thought that it'd have been nice to share the same suggestions on my blog. That's exactly what you'll find in this\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"html5 css3 javascript logos","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":305,"url":"https:\/\/www.audero.it\/blog\/2014\/07\/15\/my-experience-at-4developers-2014\/","url_meta":{"origin":273,"position":2},"title":"My Experience at 4Developers 2014","author":"Aurelio De Rosa","date":"July 15, 2014","format":false,"excerpt":"In March I announced via Twitter my participation as a speaker at 4Developers 2014. 4Developers\u00a02014 was a single-day, multi-track and multi-language conference held in the lovely Warsaw on the 7th of April\u00a02014\u00a0at the\u00a0Gromada Airport Hotel. The tracks for the edition of this year were: Java, .Net, PHP, Python, Front-end (HTML5,\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"Logo panel 4developers 2014","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2014\/07\/logo-panel-4developers-2014-225x300.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5,"url":"https:\/\/www.audero.it\/blog\/2013\/05\/13\/learning-curve-what-it-is-and-how-it-applies-to-information-technology\/","url_meta":{"origin":273,"position":3},"title":"Learning Curve: What it is and How it Applies to Information Technology","author":"Aurelio De Rosa","date":"May 13, 2013","format":false,"excerpt":"The terms \"learning curve\" and \"steep learning curve\" are often talked and written in Computer Science. At the time I could not understand deeply those terms, every time I found them I felt like I was missing something that all programmers except me already knew. After, I realised that there\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"Tic Tac Toe learning curve","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/05\/tic-tac-toe-learning-curve.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":197,"url":"https:\/\/www.audero.it\/blog\/2013\/12\/23\/enhancing-the-abbr-element-on-mobile\/","url_meta":{"origin":273,"position":4},"title":"Enhancing the abbr Element on Mobile","author":"Aurelio De Rosa","date":"December 23, 2013","format":false,"excerpt":"Today's world runs fast, really fast. When writing, a lot of people use abbreviations and acronyms to save time that we can find spread all over the web. They are so used that an HTML tag, <abbr>, was created to identify them and help the semantic of web pages. In\u2026","rel":"","context":"In &quot;CSS&quot;","block_context":{"text":"CSS","link":"https:\/\/www.audero.it\/blog\/category\/css\/"},"img":{"alt_text":"The abbr tag unstyled","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-unstyled.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":553,"url":"https:\/\/www.audero.it\/blog\/2016\/08\/03\/power-simplicity-code\/","url_meta":{"origin":273,"position":5},"title":"The power of simplicity in code","author":"Aurelio De Rosa","date":"August 3, 2016","format":false,"excerpt":"A\u00a0few days ago I found an online test\u00a0featuring six exercises on JavaScript. For fun, whishing to challenge myself with something tricky, I decided to take it.\u00a0The test proved to be very simple, so it isn't worth a discussion. It's what happened next that inspired this article. I was talking with\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2016\/08\/code-simplicity.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":25,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions\/985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media\/285"}],"wp:attachment":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}