Static vs Non-static methods in PHP: what is faster?

Posted by Stanislav Furman on May 4, 2014

Static vs Non-static methods in PHP: what is faster?

Some theory

As you know there are two types of methods in PHP classes: static and non-static. To be called a non-static method needs an instance of its class, and static method can be called without instantiating of the class. 

In the meantime there are two very common questions:

  • When to use non-static methods and when to use static methods?
  • Is there any performance difference between static and non-static methods?

These are very common dilemmas among PHP developers. Most of developers guess that static methods must work faster because there is no object instance with all its properties involved to the call. Sounds logical. Is that actually true?

As I already mentioned above, and as you already know, the main difference between static and non-static metods is that static methods do not need an instance of the class to be called in the code. It means that for static methods there is no need to create object and keep in the memory. So, at least we can save some memory which can also affect the performance? Hmmm... we'll see...

So, it's time to do some very simple experiments for further analysis.

Continue reading

Apple has iWatch already in production, report says

Posted by Stanislav Furman on April 30, 2014
Sources claim that Apple has already start production on iWatch

Regular expressions? What's that?

Posted by Stanislav Furman on April 29, 2014

Apparently, the person who wrote this code has never heard about regular expressions. :)

<?php
$find = str_replace(",", "", $find);
$find = str_replace(".", "", $find);
$find = str_replace("/", "", $find);
$find = str_replace(" ", "", $find);
$find = str_replace("-", "", $find);
$find = str_replace("+", "", $find);
$find = str_replace("#", "", $find);
?>

Please, never repeat this! :)


IE users risk having their computers hacked and taken over

Posted by Stanislav Furman on April 28, 2014
Microsoft has announced that Internet Explorer users are are all vulnerable to a glitch

Unix shell commands to detect a DDoS attack and its source

Posted by Stanislav Furman on April 25, 2014
5 Unix shell commands to check if your server is under DDoS attack and its source

This password is already in use. Old school security fail.

Posted by Stanislav Furman on April 23, 2014
Old school security fail.

RIP Nokia? Microsoft renames Nokia to Microsoft Mobile

Posted by Stanislav Furman on April 21, 2014
Bye-bye, Nokia! Hello, Microsoft Mobile! The end of Nokia?

What Is the Heartbleed Encryption Bug?

Posted by Stanislav Furman on April 11, 2014

Redis: How to delete keys matching a pattern

Posted by Stanislav Furman on April 10, 2014

Sometimes you might want to purge a set of similar Redis keys in one shot. So far, standard Redis "DEL" command does not allow to remove keys using patterns. However, there is a trick to do this action. Execute the following command in bash:


redis-cli -h [host] -p [port] KEYS "prefix:*" | xargs redis-cli DEL

Seems clear? Wait a minute! What if you use multiple databases (keyspaces) and need to remove keys from a database different from default (0) one? No problem there! Here is the solution:

Continue reading

Backward version compatibility in PHP web application

Posted by Stanislav Furman on February 17, 2014

If you develop a PHP web application which may be used on a web server with older PHP version, you can run into a situation when some of the PHP functions in your application won't work at all, or won't work as expected.

In fact, you can handle those situations if you want to. However, it can make you application code not as nice as you want and a little heavier.

Continue reading