Posts Tagged with "php"

Detect an Ajax request in PHP

Posted by Stanislav Furman on August 24, 2017

If you would like to use same PHP code to handle both AJAX and non-AJAX requests, here is a quick and simple trick that you can use to check if the incoming request is AJAX. For our trick we will use a HTTP header called HTTP_X_REQUESTED_WITH. It is supported by all modern browsers that support AJAX. Therefore, it should work in 99% of cases.

Continue reading

Regular expressions? What's that? Part 2.

Posted by Stanislav Furman on June 2, 2014
A good example of how NOT to code.

PHP NG, significant speed-up features coming in PHP 6

Posted by Stanislav Furman on May 15, 2014
PHPNG : significant speedup changes announced in PHP 6 Release

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

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! :)


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

PHP 5.5.5 has been released

Posted by Stanislav Furman on October 17, 2013

Meet AMPPS - a good alternative for XAMPP and WAMP

Posted by Stanislav Furman on October 7, 2013

Meet AMPPS - a good alternative for XAMPP and WAMP  

For those who is looking for a good alternative for XAMMP or WAMP web server stacks. There is a very good option called AMPPS!

The listed number of provided features is impressive. Unlike the other solutions Ampps comes with over 300 PHP web applications, over 1000 PHP classes and libraries including Joomla!, WordPress, Magento, Dolphin and more. 

Very easy to install and manage services with the administration panel. You can easily switch PHP versions with only one-click action.

One thing to notice though... Despite the fact that there are several versions of PHP included, you cannot switch MySQL version which, to be honest, I don't find too critical.

Server configuration is also very straightforward using the web panel. If you mess up the configuration, you can reset it to default state which might be useful sometimes. :)

Also it is very easy to update! The app has built-in updater which makes life way easier when it comes to update Ampps.


Loose comparison in PHP. Example of breakable functionality.

Posted by Stanislav Furman on September 12, 2013
Example of breakable functionality using the loose comparison in PHP

Floating point comparisons or why prices need to be stored in cents

Posted by Stanislav Furman on September 5, 2013
Comparisons of floating point numbers and potential problem that may occur