0% found this document useful (0 votes)
8 views3 pages

PHP Object-Oriented Concepts Explained

Chapter 3 discusses object-oriented concepts in PHP, including introspection, serialization, sessions, cookies, constructors, destructors, and MySQLi. Introspection allows programs to examine their structure at runtime, while serialization converts an object's state for storage or transmission. It also covers the attributes of cookies, the purpose of session start, and types of inheritance, along with a sample HTML form for data submission.

Uploaded by

jayankeni2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

PHP Object-Oriented Concepts Explained

Chapter 3 discusses object-oriented concepts in PHP, including introspection, serialization, sessions, cookies, constructors, destructors, and MySQLi. Introspection allows programs to examine their structure at runtime, while serialization converts an object's state for storage or transmission. It also covers the attributes of cookies, the purpose of session start, and types of inheritance, along with a sample HTML form for data submission.

Uploaded by

jayankeni2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 3

Apply Object Oriented Concepts in PHP


Define introspection
2. Define serialization and explain it with example
1. Introspection
- Introspection is the ability of a program to examine its own structure and state at runtime.
- In PHP, introspection is achieved using functions like get_class(), get_object_vars(), method_exists(),
etc.

2. Serialization
- Serialization is the process of converting an object's state into a format that can be stored or
transmitted.
- In PHP, serialization is achieved using the serialize() function.

Enlist the attributes of cookies.


Attributes of Cookies are as follows:
1. name
2. value
3. expire
4. path
5. domain
6. secure

Define session and cookie. Explain use of session start


Session
A session is like a temporary memory for a website. It helps the website remember things about you,
like your username or what's in your shopping cart.

Cookie
A cookie is like a small note that a website leaves on your computer. It helps the website remember
things about you, like your preferences or what you did last time you visited.

Session Start
Session start is like waking up the website's memory. It helps the website remember things about you,
so you don't have to start over every time you visit.
Explain the concept of constructor and destructor in detail.

Constructor
A constructor is a special method in a class that is automatically called when an object of that class is
created. Its main purpose is to:

1. Initialize the object's properties


2. Set default values
3. Allocate resources

In PHP, a constructor is defined using the __construct() method.

Destructor
A destructor is a special method in a class that is automatically called when an object of that class is
destroyed. Its main purpose is to:

1. Release resources
2. Clean up memory
3. Perform final tasks

In PHP, a destructor is defined using the __destruct() method.

call() - MySQLi()
The __call() method in PHP is a special function that is used when trying to call a method that
does not exist in a class. It helps in method overloading.

2. MySQLi in PHP
MySQLi (MySQL Improved) is an extension in PHP used to interact with MySQL databases. It
provides better security and performance compared to the old mysql extension.

__call() is used for method overloading when calling undefined functions.


MySQLi is used to connect and interact with MySQL databases in PH

Types of Inheritance:
Single Inheritance
Multilevel Inheritance
Multiple Inheritance
Hierarchical Inheritance
<!DOCTYPE html>
<html>
<body>
<form action = 'data..php' method = 'post'>
<input type = 'text' name = 'name' placeholder = 'Customer
Name...'><br><br>
<input type = 'text' name = 'address' placeholder =
'Address...'><br><br>
<input type = 'text' name = 'number' placeholder = 'Mobile
Number...'><br><br>
<label> Date of Birth: </label>
<input type = 'date' name = 'dob'><br><br>
<input type = 'submit' value = 'Submit'><br>
</form>
</body>
</html>
[Link]
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<html><body><form>
Customer Name: '.$_POST['name'].'<br>
Address: '.$_POST['address'].'<br>
Mobile Number: '.$_POST['number'].'<br>
Date of Birth: '.$_POST['dob'];
}
?>

You might also like