Difference between equality(==) and identity(===) in PHP

Double equals(==) compares the values of variables for equality, type casting as necessary. Triple equals(===) checks if 2 variables are of the same TYPE and have the same value.
A full explanation of the differences are available in PHP Manual
1 === 1: true
1 == 1: true
1 === “1”: false //1 is an integer, “1” is a string
1 == “1”: true //“1” gets casted to an integer, which is 1
“foo” === “foo”: true //both operands are strings and have the same value
Note: two instances of the same class do NOT match the === operator
$a = new stdClass();
$a->foo = “bar”;
$b = clone $a;
var_dump($a === $b); //bool(false)

IE Conditional Comment

When develop a website, you should take care of anything that IE can throw at you without the use of hacks. Hacks are dangerous, since they are based on non-standard exploits and you can’t trust how they’re going to behave on the future browsers. Thus the solution for this problem is the conditional stylesheet or conditional comment. One important thing is that IE 10 and up don’t support conditional comment

Conditional comment operators

Operator Description
IE represents Internet Explorer; if a number value is also
specified, it represents a version vector
lt less than operator
lte less than or equal to
gt greater than
gte greater than or equal to
! the NOT operator
() subexpression operator
& the AND operator
| the OR operator
true evaluates to true
false evaluates to false


Target everything except IE

<!--[if !IE]>
  <link rel="stylesheet" type="text/css" href="not-ie.css" />

Target IE7 only

<!--[if IE 7]>
  <link rel="stylesheet" type="text/css" href="ie7.css" />

Target IE8 and lower

<!--[if lte IE 8]>
  <link rel="stylesheet" type="text/css" href="ie8.css" />

These conditional comments don’t have to be used only for CSS. You could load JavaScript, or even use them to display the specific content of your site.

Asynchronous And Synchronous Ajax Calls

In jQuery ajax call, there’s an option called async. Let’s look at below example:

    url: your_url,
    type: "POST",
    async: true,
    dataType: "json"

By default, all requests are sent asynchronously(this is set to true by default). If you need synchronous requests, set this option to false
Setting async to false means that the statement you are calling has to complete before the next statement in your function call be called. If you set async to true then that statement will execute and the next statement will be called regardless of whether the async statement has completed yet.
Note that cross-domain requests and dataType: "jsonp"requests do not support synchronous operation. Also as of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().
Try something like this

    url: target,
    contentType:'application/json; charset=utf-8',
    type: 'POST',
    dataType: 'json',
    async : false,
    success : function(){
    error: function(){

Double Slashes In A Url

Many developers was wondering about the following line

<script src="//someserver.com/js/script.js"></script>

What does the “double slashes” do or is this line of code correct?

It’s a relative URL without a scheme(http or https) according to RFC 3986: “Uniform Resource Identifier (URI): Generic Syntax”, Section 4.2. It’s useful when switching between http and https, because you won’t need to explicitly specify the scheme. It’s also supported in all web browsers.

More detailed, the two forward slashes are described as a common shorthand for whatever protocol being used

z-index Property

What is z-index

z-index is a css property that specifies the stack order of an element.  The stack order is based on the defined value. If an element has higher z-index, it’s in front of a lower z-index element. The default value is 0.
Note: z-index only works on positioned elements(absolute, relative, fixed)


tag {
    z-index: value;


Property Value Example Description
z-index auto z-index: auto; Sets the stack order equal to its parents. This is default
number z-index: 10; Sets the stack order of the element. Negative numbers are allowed
inherit z-index: inherit; nherits this property from its parent element

Browser Support

Most browser fully supports z-index property. IE7 doesn’t support the value “inherit”, IE8 requires !Doctype

Property compatible_ie compatible_firefox compatible_chrome compatible_safari compatible_opera
version 4.0 3.0 1.0 1.0 4.0


img {
    position: relative;
    left: 0px;
    bottom: 0px;
    z-index: 99;

PHP Composer

What is PHP Composer?

It’s a very good dependency management tool for PHP. It manages all the libraries that you have on your project.


The composer will pull all the required libraries, dependencies and keep track all of them just in individual project not globally. Furthermore, you might be aware of PEAR which is established as PHP package manager. However, it has been abandoned for several reasons. First of all, much of the code in PEAR is out of date. Secondly, PEAR forces you to install packages system wide rather than on a project-by-project.


Installing composer is quite easy. In this tutorial, I’ll use curl to install composer thus make sure you have curl installed or enabled in your system. If not, use the following to install

sudo apt-get install php5 git php5-curl

Now move to your project location and run this command:

curl -sS https://getcomposer.org/installer | php

You should see a success message like this:

All settings correct for using Composer
Composer successfully installed to: /var/www/my_project/composer.phar
Use it: php composer.phar


Now that you have composer installed. To use the composer, it requires composer.json file in which describes the dependencies of your project. For instance, our project depends on PEAR, Mail, Mail_Mime, Net_SMTP, Service_JSON. So let’s create the file:

    "require": {
        "pear-pear.php.net/PEAR": "1.9.4", 
        "pear-pear.php.net/Mail": "1.2.0",
        "pear-pear.php.net/Mail_Mime": "1.8.5",
        "pear-pear.php.net/Net_SMTP": "1.6.1",
        "pear-pear.php.net/Services_JSON": "1.0.3"

One question rising from here is that where you can find the package and the version for this file. Here is a good place for you to do that.
Ok now you can run a command to install those dependencies on your project:

php composer.phar install


Once you have all your dependencies installed. You need to autoload them into your project. In your PHP project, simply specify this in your index or bootstrap file:

require 'vendor/autoload.php';


Composer is now widely used by many PHP developers. So it’s better for you to start using it today.