Language Constructs

Language constructs are used and behave almost similar to built-in functions .
The real difference lies in how PHP engine interprets a language construct and a built-in function. language constructs are relatively faster over built-in functions since they are bound to the language.Language Constructs Don’t Need Parenthesis .Language constructs are faster than built in functions

Below given are the examples

echo
die
if
print
unset
isset
empty
include
require


Class

A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.

Use classes to encapsulate code and represent objects, and namespaces to avoid symbol name collisions

A. A class can not extend more than one class.

B. A class can not implement more than one class.

C. A class cannot extend more than one interface.

D. A class can implement more than one interface.

Example

<?php
 class a{
 function function_a(){
 echo "Function A";
 }
 }

a::function_a();
 ?>

Data encapsulation

Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.

Data encapsulation is a mechanism of bundling the data, and the functions that use

Implements

We use implements keyword to extend interface of class, at the same time we can implement more than one interface and one interface can be implemented by another interface.

All methods declared in an interface must be public and the variables should be constant.

This is mandatory that we must declare the body part of the method in the derived class otherwise an error message will be generated.

Example

<?php
interface a{
public function test();
}

class b implements a{
public function test(){
echo “Function Test”;
}
}

$b=new b();
$b->test();
?>

Hierarchical Inheritance

In hierarchical type of inheritance, one class is extended by many subclasses. It is one-to-many relationship

Example

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

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

class c extends a
{
public function function_c(){
echo “class c”;
}
}

echo c::function_c();
echo c::function_a();

?>

Multilevel Inheritance

In multilevel, one-to-one ladder increases. Multiple classes are involved in inheritance, but one class extends only one. The lowermost subclass can make use of all its super classes’ members. Multilevel inheritance is an indirect way of implementing multiple inheritance. Following program explains.

Example

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

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

class c extends b
{
public function function_c(){
echo “class c”;
}
}

echo c::function_c();
echo c::function_b();
echo c::function_a();

?>