{"id":502,"date":"2014-06-08T13:53:30","date_gmt":"2014-06-08T12:53:30","guid":{"rendered":"http:\/\/www.muratyaman.co.uk\/wp\/?p=502"},"modified":"2020-04-01T12:33:45","modified_gmt":"2020-04-01T11:33:45","slug":"composer-for-php-do-we-really-need-it","status":"publish","type":"post","link":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/2014\/06\/composer-for-php-do-we-really-need-it\/","title":{"rendered":"Composer for PHP: Do we really need it?"},"content":{"rendered":"<p>If you are wondering what we are dealing with in PHP world on a day to day basis, here is an example: just check <a href=\"http:\/\/getcomposer.org\">http:\/\/getcomposer.org<\/a> and autoload*.php files in it!! It&#8217;s supposed to be a solution!?<\/p>\n<p>First of all, PHP saved us huge pain by <a href=\"http:\/\/www.php.net\/\/manual\/en\/language.oop5.autoload.php\">autoloading classes<\/a>. It&#8217;s been brilliant! Now, it is a mess, especially when you want to use code from different projects! Therefore, Composer has its excuse; introduction says:<\/p>\n<blockquote><p>\nComposer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.\n<\/p><\/blockquote>\n<p>Example: download Laravel 4 and check the vendor directory, and the amount of code and variation around autoload!<\/p>\n<p>WHY?!<\/p>\n<p>Why can PHP not guide the PHP developers to write their code in certain ways (e.g. <a href=\"http:\/\/www.php-fig.org\/\">PSR<\/a>), and to package their code for others (<a href=\"http:\/\/www.php.net\/\/manual\/en\/book.phar.php\">PHAR<\/a>)? Even though PHP has library to create PHAR files, it does not make a tool to create a simple PHAR file by using a directory; it doesn&#8217;t have a proper example in documentation. PHP must promote PHAR if it really &#8211; admittingly &#8211; wants to be like Java (*yuck*).<\/p>\n<p>And PHP framework developers &#8211; yes, you! &#8211; you should also encourage others to write &#8220;application&#8221; code using namespaces without polluting the global namespace, which helps packaging of applications, too.<\/p>\n<blockquote><p>Maybe, then, it would be the start of the slow-down of a down-fall of a once-great scripting language for the web&#8230;<\/p><\/blockquote>\n<p>QUESTIONS\/SUGGESTIONS:<\/p>\n<p>1. Do we need to see all the rubbish that comes with other projects: documentation, demo files, tests, etc.?<\/p>\n<p>2. Can we just create a packages folder in the system that can be &#8220;included&#8221; in path setting for PHP? We can then save PHAR files in it. This resembles the previous attempt\/failure of PEAR.<\/p>\n<p>3. Do we even need to &#8220;include&#8221; or &#8220;require&#8221; files any more? As they are read once, they are cached by PHP, right? Maybe PHP can cache these PHAR files for us. Or, we can &#8220;include&#8221; them all once.<\/p>\n<p>4. Does this affect the performance when dealing with very small &#8220;hello world&#8221; requests?<\/p>\n<p>5. Do we need to keep different versions of a project? This could be a deal-breaker for global op-code cache on the system \ud83d\ude41 Then, we have to manually &#8220;include&#8221; the desired version of a project:<\/p>\n<p><code lang=\"php\"><br \/>\n\/\/include 'my-project-1.0.phar';<br \/>\ninclude 'my-project-2.0.phar';<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are wondering what we are dealing with in PHP world on a day to day basis, here is an example &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[26],"class_list":["post-502","post","type-post","status-publish","format-standard","hentry","category-technology","tag-php"],"_links":{"self":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=502"}],"version-history":[{"count":10,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/502\/revisions"}],"predecessor-version":[{"id":940,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/502\/revisions\/940"}],"wp:attachment":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}