PHP Chapter 3
PHP Chapter 3
Concepts in PHP
Unit - III
Syntax:
class class_name
{
//properties;
//methods( );
}
Syntax:
function get_name() {
return $this->name; }}
$stud = new student("Zaid");
echo $stud->get_name();
?>
</body></html> Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
7
MHSSP
3.2 Constructor & Destructor
• Destructor:
• The child class will inherit all the public and protected properties and
methods of parent class.
• Abstract classes and methods are when the parent class has a named method,
but need its child class(es) to fill out the tasks.
• To call a static property from a child class, use the parent keyword inside child
class. parent::static_ property _name);
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
18
MHSSP
3.3 Method Overloading
• In PHP, we can perform method overloading with the help of magic
function _call().
$a=new A();
$b=new B();
$a->show();
$b->show();
?> Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
22
MHSSP
3.3 Final Keyword
• The final keyword is used only for methods and classes.
• If final keyword is used with class, then it prevents the class from
being inherited.
• In the process of shallow copying A, B will copy all of A’s field values.
• If the field value is a memory address it copies the memory address, and if the
value is a primitive type it copies the value of the primitive type.
• But in shallow copy, if you modify the content of B’s field you are also
modifying what A’s field contains.
• In this method, all the things in object A’s memory location get copied to
object B’s memory location.
• PHP offers large number of functions that one can use to accomplish
the task.
Syntax:
serialize(value);
Syntax:
unserialize(serialized_string);