{"id":813,"date":"2014-07-05T10:32:46","date_gmt":"2014-07-05T05:02:46","guid":{"rendered":"https:\/\/cns72.com\/vytcdc.com.sg\/?p=813"},"modified":"2019-11-20T12:22:36","modified_gmt":"2019-11-20T06:52:36","slug":"an-opinion-on-the-future-of-php","status":"publish","type":"post","link":"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/","title":{"rendered":"An Opinion On The Future Of PHP"},"content":{"rendered":"<div style=\"text-align: justify;\">There&#8217;s been a lot of buzz in the <span id=\"lk13440h9h_7\" class=\"lk13440h9h\">community<\/span> lately around PHP and its future. The vast majority of this buzz has been distinctly positive, which is awesome to hear. There&#8217;s been a lot of talk about PHP6 and what that might look like. There&#8217;s been a lot of questions around <span id=\"lk13440h9h_1\" class=\"lk13440h9h\">HHVM<\/span> and its role in the future of the language and community. Well, let me share with you some of my thoughts in this space&#8230; <a name=\"more\"><\/a><\/div>\n<h2>On Backwards Compatibility<\/h2>\n<div style=\"text-align: justify;\">In my opinion, backwards compatibility <strong>must<\/strong> be mostly maintained in a future major release (call it 6, 7, 99, &#8220;enthusiastic elephpant&#8221;, whatever). Now, when I say &#8220;mostly&#8221;, I do mean that some controlled breaks should happen. But those breaks should be well contained and well controlled. They also should ONLY target refining edge-case behavior and the like. That doesn&#8217;t mean there can&#8217;t be major internal refactoring. It doesn&#8217;t mean things can&#8217;t be cleaned up. It just means that they should broken in very controlled ways so as to not hurt user-land developers.<\/div>\n<div style=\"text-align: justify;\">There&#8217;s a really simple test to see if this is maintained:<\/div>\n<blockquote>\n<div style=\"text-align: justify;\">It <strong>must<\/strong> be easy to write a single codebase that executes on 5.X and 6.X (and any two consecutive major versions)<\/div>\n<\/blockquote>\n<div style=\"text-align: justify;\">Why is that important? Well, look at PHP4 &#8211; PHP5 transition. It was pretty easy to write code that worked on both, and it still took nearly 10 years for adoption to switch (in fact, it took a movement called GOPHP5 to pull off). Imagine if it was hard to write code that worked on both?<\/div>\n<div style=\"text-align: justify;\">Well, as it turns out, we don&#8217;t have to imagine. Python did just that. Python 3 was first released nearly 5 years ago. And today, in 2014, it still sees trivial adoption rates. Not because it isn&#8217;t good, but because it&#8217;s not easy to maintain a single codebase that works on both versions. Which means that you either use 2, or you use a subset of 2 that works in 3 (gaining the full benefit of neither). And if the libraries or platforms you need to use don&#8217;t exist for 3, you&#8217;re left to port it yourself (basically you are SOL). And in <span id=\"lk13440h9h_3\" class=\"lk13440h9h\">practice<\/span>, that&#8217;s exactly what happened.<\/div>\n<div style=\"text-align: justify;\">I don&#8217;t want to say that it&#8217;s a mistake to do that. There are a TON of benefits to the language to make those kinds of changes. But to the community and the average user, it&#8217;s a show stopper IMHO.<\/div>\n<h2>On An Engine Rewrite<\/h2>\n<div style=\"text-align: justify;\">There have been people talking about rewriting PHP&#8217;s engine to clean a lot of things up. While I can definitely see the benefits in it (the engine is a pretty hairy codebase), I have to question why it is needed. After all, what about todays <span id=\"lk13440h9h_5\" class=\"lk13440h9h\">architecture<\/span> is fundamentally flawed? There are definitely architectural flaws in there, but for the most part it works pretty well.<\/div>\n<div style=\"text-align: justify;\">So, I would much rather see a component based refactor occur. Compartmentalize the engine into a series of subsystems. Today, that&#8217;s actually partly done. But I&#8217;d rather see it refactored to be <em>practically<\/em> pluggable. Why is that important? Well, once the engine is compartmentalized, then specific refactors can occur to actually make significant changes to the engine.<\/div>\n<div style=\"text-align: justify;\">For example, one of the messiest parts of PHP today is in the parser and compiler. Right now, they are so tightly coupled and messy that it causes a ton of issues with development. Instead, if they were compartmentalized, the parser could be swapped out, and the compiler could be swapped out. The common part in the middle would be an AST (Abstract Syntax Tree). Why an AST? Well, because it&#8217;s a common representation that both sides can use. Don&#8217;t get me wrong, this would be a very significant amount of work, but would have HUGE benefits. For everything from better, consistent and more predictable syntax to adding the ability to define new syntax via PHP code (imagine being able to define DSLs in PHP that are actually first-class parts of the language).<\/div>\n<div style=\"text-align: justify;\">So no, a total rewrite isn&#8217;t needed. A refactor is. A cleanup is.<\/div>\n<h2>On Objectifying The Standard Library<\/h2>\n<div style=\"text-align: justify;\">Some people have suggested that the core standard <span id=\"lk13440h9h_6\" class=\"lk13440h9h\">library<\/span> should be refactored to promote scalars into behaving like objects. So that you can do things like this:<\/div>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">$string <\/span><span class=\"pun\">=<\/span><span class=\"str\">\"Foo\"<\/span><span class=\"pun\">;<\/span><span class=\"pln\">\r\nvar_dump<\/span><span class=\"pun\">(<\/span><span class=\"pln\">$string<\/span><span class=\"pun\">-&gt;<\/span><span class=\"pln\">length<\/span><span class=\"pun\">);<\/span><span class=\"com\">\/\/ 3<\/span><span class=\"pln\">\r\nvar_dump<\/span><span class=\"pun\">(<\/span><span class=\"pln\">$string<\/span><span class=\"pun\">-&gt;<\/span><span class=\"pln\">toLower<\/span><span class=\"pun\">());<\/span><span class=\"com\">\/\/ string(3) \"foo\"<\/span><span class=\"com\">\/\/ etc<\/span><\/pre>\n<div style=\"text-align: justify;\">While I admit this sounds like a cool idea, I don&#8217;t think it should happen.<\/div>\n<div style=\"text-align: justify;\">The reason is simple, scalars are not objects, but more importantly they are not any type. PHP relies on a type-system that truly believes that strings <strong>are<\/strong> integers. A lot of the flexibility to the system is based that any scalar can be converted to any other scalar with ease. Now, this isn&#8217;t necessarily a good thing, in fact a large number of bugs occur because of this. It&#8217;s a leaky abstraction.<\/div>\n<div style=\"text-align: justify;\">But those types of edge-cases could be cleaned up. For example, you could raise a notice or warning or other catchable error\/exception on a &#8220;lossy&#8221; cast from one type to another (so if you try to cast <i>&#8220;123abc&#8221;<\/i> into a int, you&#8217;d get told there was data loss).<\/div>\n<div style=\"text-align: justify;\">More importantly though, due to this loose type system, you can&#8217;t 100% of the time know what type a variable will be. You can tell how you want to treat it, but you can&#8217;t tell what it is <span id=\"lk13440h9h_10\" class=\"lk13440h9h\">under the hood<\/span>. Even with casting or scalar type hinting it isn&#8217;t a perfect situation since there are cases where types can still <span id=\"lk13440h9h_9\" class=\"lk13440h9h\">change<\/span>.<\/div>\n<div style=\"text-align: justify;\">So that means that all scalar operations would need to be bound to all scalar types. Which leads to an object model where scalars have all of the math methods, as well as all of the string methods. What a nightmare&#8230;<\/div>\n<h2>The Rise of HHVM<\/h2>\n<div style=\"text-align: justify;\">Right now, today, as I write this, I don&#8217;t recommend moving production systems to HHVM. There are a few reasons for it. And none of them is a fundamental reason. All of them are known. Time will tell if they get resolved, but I have high hopes.<\/div>\n<ol>\n<li>\n<div style=\"text-align: justify;\">HHVM is controlled by a single company. Don&#8217;t get me wrong, it&#8217;s not that Facebook is spending a <span id=\"lk13440h9h_11\" class=\"lk13440h9h\">lot of money<\/span> on development that&#8217;s the problem. It&#8217;s that the project is controlled by a company who&#8217;s business has no bearing or impact by your use of HHVM. It would be one thing if they sold support contracts and made it into a legitimate product, but as it stands it&#8217;s neither an <span id=\"lk13440h9h_2\" class=\"lk13440h9h\">open<\/span> source project, nor a commercial one. It&#8217;s a weird conglomerate. And I would be VERY wary to bind a production stack to that sort of a situation.<\/div>\n<\/li>\n<li>\n<div style=\"text-align: justify;\">HHVM has no public spec. That means that your code is basically the same as code written to run on the Zend engine. It&#8217;s a trial and error case. And that&#8217;s &#8220;ok&#8221; for a single implementation, but murder to try to support 2 or more implementations. As a library maintainer I have personally felt this pain, and will continue to. However, if HHVM and PHP were to agree on a common specification, then things would get a TON easier&#8230;<\/div>\n<\/li>\n<li>\n<div style=\"text-align: justify;\">HHVM is not run as an open source project. It does accept contributed code. That&#8217;s awesome. But a pull-request\/patch queue doesn&#8217;t make an open source project. Where&#8217;s the clarity of process? Where&#8217;s the clarity of vision? Where&#8217;s the open tooling? Where&#8217;s the leadership?<\/div>\n<\/li>\n<\/ol>\n<div style=\"text-align: justify;\">I know I&#8217;m not alone in these beliefs. HHVM <strong>will<\/strong> be a strong contender in the future. But IMHO, until the above issues are sorted out, it&#8217;s not ready for prime-time in a commercial production setting.<\/div>\n<h2>Can Both PHP And HHVM Live Side-By-Side?<\/h2>\n<div style=\"text-align: justify;\">Absolutely. Despite what some benchmarks woud like you to believe, JIT compilers aren&#8217;t magic. They come with real world tradeoffs. Many benchmarks show this specifically. In fact, if you look closely at the vast majority of the benchmarks, you&#8217;ll notice that they aren&#8217;t running real world code. Oh, you&#8217;re comparing the performance of HelloWorld or a Fibonacci generator??? Good for you. Now please quiet down and throw away your meaningless results.<\/div>\n<div style=\"text-align: justify;\">Let me say that again, benchmarks that don&#8217;t test real world systems are meaningless. They are just noise. They are worse than useless, they are downright dangerous.<\/div>\n<div style=\"text-align: justify;\">In practice, there are going to be use cases where HHVM will give a signifiant boost of speed. But there are also going to be cases where PHP <em>will<\/em> be faster. The only way for you to know is to test <strong>your application<\/strong>&#8230;<\/div>\n<h3>But HHVM Runs My Code As Native! How Could PHP Be Faster<\/h3>\n<div style=\"text-align: justify;\">Remember how I said JIT isn&#8217;t magic? Well, that&#8217;s true. You can&#8217;t compile PHP natively directly, because it&#8217;s a dynamic language. Which means that you can&#8217;t know enough about what code is going to do to compile it to native code until right before you execute it. So a JIT does just that. It analyzes the code being executed, and when it learns enough about it, it generates native code. There&#8217;s overhead to this process, which is why HHVM is slow on the command line.<\/div>\n<div style=\"text-align: justify;\">But more importantly, it doesn&#8217;t generate universal code. It generates code that&#8217;s specific to the conditions that existed when it was created. So if your function adds 2 integers, it may compile to a simple add instruction. But it will also add guard instructions to confirm that the parameters were integers. If you then pass a non-integer (which is perfectly valid PHP), one of the guards will fail.<\/div>\n<div style=\"text-align: justify;\">When the guard fails, something called a bailout happens. This basically means that the engine will &#8220;undo&#8221; everything that was done for the current method (effectively running it in reverse), and switch to the interpreted mode. That&#8217;s far more expensive than just running the interpreted mode in the first place.<\/div>\n<div style=\"text-align: justify;\">And that&#8217;s just one way JIT compilers aren&#8217;t &#8220;magic&#8221;.<\/div>\n<div style=\"text-align: justify;\">I don&#8217;t want this to sound like I&#8217;m against JIT style compilers. Indeed, for the majority of code they will result in huge efficiencies. But they aren&#8217;t perfect.<\/div>\n<div style=\"text-align: justify;\">And if you look at other communities, you&#8217;ll see VM implementations right along side JIT compiler implementations. CPython and PyPy are two great examples. (It&#8217;s also worth noting that python has a language spec, so you can easily move between competing implementations).<\/div>\n<h3>But HACK Is Awesome!<\/h3>\n<div style=\"text-align: justify;\">Hack is a new language that Facebook developed and included in HHVM. It is basically a statically typed version of PHP, with some AWESOME features built in&#8230;<\/div>\n<div style=\"text-align: justify;\">And Hack is incredible! I am really looking forward to my prior reservations about HHVM to be resolved so I can invest in it!<\/div>\n<div style=\"text-align: justify;\">And that leads to an interesting idea. Right now, there are several <span id=\"lk13440h9h_8\" class=\"lk13440h9h\">meta<\/span> languages spinning up around PHP. Hack and Zephir being the two main ones. But there&#8217;s a problem. Both are specific to a runtime (Hack only works on HHVM, and Zephir only works on PHP). How to solve that issue?<\/div>\n<div style=\"text-align: justify;\">Well, I would solve it by throwing away Zephir, and building a Hack-&gt;PECL compiler for Hack. Since Hack is statically typed, it should be possible to cross-compile between Hack and PECL. And considering that Hack already supports C++ bindings for binding to system libraries, the compiler could theoretically handle that as well. So then there&#8217;d be no reason to write a PECL extension again. You&#8217;d build your extension in Hack, where you have static code analyzers and debuggers, get it to run, and then generate a 100% compatible PECL extension from it. It&#8217;s not a trivial thing to build, but I&#8217;d love to see it! (Again, another reason for a language spec).<\/div>\n<h2>On A Language Specification<\/h2>\n<div style=\"text-align: justify;\">So you may have noticed that I&#8217;ve mentioned a few times already in this post about the need for a language specification&#8230;<\/div>\n<div style=\"text-align: justify;\">As a minor hint, I think that&#8217;s the single most important thing that could happen to improve the future of PHP as a language, platform, ecosystem and community.<\/div>\n<h2>Wrapping Up<\/h2>\n<p>It&#8217;s a very exciting time for PHP. There&#8217;s a ton of awesome things happening, and a ton of cool progress being made. If we want to keep it going, I think we just need to be smart about the choices we make&#8230;<\/p>\n<p>http:\/\/blog.ircmaxell.com\/2014\/03\/an-opinion-on-future-of-php.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s been a lot of buzz in the community lately around PHP and its future. The vast majority of this buzz has been distinctly positive, which is awesome to hear. There&#8217;s been a lot of talk about PHP6 and what that might look like. There&#8217;s been a lot of questions around HHVM and its role [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2543,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[45],"tags":[52],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.0.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>An Opinion On The Future Of PHP | PHP training in Chennai<\/title>\n<meta name=\"description\" content=\"A lot of buzz in the\u00a0community\u00a0lately around PHP training in chennai.The vast majority of this buzz has been distinctly positive,and awesome to hear.\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Opinion On The Future Of PHP | PHP training in Chennai\" \/>\n<meta property=\"og:description\" content=\"A lot of buzz in the\u00a0community\u00a0lately around PHP training in chennai.The vast majority of this buzz has been distinctly positive,and awesome to hear.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\" \/>\n<meta property=\"og:site_name\" content=\"TCDC\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vytcdc\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-05T05:02:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-20T06:52:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2014\/07\/Future-Of-PHP.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"550\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vytcdc\" \/>\n<meta name=\"twitter:site\" content=\"@vytcdc\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"10 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#website\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"name\":\"TCDC\",\"description\":\"Career Development Courses\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/cns72.com\/vytcdc.com.sg\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2014\/07\/Future-Of-PHP.jpg\",\"width\":550,\"height\":350},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/#webpage\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\",\"name\":\"An Opinion On The Future Of PHP | PHP training in Chennai\",\"isPartOf\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/#primaryimage\"},\"datePublished\":\"2014-07-05T05:02:46+00:00\",\"dateModified\":\"2019-11-20T06:52:36+00:00\",\"author\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#\/schema\/person\/221376484ed2b7efe8b1a0d8b8289907\"},\"description\":\"A lot of buzz in the\\u00a0community\\u00a0lately around PHP training in chennai.The vast majority of this buzz has been distinctly positive,and awesome to hear.\",\"breadcrumb\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/an-opinion-on-the-future-of-php\/\",\"name\":\"An Opinion On The Future Of PHP\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#\/schema\/person\/221376484ed2b7efe8b1a0d8b8289907\",\"name\":\"Bhuvana\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/016aaa3e179e649976a14947431574c4?s=96&d=mm&r=g\",\"caption\":\"Bhuvana\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts\/813"}],"collection":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/comments?post=813"}],"version-history":[{"count":0,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts\/813\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/media\/2543"}],"wp:attachment":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/media?parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/categories?post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/tags?post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}