OOPS

class can declared final to indicate that it cannot be extended; that is, one cannot declare subclasses of a final class.
A final class cannot be extended.
Final method can not be override by the child class.
Class variables cannot be declare as final.
Syntax:

 final class Building{ }
 final public function set_color(){}

We can easily access constants, static variables, public functions and final functions from final classes using scope resolution operator.

Why do I have to use final?

Preventing massive inheritance chain of doom
Encouraging composition
Force the developer to think about user public API
Force the developer to shrink an object’s public API
A final class can always be made extensible
extends breaks encapsulation
You don’t need that flexibility
You are free to change the code
When to avoid final:

Final classes only work effectively under following assumptions:

There is an abstraction (interface) that the final class implements
All of the public API of the final class is part of that interface

PHP

Just as architects designing houses and buildings can develop templates for where a bathroom should be located or how a kitchen should be configured. Having those templates, or design patterns, means they can design better buildings more quickly. The same applies to software.

There are numerous ways to structure the code and project for your web application, and you can put as much or as little thought as you like into architecting. But it is usually a good idea to follow common patterns because it will make your code easier to manage and easier for others to understand.

Factory

One of the most commonly used design patterns is the factory pattern. In this pattern, a class simply creates the object you want to use.

Example

 $this->vehicleModel = $model;
 }
public function getMakeAndModel()
 {
 return $this->vehicleMake . ' ' . $this->vehicleModel;
 }
 }
class AutomobileFactory
 {
 public static function create($make, $model)
 {
 return new Automobile($make, $model);
 }
 }
// have the factory create the Automobile object
 $veyron = AutomobileFactory::create('a', 'b');
print_r($veyron->getMakeAndModel()); // outputs "a b"

This code uses a factory to create the Automobile object. There are two possible benefits to building your code this way; the first is that if you need to change, rename, or replace the Automobile class later on you can do so and you will only have to modify the code in the factory, instead of every place in your project that uses the Automobile class. The second possible benefit is that if creating the object is a complicated job you can do all of the work in the factory, instead of repeating it every time you want to create a new instance.

The example code used here is so simple that a factory would simply be adding unneeded complexity. However if you are making a fairly large or complex project you may save yourself a lot of trouble down the road by using factories.

Singleton

When designing web applications, it often makes sense conceptually and architecturally to allow access to one and only one instance of a particular class.

The singleton pattern is useful when we need to make sure we only have a single instance of a class for the entire request life cycle in a web application. This typically occurs when we have global objects (such as a Configuration class) or a shared resource (such as an event queue).

Front Controller

The front controller pattern is where you have a single entrance point for your web application (e.g. index.php) that handles all of the requests. This code is responsible for loading all of the dependencies, processing the request and sending the response to the browser. The front controller pattern can be beneficial because it encourages modular code and gives you a central place to hook in code that should be run for every request

Model-View-Controller

The model-view-controller (MVC) pattern and its relatives HMVC and MVVM lets you break up code into logical objects that serve very specific purposes. Models serve as a data access layer where data is fetched and returned in formats usable throughout your application. Controllers handle the request, process the data returned from models and load views to send in the response. And views are display templates (markup, xml, etc) that are sent in the response to the web browser.

MVC is the most common architectural pattern used in the popular PHP frameworks.

  • Yii
  • Zend Framework
  • Symfony
  • CodeIgniter etc.
  • sort() – sort arrays in ascending order
  • rsort() – sort arrays in descending order
  • asort() – sort associative arrays in ascending order, according to the value
  • ksort() – sort associative arrays in ascending order, according to the key
  • arsort() – sort associative arrays in descending order, according to the value
  • krsort() – sort associative arrays in descending order, according to the key
The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters  while print can take one argument. echo is marginally faster than print.

The echo statement can be used with or without parentheses: echo or echo().

Ex :

echo “Hello world!
“;

The print statement can be used with or without parentheses: print or print().

Ex :

print “Hello world!
“;

A constant is an identifier  for a simple value. The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

Constants are automatically global across the entire script.

Create a PHP Constant

To create a constant, use the define() function.

Syntax

define(name, value, case-insensitive)

Parameters:

  • name: Specifies the name of the constant
  • value: Specifies the value of the constant
  • case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false

Ex : define(“KEY”, “xYzAbC878KKllksPrashWalke28SandyWal12”);

Several predefined variables in PHP are “superglobals”, which means that they are always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.

The PHP superglobal variables are:

  • $GLOBALS : Access global variables from anywhere in the PHP script.PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
  • $_SERVER : Holds information about headers, paths, and script locations.
  • $_REQUEST : Used to collect data after submitting an HTML form.
  • $_POST : Used to collect form data after submitting an HTML form with method=”post”. $_POST is also widely used to pass variables.
  • $_GET : Used to collect form data after submitting an HTML form with method=”get”.$_GET can also collect data sent in the URL.
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3, …)). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.

Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.

GET

$_GET is an array of variables passed to the current script via the URL parameters.

Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL).

GET also has limits on the amount of information to send. The limitation is about 2000 characters.

Variables are displayed in the URL, it is possible to bookmark the page.

Use GET when –

GET may be used for sending non-sensitive data.

GET should NEVER be used for sending passwords or other sensitive information!

POST

$_POST is an array of variables passed to the current script via the HTTP POST method.

Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request)

Has no limits on the amount of information to send.

POST supports advanced functionality such as support for multi-part binary input while uploading files to server.

Variables are not displayed in the URL, it is not possible to bookmark the page.

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Create Cookies With PHP

A cookie is created with the setcookie() function.

Syntax

setcookie(name, value, expire, path, domain, secure, httponly);

Only the name parameter is required. All other parameters are optional.

When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn’t maintain state.

Session variables solve this problem by storing user information to be used across multiple pages (e.g. username,  etc). By default, session variables last until the user closes the browser.

So; Session variables hold information about one single user, and are available to all pages in one application.

A session is started with the session_start() function.

Session variables are set with the PHP global variable: $_SESSION.

A persistent cookie is permanently stored in a cookie file on the browser’s computer. By
default, cookies are temporary and are erased if we close the browser.

PHP Programming 

Bubble sort : Simplest Sorting Algorithm

It compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

function bubbleSort($array)
{
 if (!$length = count($array)) {
  return $array;
 }      
 for ($i = 0; $i < $length; $i++) {
  for ($j = 0; $j < $length; $j++) {
   if ($array[$i] < $array[$j]) {
    $tmp = $array[$i];
    $array[$i] = $array[$j];
    $array[$j] = $tmp;
   }
  }
 }
return $array;
}
This algorithm works by running through the array and swapping a value for the next value along if that value is less than the current value. After the first run through the highest value in the array will be at the correct end. It therefore must run through the array once for every item in the array, so it has a low efficiency.

MySql

Following tables (Storage Engine) we can create :
1. MyISAM(The default storage engine IN MYSQL Each MyISAM table is stored on disk
in three files. The files have names that begin with the table name and have an

extension to indicate the file type. An .frm file stores the table format. The data file has
an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. )
2. InnoDB(InnoDB is a transaction-safe (ACID compliant) storage engine for MySQL
that has commit, rollback, and crash-recovery capabilities to protect user data.)
3. Merge
4. Heap (MEMORY)(The MEMORY storage engine creates tables with contents that are
stored in memory. Formerly, these were known as HEAP tables. MEMORY is the
preferred term, although HEAP remains supported for backward compatibility. )
5. BDB (BerkeleyDB)(Sleepycat Software has provided MySQL with the Berkeley DB
transactional storage engine. This storage engine typically is called BDB for short. BDB
tables may have a greater chance of surviving crashes and are also capable of
COMMIT and ROLLBACK operations on transactions)
6. EXAMPLE
7. FEDERATED (It is a storage engine that accesses data in tables of remote
databases rather than in local tables. )
8. ARCHIVE (The ARCHIVE storage engine is used for storing large amounts of data
without indexes in a very small footprint. )
9. CSV (The CSV storage engine stores data in text files using comma-separated
values format.)
10. BLACKHOLE (The BLACKHOLE storage engine acts as a “black hole” that accepts
data but throws it away and does not store it. Retrievals always return an empty result)

CSS /HTML/ Bootstrap

Margin is applied to the outside​ of you element hence effecting how far your
element is away from other elements.
Padding is applied to the inside​ of your element hence effecting how far your
element’s content is away from the border.
HTML5 introduces the session Storage attribute which would be used by the sites to
add data to the session storage, and it will be accessible to any page from the same
site opened in that window i.e. session and as soon as you close the window, session
would be lost.
HTML5 introduces the local Storage attribute which would be used to access a page’s
local storage area without no time limit and this local storage will be available
whenever you would use that page.

jQuery / Javascript

Server Setting

Other