Category: PHP
-
Is Zephir worth learning?
Not so short answer: If you want to learn something that makes you more marketable, then no. It is better to learn C++ instead. If you just want to play with it, maybe write an extension or two for your project, then Zephir is fun language to learn. I checked for jobs dice.com and other…
-
A second look at Zephir
Ever since I found out about Zephir, I have been very curious about it. I mean compiled PHP code. How awesome is that? Also, Zephir code doesn’t have to be compiled into a PHP extension. You can just convert it to binary and run it normally like any other PHP code. Why spend a lot…
-
Some very cool features in PHP7
I played around with PHP7 over the weekend and I have to admit it has some very cool things I have wanted PHP to have for a while, and then some. Here are some of them (in no particular order): Performance PHP7 will increase the performance of PHP scripts by 50-60%. Nuff said. Anonymous Classes…
-
PHPSpec: Mocking methods of the object being tested
PHPSpec is very opinionated and won’t let you mock anything of an object being tested. It helps you write better code. This, however, causes issues when you are writing specs for legacy code which (usually) was not well designed. There is a way you can get around this limitation – a child class. Let’s say…
-
You can make PHP extensions in a PHP like language
I recently came across an article which spoke about a language called Zephir. It was written with the goal of letting PHP programmers write PHP extensions. I was really happy to read this. For quite some time I have dreamed of creating PHP extensions but the fact that I would have to learn C kept…
-
Selenium Chrome driver nuances
When writing test, you generally tend to run the test in one browser and expect it to work on all the rest (except maybe Internet Explorer). I had ran my tests on Firefox and they succeeded but not on Chrome. In Firefox, if you click on an element that is not currently visible on the…
-
Testing multiple browsers with Selenium2 in PHPUnit
You used to be able to run test on multiple browsers with PHPUnit Selenium test class by specifying a $browsers property. You can still do the same with PHPUnit’s Selenium 2 class made for web driver. Here is how you do it: class SomeTest extends PHPUnit_Extensions_Selenium2TestCase { /** * Variable to specify which browsers to…
-
Fastest way to traverse an associative array
PHP has array_walk() which can be used to traverse an array and modify it in place. I wanted to find out if array_walk() would be faster than a loop written in PHP (for, foreach). I mean, PHP’s code is written in C/C++ and traversing anything has to be faster in C than in PHP. So,…
-
Convert an array to XML in PHP
I haven’t benchmarked the memory consumption of this method versus just traversing the array yourself and writing XML but I can’t see anything else being more efficient than this. $testArray = [ ‘key1’ => ‘val1’, ‘key2’ => [ ‘key3’ => ‘hello’ ] ]; $xml = new SimpleXMLElement(‘<root/>’); array_walk_recursive($testArray, array ($xml, ‘addChild’)); print $xml->asXML();
-
Code Assist in Zend Studio (eclipse based)
Have you noticed there is a delay autocomplete suggestions when you type in a variable name or a function name? My typing speed is decent and I found the code assist delay to be too much. By the time Zend Studio was ready to show me the suggestions, I had already typed the variable name.…