0% found this document useful (0 votes)
2 views

Declaring a class, creating an object

The document outlines a course on Web Technologies focusing on PHP, covering topics such as object-oriented programming, database connectivity, and security issues. It includes course outcomes, class and object definitions, and best practices for coding in PHP. Additionally, it provides book references for further reading on PHP and web development.

Uploaded by

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

Declaring a class, creating an object

The document outlines a course on Web Technologies focusing on PHP, covering topics such as object-oriented programming, database connectivity, and security issues. It includes course outcomes, class and object definitions, and best practices for coding in PHP. Additionally, it provides book references for further reading on PHP and web development.

Uploaded by

siyalohiya67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIVERSITY INSTITUTE OF COMPUTING

Bachelor of Computer Application


Subject Name: Web Technologies
22CAH-371/23SCH-254

Web Technologies DISCOVER . LEARN . EMPOWER


1
Web Technologies
• Web development
Course Outcome
CO Title Level
• History
Number • Static pages
CO1 Understand • Dynamic pages
Students will learn basics of PHP

CO2 Understand &


Students will understand the underlying concept of themes in Analyze
wordpress.

CO3 Understand
Students will learn database connectivity, plugin and security
issues.

2
Web Development
Using PHP
Course Outcome • OOP
CO Title Level
Number
• Session and Cookies
Understand
• File handling
CO1
Students will learn basics of PHP • Database
CO2 Understand &
Students will understand the underlying concept of themes in Analyze
wordpress.

CO3 Understand
Students will learn database connectivity, plugin and security
issues.

3
Topic to be Covered
• Declaring a class
• Creating an object

4
Introduction

• An object is a data type that can store data and functions together in
a single unit. Objects are created using the new keyword followed by
the class name. Once an object is created, you can access its
properties and methods using the arrow notation (->).
• A class can have properties, which are variables that store data, and
methods, which are functions that perform actions on the object.
Classes can also have constructors, which are special methods that
are called when an object is created, and destructors, which are
special methods that are called when the object is destroyed.

5
PHP: Creating classes and Instantiation

• A class is a template for objects, and an object is an instance of class.

• A class is defined by using the class keyword, followed by the name of the class
and a pair of curly braces ({}). All its properties and methods go inside the braces:

Syntax:-
<?php
class Class_name {

//properties and methods

}
?>
6
Cntd..
Below we declare a class named Fruit consisting of two properties ($name
and $color) and two methods set_name() and get_name() for setting and
getting the $name property:
<?php
class Fruit {
// Properties
public $name;
public $color;

// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
7
?>
Define Objects
• The object is declared to use the properties of a class.
• The object variable is declared by using the new keyword followed by the
class name.
• Multiple object variables can be declared for a class.
• The object variables are work as a reference variable. So, if the property
value of any class is modified by one object then the property value of
another object of the same class will be changed at a time.
Syntax:

$object_name = new Class_name()

8
Example
• <?php
//Declare class
class Product
{
//Declare properties
public $name = "Cake";
public $price = 20;

}
//Declare object
$obj_pro = new Product;
//Print all object properties
print_r($obj_pro);
//Print each property separately
echo "<br />Product Name: ".$obj_pro->name."<br />";
echo "Product Price: ".$obj_pro->price."<br />";

?>
9
Best Practices

• Use classes to create objects and define the properties and methods
of the object.
• Use constructors to set the initial values of an object's properties, and
to perform any necessary setup when an object is created.
• Keep objects small and focused, with a single responsibility. This
makes the code easier to understand and maintain.
• Use clear and descriptive property and method names to make it easy
to understand what the object does and how it is used.

10
CONTINUE……

• Use encapsulation to hide the implementation details of an object,


and expose only the necessary properties and methods to the rest of
the code.
• Use inheritance and polymorphism to reuse code and create a
hierarchy of classes.
• Use interfaces to define contracts and ensure that objects conform to
a specific set of methods.
• Avoid using global objects, as they can make the code difficult
to understand and maintain.

11
Book References
• Php: The Complete Reference, Steven Holzner, Tata McGraw-
Hill Education, 2007
• Modern PHP: New Features and Good Practices, Josh Lockhart,
"O'Reilly Media, Inc.“, 2015.
• PHP for the Web: Visual QuickStart Guide, Larry Ullman
Pearson Education, 2006.
• https://www.tutorialspoint.com/php/index.htm
• https://www.codecademy.com/learn/learn-php

12
THANK YOU

You might also like