Archive a git branch

If you would like to archive and delete a branch from your branch list:

/* Display list of branches */
git branch
/* archive (tag) the branch */
git tag archive/<branchname> <branchname>
/* delete the branch */
git branch -D <branchname>

If you need to restore this branch at a later stage:

git checkout -b <branchname> archive/<branchname>

The history of the branch will be preserved exactly as it was when you tagged it.


Some facts about PHP Array


In PHP the key of an array can either be an integer or a string. The value can be of any type.

Strings containing valid integers will be cast to the integer type. E.g. the key “8” will actually be stored under 8. On the other hand “08” will not be cast, as it isn’t a valid decimal integer.

Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.

Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.

Null will be cast to the empty string, i.e. the key null will actually be stored under “”.

Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.

If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.

Example: Type Casting and Overwriting example

$array = array(
    1    => "a",
    "1"  => "b",
    1.5  => "c",
    true => "d",

The above example will output:

array(1) {
  string(1) "d"

As all the keys in the above example are cast to 1, the value will be overwritten on every new element and the last assigned value “d” is the only one left over.

The key is optional. If it is not specified, PHP will use the increment of the largest previously used integer key. It is possible to specify the key only for some elements and leave it out for others:

Example: Keys not on all elements

$array = array(
    6 => "c",

The above example will output:

array(4) {
  string(1) "a"
  string(1) "b"
  string(1) "c"
  string(1) "d"

As you can see the last value “d” was assigned the key 7. This is because the largest integer key before that was 6.

AJAX with Core JavaScript

Using JavaScript libraries and frameworks sometimes make us forget how to implement AJAX call with pure JavaScript. That’s why I grabbed this from

var xhttp;
if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);

xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("demo").innerHTML = xhttp.responseText;
};"GET", "ajax_info.txt", true);

To POST data like an HTML form, add an HTTP header with setRequestHeader(). Specify the data you want to send in the send() method:"POST", "ajax_test.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");


Introduction to XML Soap

SOAP (Simple Object Access Protocol) is a XML based protocol that provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

A SOAP message is an ordinary XML document containing the following elements:

1. An Envelope element that identifies the XML document as a SOAP message
2. An optional Header element that contains header information
3. A Body element that contains call and response information
4. A Fault element containing errors and status information

For details go to

A SOAP Example

In the example below, a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter that will be returned in the response. The namespace for the function is defined in “;.

A SOAP request:

POST /InStock HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>


<soap:Body xmlns:m="">


The SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>


<soap:Body xmlns:m="">



A short introduction to RESTful application

RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, et al.)

With better cache support, lightweight requests and responses, and easier response parsing, REST allows for nimbler clients and servers, and reduces network traffic, too.


Comparing the three MySQL APIs in PHP


It is recommended to use either the mysqli or PDO_MySQLextensions. It is not recommended to use the old mysql extension for new development, as it was deprecated in PHP 5.5.0 and was removed in PHP 7. A detailed feature comparison matrix is provided below.

The overall performance of all three extensions is considered to be about the same. Although the performance of the extension contributes only a fraction of the total run time of a PHP web request. Often, the impact is as low as 0.1%.

Feature comparison

ext/mysqli PDO_MySQL ext/mysql
PHP version introduced 5.0 5.1 2.0
Included with PHP 5.x Yes Yes Yes
Included with PHP 7.x Yes Yes No
Development status Active Active Maintenance only in 5.x; removed in 7.x
Lifecycle Active Active Deprecated in 5.x; removed in 7.x
Recommended for new projects Yes Yes No
OOP Interface Yes Yes No
Procedural Interface Yes No Yes
API supports non-blocking, asynchronous queries with mysqlnd Yes No No
Persistent Connections Yes Yes Yes
API supports Charsets Yes Yes Yes
API supports server-side Prepared Statements Yes Yes No
API supports client-side Prepared Statements No Yes No
API supports Stored Procedures Yes Yes No
API supports Multiple Statements Yes Most No
API supports Transactions Yes Yes No
Transactions can be controlled with SQL Yes Yes Yes
Supports all MySQL 5.1+ functionality Yes Most No

Automatic underscore insertion in PHP


When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:

<input name="foo" src="image.gif" type="image" />

When the user clicks somewhere on the image, the accompanying form will be transmitted to the server with two additional variables: foo.x and foo.y.

Because foo.x and foo.y would make invalid variable names in PHP, they are automatically converted to foo_x and foo_y. The periods are replaced with underscores. So, you would access these variables like $_GET[‘foo_x’].

Note spaces in request variable names are also converted to underscores.