GitHub PullRequestReviewCommentEvent at 2014-05-09 14:58:15
Repository: namshi.github.com
Actor: odino
Payload: {"comment":{"url":"https://api.github.com/repos/namshi/namshi.github.com/pulls/comments/12479441","id":12479441,"diff_hunk":"@@ -0,0 +1,109 @@\n+---\n+author: Geshan Manandhar\n+layout: post\n+title: \"3 PHP 5.5 features we are using at Namshi\"\n+date: 2014-05-07 09:03\n+comments: true\n+categories:\n+- php\n+\n+---\n+\n+Here at  [Namehi](http://www.namshi.com) we are constanty updating our software stack to exploit the best benefits latest technology has to offer. Keeping up tp date with the latest stable version of PHP, we are using [PHP 5.5](http://php.net/releases/5_5_0.php) for some time now. We also leverage the new features added in PHP 5.5, this post will shed light on some of the features that have come handy in our development process.\n+\n+PHP [5.4](https://php.net/manual/en/migration54.new-features.php) and PHP [5.5](https://php.net/manual/en/migration55.new-features.php) both were featured packed PHP releases, we have found 3 of these features useful in our routine PHP development which are discussed below:\n+\n+<!-- more -->\n+\n+### array_column function\n+\n+The short array syntax was introduced in PHP 5.4, which makes creating arrays simpler than the old syntax.\n+\n+```php\n+$productIds = [1001, 1005, 1007];\n+\n+//array with keys and values\n+$products = [\n+    [\"title\" => \"Vito Solo Shirt\", \"sku\" => \"VI714AT94SIB\", \"price\" => 180.00],\n+    [\"title\" => \"Core Ultra Shirt\", \"sku\" => \"JA872AT40VYL\" , \"price\" => 195.00],\n+    [\"title\" => \"Swoosh T-shirt\", \"sku\" => \"NI727AT17RGG\" , \"price\" => 130.00]\n+];\n+\n+```\n+For arrays like in above example or if you have result set from a database query [array_column](http://www.php.net/manual/en/function.array-column.php) PHP function comes in very handy to extrct out the needed data as shown below:\n+\n+```php\n+$productTitles = array_column($products, \"title\");\n+\n+//product titles will be a new array of titles extacted from products array in above example code\n+Array\n+(\n+    [0] => Vito Solo Shirt\n+    [1] => Core Ultra Shirt\n+    [2] => Swoosh T-shirt\n+)\n+\n+//if you want to create a key value array where key is the sku and value is the price, it can be done by following call\n+\n+$productPrices = array_column($products, \"price\", \"sku\");\n+\n+Array\n+(\n+    [VI714AT94SIB] => 180\n+    [JA872AT40VYL] => 195\n+    [NI727AT17RGG] => 130\n+)\n+\n+```\n+The PHP `array_colum` function is an easy yet effective way to extact out needed informaton from an array which will make working with PHP arrays pleasant than usual. \n+\n+### finally\n+\n+Finally the `finally` keyword has been added to PHP, as mentioned in the [exceptions](http://www.php.net/manual/en/language.exceptions.php) documentation in the PHP website: \n+>Code within the finally block will always be executed after the try and catch blocks, regardless of whether an exception has been thrown, and before normal execution resumes.\n+\n+This makes a very good usecase when some code needs to be executed if the exception occurred and `return` has to be called. A typical example is closing the database connection:\n+\n+```php\n+try {\n+     //open sql connection \n+     if ($condition) { \n+        return false;\n+     }\n+  }\n+  finally {\n+    //close the sql connection, this will be executed even if the return is called.","path":"source/_posts/2014-05-07-3-php-5-dot-5-features-we-are-using-at-namshi.markdown","position":75,"original_position":75,"commit_id":"81799e831954b287ae2ea391753b707256f7975e","original_commit_id":"81799e831954b287ae2ea391753b707256f7975e","user":{"login":"odino","id":328420,"avatar_url":"https://avatars.githubusercontent.com/u/328420?","gravatar_id":"7e1b44a243d0cd4a01e5de1fa41fc0ed","url":"https://api.github.com/users/odino","html_url":"https://github.com/odino","followers_url":"https://api.github.com/users/odino/followers","following_url":"https://api.github.com/users/odino/following{/other_user}","gists_url":"https://api.github.com/users/odino/gists{/gist_id}","starred_url":"https://api.github.com/users/odino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odino/subscriptions","organizations_url":"https://api.github.com/users/odino/orgs","repos_url":"https://api.github.com/users/odino/repos","events_url":"https://api.github.com/users/odino/events{/privacy}","received_events_url":"https://api.github.com/users/odino/received_events","type":"User","site_admin":false},"body":"do we really use it @geshan ? :-D","created_at":"2014-05-09T14:58:15Z","updated_at":"2014-05-09T14:58:15Z","html_url":"https://github.com/namshi/namshi.github.com/pull/5#discussion_r12479441","pull_request_url":"https://api.github.com/repos/namshi/namshi.github.com/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/namshi/namshi.github.com/pulls/comments/12479441"},"html":{"href":"https://github.com/namshi/namshi.github.com/pull/5#discussion_r12479441"},"pull_request":{"href":"https://api.github.com/repos/namshi/namshi.github.com/pulls/5"}}}}