Single Inheritance

In single inheritance, one class extends one class only

Example

<?php
class a
{
public function function_a(){
echo “class A”;
}
}

class b extends a
{
public function function_b(){
echo “class B”;
}
}

echo b::function_b();
echo b::function_a();

?>

Access Specifiers

It specify the level of access to the the data member or function in a class

Please note that all data members and member functions are public by default.

Private

A private access specifier is used to hide data and member functions. A method or data member declared as private can only be accessed by the class itself and neither the outside program nor the derived class can have access to it.

Public

A public access specifier allows the data members and methods to be access from anywhere in the script. Lets look at an example below:

protected

A protected access specifier allows the derived class to access the data member or member functions of the base class, whereas disallows global access to other objects and functions.
Example

<?php
class PHPCode{
private $a;
public $b;
public function __construct($a, $b) {
$this->b = $a;
$this->b = $b;
}
}

$obj = new PHPCode(7,17);
echo $obj->b;
?>
Here we can not access the variable a but b

The reason why data members are declared private is to avoid the outside programs to either accidentally modify the values without necessary validation.

When you define a method as private that method can only be called from within that class and not from outside that is the global level script.

Private data member or functions can not be accessed by the child class objects

Alternative PHP Cache

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. Besides a opcode cache it provides a user cache for storing application data. This module uses the APC user cache as a cache backend for Drupal.

Heredoc

Heredoc is a robust way to create string in PHP with more lines but without using quotations. Heredoc is rarely used as the day by day usage is more complicated as creating strings with quotes or double quotes. Besides this the not properly used heredoc can lead to problems in your code.

• Delimits strings without using quotes (so no need to escape)
• Start with <<< and an identifier; end with same identifier
• Do not indent ending identifier or add any chars

Example

<?php
 $str = <<<DEMO
 phpcode
 DEMO;
 print $str;
 ?>

Output

phpcode

Switch Statement

We can use the switch statement to select one of many blocks of code to be executed.

General Format

switch (val)
{
case label1:
code to be executed if n=label1;
break;
case label2:

 code to be executed if n=label2;

 break;
default:
code to be executed if n is different from both label1 and label2;
}

Example

<?php
$val=1;
switch($val){
case 1 : echo “Sunday”;break;
case 2 : echo “Monday”;break;
case 3 : echo “Tuesady”;break;
case 4 : echo “Wednesady”;break;
case 5 : echo “Thursday”;break;
case 6 : echo “Friday”;break;
case 7 : echo “Saturday”;break;
default : echo “Sunday”;break;

}
?>

Output

Sunday

operators

= Assignment
+ Addition
Subtraction
* Multiplication
/ Division
% Modulus
== Equal To
!= Not Equal To
< Less Than
> Greater Than
<= Less Than or Equal To
>= Greater Than or Equal To
+= Plus Equals
-= Minus Equals
*= Multiply Equals
/= Divide Equals
%= Modulo Equals
.= Concatenate Equals

mysql_connect() vs mysql_pconnect()

Difference between mysql_connect() and mysql_pconnect() PHP

mysql_pconnect() acts very much like mysql_connect() with two major differences.

When connecting using mysql_pconnect() , the function would first try to find a (persistent) link that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

When connecting using mysql_connect(), the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use

Note :mysql_close() will not close links established by mysql_pconnect().

Difference between mysql_connect() and mysql_pconnect() PHP

Difference between mysql_connect() and mysql_pconnect() PHP

mysql_pconnect() acts very much like mysql_connect() with two major differences.

When connecting using mysql_pconnect() , the function would first try to find a (persistent) link that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

When connecting using mysql_connect(), the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use

Note :mysql_close() will not close links established by mysql_pconnect().