The document discusses object-oriented programming concepts in PHP including classes, objects, inheritance, encapsulation, and polymorphism. It provides examples of defining classes, creating objects, accessing properties and methods, constructors, destructors, inheritance, overriding methods, scopes, interfaces, constants, abstract classes, and calling parent functions. Key concepts are explained like public, private, and protected access modifiers, abstract classes and methods, and using parent, self and static keywords.
Object oriented programming assume everything as an object
Class − This is a programmer-defined data type, which includes local functions as well as local data.
Object − An individual instance of the data structure defined by a class.
Member Variable − These are the variables defined inside a class.
Member function − These are the function defined inside a class and are used to access object data.
Inheritance − When a class is defined by inheriting existing function of a parent class then it is called inheritance.
Parent class − A class that is inherited from by another class. This is also called a base class or super class.
Child Class − A class that inherits from another class. This is also called a subclass or derived class.
Polymorphism − This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it take different number of arguments and can do different task.
Data Abstraction − Any representation of data in which the implementation details are hidden (abstracted).
Encapsulation − refers to a concept where we encapsulate all the data and member functions together to form an object.
Constructor − refers to a special type of function which will be called automatically whenever there is an object formation from a class.
Destructor − refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.
....
Abstraction, Encapsulation, Polymorphism, Interfaces and Scope: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense.
Real life examples of Object-Oriented terminology in a way that makes sense and allows you to utilizing OOP immediately.
Object oriented programming assume everything as an object
Class − This is a programmer-defined data type, which includes local functions as well as local data.
Object − An individual instance of the data structure defined by a class.
Member Variable − These are the variables defined inside a class.
Member function − These are the function defined inside a class and are used to access object data.
Inheritance − When a class is defined by inheriting existing function of a parent class then it is called inheritance.
Parent class − A class that is inherited from by another class. This is also called a base class or super class.
Child Class − A class that inherits from another class. This is also called a subclass or derived class.
Polymorphism − This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it take different number of arguments and can do different task.
Data Abstraction − Any representation of data in which the implementation details are hidden (abstracted).
Encapsulation − refers to a concept where we encapsulate all the data and member functions together to form an object.
Constructor − refers to a special type of function which will be called automatically whenever there is an object formation from a class.
Destructor − refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.
....
Abstraction, Encapsulation, Polymorphism, Interfaces and Scope: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense.
Real life examples of Object-Oriented terminology in a way that makes sense and allows you to utilizing OOP immediately.
If you are new to programing in general OR if you started programing in php before Object-Oriented Programming was even available, this presentation is designed to help you get up to speed on Object-Oriented terminology and give you practical skills as well as resources to continue learning.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
This presentation deals with pure object oriented concepts and defines basic principles of OOP's like Encapsulation , polymorphism , Inheritance and Abstraction.
Webinar topic: Migration from Procedural to OOP (Indonesian)
Presenter: Achmad Mardiansyah
In this webinar series, We are discussing a migration of the PHP development model from Procedural to OOP (Object Oriented Programming). This slide is a part of PHP ID (PHP Indonesia) Online Learning #6.
Please share your feedback or webinar ideas here: http://bit.ly/glcfeedback
Check our schedule for future events: https://www.glcnetworks.com/schedule/
Follow our social media for updates: Facebook, Instagram, YouTube Channel, and telegram
Recording available on Youtube
https://youtu.be/y3w6H04yPDU
Abstraction, encapsulation, polymorphism, and interfaces: whether you've been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole object-oriented thing is way more complicated. Not only that, people that already understand it, act like it's so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session, we'll take you through real-life examples of object-oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilize object-oriented programming (OOP) immediately.
To better understand the behavior of servlets, let’s take a look at the life cycle of servlets.
A servlet is basically a small Java program that runs within a Web server. It can receive requests from clients and return responses. The whole life cycle of a servlet breaks up into 3 phases:
• Initialization: A servlet is first loaded and initialized usually when it is requested by the corresponding clients. Some websites allow the users to load and initialize servlets when the server is started up so that the first request will get responded more quickly.
• Service: After initialization, the servlets serve clients on request, implementing the ap- plication logic of the web application they belong to.
• Destruction: When all pending requests are processed and the servlets have been idle for a specific amount of time, they may be destroyed by the server and release all the resources they occupy.
More specifically, the behavior of a servlet is described in javax.servlet.Servlet interface, in which the following methods are defined:
• public void init(ServletConfig config) throws ServletException
This method is called once when the servlet is loaded into the servlet engine, before the servlet is asked to process its first request.
The init method has a ServletConfig parameter. The servlet can read its initialization arguments through the ServletConfig object. How the initialization arguments are set is servlet engine dependent but they are usually defined in a configuration file.
A typical example of an initialization argument is a database identifier. A servlet can read this argument from the ServletConfig at initialization and then use it later to open a connection to the database during processing of a request:
private String databaseURL;
public void init(ServletConfig config) throws ServletException { super.init(config);
databaseURL = config.getInitParameter("database");
}
• public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
This method is called to process a request. It can be called zero, one or many times until the servlet is unloaded.
Once a servlet is loaded, it remains in the server’s memory as a single object instance. Thereafter, the server invokes the servlet to handle a request using a simple, lightweight method invocation. Unlike with CGI, there’s no process to spawn or interpreter to invoke, so the servlet can begin handling the request almost immediately. Multiple, concurrent requests are handled by separate threads, so servlets are highly scalable.
Servlets are naturally enduring objects. Because a servlet stays in the server’s memory as a single object instance, it automatically maintains its state and can hold on to external resources, such as database connections, that may otherwise take several seconds to establish. The following servlet presents information about how many times it has been accessed:
To better understand the behavior of servlets, let’s take a lo
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
If you are new to programing in general OR if you started programing in php before Object-Oriented Programming was even available, this presentation is designed to help you get up to speed on Object-Oriented terminology and give you practical skills as well as resources to continue learning.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
This presentation deals with pure object oriented concepts and defines basic principles of OOP's like Encapsulation , polymorphism , Inheritance and Abstraction.
Webinar topic: Migration from Procedural to OOP (Indonesian)
Presenter: Achmad Mardiansyah
In this webinar series, We are discussing a migration of the PHP development model from Procedural to OOP (Object Oriented Programming). This slide is a part of PHP ID (PHP Indonesia) Online Learning #6.
Please share your feedback or webinar ideas here: http://bit.ly/glcfeedback
Check our schedule for future events: https://www.glcnetworks.com/schedule/
Follow our social media for updates: Facebook, Instagram, YouTube Channel, and telegram
Recording available on Youtube
https://youtu.be/y3w6H04yPDU
Abstraction, encapsulation, polymorphism, and interfaces: whether you've been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole object-oriented thing is way more complicated. Not only that, people that already understand it, act like it's so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session, we'll take you through real-life examples of object-oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilize object-oriented programming (OOP) immediately.
To better understand the behavior of servlets, let’s take a look at the life cycle of servlets.
A servlet is basically a small Java program that runs within a Web server. It can receive requests from clients and return responses. The whole life cycle of a servlet breaks up into 3 phases:
• Initialization: A servlet is first loaded and initialized usually when it is requested by the corresponding clients. Some websites allow the users to load and initialize servlets when the server is started up so that the first request will get responded more quickly.
• Service: After initialization, the servlets serve clients on request, implementing the ap- plication logic of the web application they belong to.
• Destruction: When all pending requests are processed and the servlets have been idle for a specific amount of time, they may be destroyed by the server and release all the resources they occupy.
More specifically, the behavior of a servlet is described in javax.servlet.Servlet interface, in which the following methods are defined:
• public void init(ServletConfig config) throws ServletException
This method is called once when the servlet is loaded into the servlet engine, before the servlet is asked to process its first request.
The init method has a ServletConfig parameter. The servlet can read its initialization arguments through the ServletConfig object. How the initialization arguments are set is servlet engine dependent but they are usually defined in a configuration file.
A typical example of an initialization argument is a database identifier. A servlet can read this argument from the ServletConfig at initialization and then use it later to open a connection to the database during processing of a request:
private String databaseURL;
public void init(ServletConfig config) throws ServletException { super.init(config);
databaseURL = config.getInitParameter("database");
}
• public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
This method is called to process a request. It can be called zero, one or many times until the servlet is unloaded.
Once a servlet is loaded, it remains in the server’s memory as a single object instance. Thereafter, the server invokes the servlet to handle a request using a simple, lightweight method invocation. Unlike with CGI, there’s no process to spawn or interpreter to invoke, so the servlet can begin handling the request almost immediately. Multiple, concurrent requests are handled by separate threads, so servlets are highly scalable.
Servlets are naturally enduring objects. Because a servlet stays in the server’s memory as a single object instance, it automatically maintains its state and can hold on to external resources, such as database connections, that may otherwise take several seconds to establish. The following servlet presents information about how many times it has been accessed:
To better understand the behavior of servlets, let’s take a lo
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfKamal Acharya
The College Bus Management system is completely developed by Visual Basic .NET Version. The application is connect with most secured database language MS SQL Server. The application is develop by using best combination of front-end and back-end languages. The application is totally design like flat user interface. This flat user interface is more attractive user interface in 2017. The application is gives more important to the system functionality. The application is to manage the student’s details, driver’s details, bus details, bus route details, bus fees details and more. The application has only one unit for admin. The admin can manage the entire application. The admin can login into the application by using username and password of the admin. The application is develop for big and small colleges. It is more user friendly for non-computer person. Even they can easily learn how to manage the application within hours. The application is more secure by the admin. The system will give an effective output for the VB.Net and SQL Server given as input to the system. The compiled java program given as input to the system, after scanning the program will generate different reports. The application generates the report for users. The admin can view and download the report of the data. The application deliver the excel format reports. Because, excel formatted reports is very easy to understand the income and expense of the college bus. This application is mainly develop for windows operating system users. In 2017, 73% of people enterprises are using windows operating system. So the application will easily install for all the windows operating system users. The application-developed size is very low. The application consumes very low space in disk. Therefore, the user can allocate very minimum local disk space for this application.
Automobile Management System Project Report.pdfKamal Acharya
The proposed project is developed to manage the automobile in the automobile dealer company. The main module in this project is login, automobile management, customer management, sales, complaints and reports. The first module is the login. The automobile showroom owner should login to the project for usage. The username and password are verified and if it is correct, next form opens. If the username and password are not correct, it shows the error message.
When a customer search for a automobile, if the automobile is available, they will be taken to a page that shows the details of the automobile including automobile name, automobile ID, quantity, price etc. “Automobile Management System” is useful for maintaining automobiles, customers effectively and hence helps for establishing good relation between customer and automobile organization. It contains various customized modules for effectively maintaining automobiles and stock information accurately and safely.
When the automobile is sold to the customer, stock will be reduced automatically. When a new purchase is made, stock will be increased automatically. While selecting automobiles for sale, the proposed software will automatically check for total number of available stock of that particular item, if the total stock of that particular item is less than 5, software will notify the user to purchase the particular item.
Also when the user tries to sale items which are not in stock, the system will prompt the user that the stock is not enough. Customers of this system can search for a automobile; can purchase a automobile easily by selecting fast. On the other hand the stock of automobiles can be maintained perfectly by the automobile shop manager overcoming the drawbacks of existing system.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Democratizing Fuzzing at Scale by Abhishek Aryaabh.arya
Presented at NUS: Fuzzing and Software Security Summer School 2024
This keynote talks about the democratization of fuzzing at scale, highlighting the collaboration between open source communities, academia, and industry to advance the field of fuzzing. It delves into the history of fuzzing, the development of scalable fuzzing platforms, and the empowerment of community-driven research. The talk will further discuss recent advancements leveraging AI/ML and offer insights into the future evolution of the fuzzing landscape.
Courier management system project report.pdfKamal Acharya
It is now-a-days very important for the people to send or receive articles like imported furniture, electronic items, gifts, business goods and the like. People depend vastly on different transport systems which mostly use the manual way of receiving and delivering the articles. There is no way to track the articles till they are received and there is no way to let the customer know what happened in transit, once he booked some articles. In such a situation, we need a system which completely computerizes the cargo activities including time to time tracking of the articles sent. This need is fulfilled by Courier Management System software which is online software for the cargo management people that enables them to receive the goods from a source and send them to a required destination and track their status from time to time.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
3. Object Oriented Programming
● OOP stands for Object-Oriented Programming.
● Procedural programming is about writing procedures or functions that perform
operations on the data, while object-oriented programming is about creating objects
that contain both data and functions.
Object-oriented programming has several advantages over procedural programming:
● OOP is faster and easier to execute
● OOP provides a clear structure for the programs
● OOP helps to keep the PHP code DRY "Don't Repeat Yourself", and makes the code
easier to maintain, modify and debug
● OOP makes it possible to create full reusable applications with less code and shorter
development time
4. The object-oriented approach(Terminology)
● Class: This is a programmer-defined data type, which includes local functions as well as
local data.
● Object: (Also known as object instance, or instance.)
○ An individual instance of the data structure defined by a class.
○ You define a class once and then make many objects that belong to it.
● Member variable: (Also known as property, attribute, or instance variable.) One of the
component pieces of data in a class definition.
● Member function: (Also known as method.) A member that happens to be a function.
5. ● Inheritance:
○ The process of defining a class in terms of another class.
○ The new (child) class has all the member data and member function definitions from the
old (parent) class by default but may define new members or “override” parent functions
and give them new definitions.
○ We say that class A inherits from class B if class A is defined in terms of class B in this
way.
○ Parent class (or superclass or base class): A class that is inherited from by another
class.
○ Child class (or subclass or derived class): A class that inherits from another class.
6. Single inheritance
● PHP allows a class definition to inherit from another class, using the extends clause. Both
member variables and member functions are inherited.
Multiple inheritance
● PHP offers no support for multiple inheritance as in Java. Each class inherits from, at most,
one parent class (though a class may implement many interfaces).
Encapsulation − refers to a concept where we encapsulate all the data and member functions
together to form an object.
○ It is also known as information hiding concept
Constructor − refers to a special type of function which will be called automatically whenever there
is an object formation from a class.
Destructor − refers to a special type of function which will be called automatically whenever an
object is deleted or goes out of scope.
7. Basic PHP Constructs for OOP
Defining classes
class myclass {
public $var1;
public $var2 ;
public function myfunc ($arg1, $arg2)
{
……..
}
}
8. The form of the syntax is as described, in order, in the following list:
● The special form class, followed by the name of the class that you want to define.
● A set of braces enclosing any number of variable declarations and function definitions.
● Variable declarations start with the special form public, private, or protected, which
is followed by a conventional $ variable name; they may also have an initial assignment
to a constant value.
9. Creating instances
After we have a class definition, the default way to make an instance of that class is by
using the new operator
Example: objectname = new classname;
$box = new TextBoxSimple;
$box->display();
Accessing member variables
In general, the way to refer to a member variable from an object is to follow a variable
containing the object with -> and then the name of the member
Example : $variablename =object->member variable
$textbox = $box->body_text;
10. Example:
<?php
class Fruit {
// Properties
public $name;
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
$apple = new Fruit();// object creation
$apple->set_name('Apple');
echo $apple->get_name();
?>
11. After we have a class definition, the default way to make an instance of that class is by
using the new operator
Example: objectname = new classname;
$box = new TextBoxSimple;
$box->display();
In general, the way to refer to a member variable from an object is to follow a variable
containing the object with -> and then the name of the member
Example : $variablename =object->member variable
$textbox = $box->body_text;
12. Constructor functions
● A constructor allows you to initialize an object's properties upon creation of the
object.
● The correct way to arrange for data to be appropriately initialized is by writing a
constructor function — a special function called __construct(), which will be called
automatically whenever a new instance is created.
● The construct function starts with two underscores (__)
13. Example 1
<?php
class text
{
public $a;
function __construct($a)// constructor
{
$this->a = $a;
}
function display()
{
echo $this->a;
}
}
$text1= new text("hello");
$text1->display();
?>
14.
15. Example 2
<?php
class student
{
public $id;
public $name;
function __construct($id,$name)
{
$this->id = $id;
$this->name = $name;
}
function display1()
{
echo $this->id;
}
function display2()
{
echo $this->name;
}}
$s1= new student(2,"arun");
echo "<center>";
echo "<table border='1'>";
echo "<th>id</th><th>name</th>";
echo "<tr><td>";
$s1->display1();
echo "<td>";
$s1->display2();
echo "</td></tr>";
echo "</center>";
?>
16. Destructor functions
● A destructor is called when the object is destructed or the script is stopped or exited.
● The destruct() function will be called automatically at the end of the script.
● The destruct function starts with two underscores(__)
<?php
class text
{
public $a;
function __construct($a)// constructor
{
$this->a = $a;
}
function __destruct()
{
echo $this->a;
}
}
$text1= new text("hello");
?>
17. Inheritance
● Inheritance in OOP = When a class derives from another class.
● The child class will inherit all the public and protected properties and methods from
the parent class. In addition, it can have its own properties and methods.
● An inherited class is defined by using the extends keyword.
● PHP class definitions can optionally inherit from a parent class definition by using the
extends clause.
● The syntax is:
class Child extends Parent {
<definition body>
}
18. The effect of inheritance is that the child class (or subclass or derived class) has the
following characteristics:
● Automatically has all the member variable declarations of the parent class (or
superclass or base class)
● Automatically has all the same member functions as the parent, which (by default) will
work the same way as those functions do in the parent
19. Example:
<?php
class student {
public $name;
public $mark1;
public $mark2;
public function __construct($name, $mark1,$mark2) {
$this->name = $name;
$this->mark1 = $mark1;
$this->mark2 = $mark2;
}
public function display() {
echo "name=".$this->name."<br>";
echo "mark1=".$this->mark1."<br>";
echo "mark2=".$this->mark2."<br>";}
}
class addition extends student
{
public $total;
public function add()
{
$total=$this->mark1+$this-
>mark2;
echo "total=".$total;;
}
}
$s1 = new addition("Abi",50,60);
$s1->display();
$s1->add();
?>
20.
21. Chained subclassing
● PHP does not support multiple inheritance but does support chained subclassing.
● This is a fancy way of saying that, although each class can have only a single parent,
classes can still have a long and distinguished ancestry (grandparents, great-
grandparents, and so on). (multilvel)
● Also, there’s no restriction on family size;
● each parent class can have an arbitrary number of children. (Hierarchical)
22.
23. Example1:(multilevel inheritance)
<?php
class student {
public $name;
public $m1;
public $m2;
public function get() {
$this->name = "arun";
$this->m1 =60;
$this->m2 =70;
}
public function display() {
echo "name=".$this->name."<br>";
echo "mark1=".$this->m1."<br>";
echo "mark2=".$this->m2."<br>";
24. class total extends student
{
public $total;
public function computeTotal()
{
$this->total= $this->m1+$this->m2;
echo "total=".$this->total."<br>";
}
}
class avg extends total
{
public $avg;
public function calculateAvg()
{
$this->avg=$this->total= $this->total/2;
echo "avg=".$this->avg;
}
}
$avg1 = new avg();
$avg1->get();
$avg1->display();
$avg1->computeTotal();
$avg1->calculateAvg();
?>
25. Example2:(Hierarchical inheritance)
<?php
class arith{
public $m1;
public $m2;
public function get() {
$this->m1 =60;
$this->m2 =70;
}
public function display() {
echo "number1=".$this->m1."<br>";
echo "number2=".$this->m2."<br>";
}
}
class addition extends arith
{
public $add;
public function computeadd()
{
$this->add= $this->m1+$this->m2;
echo "add=".$this->add."<br>";
}
}
26. class subtraction extends arith
{
public $sub;
public function calculatesub()
{
$this->sub=$this->m1-$this->m2;
echo "sub=".$this->sub;
}
}
$a1=new addition();
$s1=new subtraction();
$a1->get();
$a1->display();
$a1->computeadd();
$s1->get();
$s1->calculatesub();
?>
27. Overriding method (functions)
● Method overriding allows a child class to provide a specific implementation of a method
already provided by its parent class.
● Method overriding occurs when a subclass (child class) has the same method as the
parent class
● To override a method, you redefine that method in the child class with the same name,
parameters, and return type.
● The method in the parent class is called overridden method,
● while the method in the child class is known as the overriding method.
● The code in the overriding method overrides (or replaces) the code in the overridden
method.
28. PHP will decide which method (overridden or overriding method) to call based on the
object used to invoke the method.
● If an object of the parent class invokes the method, PHP will execute the
overridden method.
● But if an object of the child class invokes the method, PHP will execute the
overriding method.
29. Example:
<?php
class base{
public function display() {
echo "parent method";
}
}
class sub extends base
{
public function display()
{
echo "child method";
}
}
$sub1=new sub();
$sub1->display();
?>
30. Scoping issues
● Names of member variables and member functions are never meaningful to calling
code on their own , they must always be reached via the -> construct
● The names visible within member functions are exactly the same as the names
visible within global functions — that is, member functions can refer freely to
other global functions but can’t refer to normal global variables unless those
variables have been declared global inside the member function definition.
31. Advanced OOP features
1.Public, Private, and Protected Members
Public:(default access speicifier)
Unless you specify otherwise, properties and methods of a class are public. That is to say,
they may be accessed in three possible situations:
● The property or method can be accessed from everywhere. This is default
○ From outside the class in which it is declared
○ From within the class in which it is declared
○ From within another class that implements the class in which it is declared
32. Example:
<?php
class student {
var $name;// default access specifier public
public $mark1,$mark2;
function get($name, $mark1,$mark2)
{
$this->name = $name;
$this->mark1 = $mark1;
$this->mark2 = $mark2;
}
function display()
{
echo "name=".$this->name."<br>";
echo "mark1=".$this->mark1."<br>";
echo "mark2=".$this->mark2."<br>";}
}
$s1 = new student();
$s1->get("nithya",50,60);
$s1->display();
?>
33. Private:
● The property or method can ONLY be accessed within the class
● The private member cannot be referred to from classes that inherit the class in
which it is declared and cannot be accessed from outside the class.
Protected:
● The property or method can be accessed within the class and by classes derived from
that class
● A protected property or method is accessible in the class in which it is declared, as
well as in classes that extend that class
34. Example:
<?php
class student {
protected $name;
protected $mark1,$mark2;
function get($name, $mark1,$mark2) {
$this->name = $name;
$this->mark1 = $mark1;
$this->mark2 = $mark2;
}
function display() {
echo "name=".$this->name."<br>";
echo "mark1=".$this->mark1."<br>";
echo "mark2=".$this->mark2."<br>";}
}
class addition extends student
{
function add()
{
$total=$this->mark1+$this->mark2;
echo "total=".$total;;
}}
$s1 = new addition();
$s1->get("nithi",50,60);
$s1->display();
$s1->add();
?>
35. 2.Interfaces
● Interfaces allow you to specify what methods a class should implement.
● An interface consists of methods that have no implementations, which means the
interface methods are abstract methods.
● All the methods in interfaces must have public visibility scope.
● Interfaces are different from classes as the class can inherit from one class only
whereas the class can implement one or more interfaces.
37. Program:
<?php
interface Arithmetic
{
public function add();
}
class Addition implements Arithmetic
{
var $p,$q;
public function add() {
$this->p=50;
$this->q=40;
$this->sum=$this->p+$this->q;
echo "add=".$this->sum;
}
}
$obj1 = new Addition();
$obj1->add();
?>
38. 3.Constants
● A constant is somewhat like a variable, in that it holds a value but is really more like a
function because a constant is immutable. Once you declare a constant, it does not
change.
● The constant’s name does not have a leading $, as variable names do.
● Constants cannot be changed once it is declared.
● Class constants can be useful if you need to define some constant data within a class.
● A class constant is declared inside a class with the const keyword.
● We can access a constant from outside the class by using the class name followed by
the scope resolution operator (::) followed by the constant name
● we can access a constant from inside the class by using the self keyword followed by
the scope resolution operator (::)
39. Program:
<?php
class area
{
const pi=3.14; // const value
var $r,$a;
function get($r)
{
$this->r = $r;
}
function compute()
{
$this->a= self::pi*$this->r*$this->r;
echo "area of circle=".$this->a;
}
}
$area1 = new area();
$area1->get(6);
$area1->compute();
?>
40. 4.Abstract classes
● An abstract class is one that cannot be instantiated, only inherited.
● An abstract class is a class that contains at least one abstract method.
● An abstract method is a method that is declared, but not implemented in the code.
● An abstract class or method is defined with the abstract keyword
abstract class MyAbstractClass
{
abstract function myAbstractFunction()
{
}
}
41. Program:
<?php
abstract class rect
{
var $l,$b,$a;
function get()
{
$this->l=6;
$this->b=5;
}
abstract function compute();
}
class area extends rect
{
function compute()
{
$this->a=$this->l*$this->b;
echo "area of rect =".$this->a;
}
}
$area1 = new area();
$area1->get();
$area1->compute();
42. 5.Simulating class functions
● In PHP, there are no declarations in a class definition that indicate whether a function
is intended for per-instance or per-class use.
● But PHP does offer a syntax for getting to functions in a class even when no instance
is handy.
● The :: syntax operates much like the -> syntax does, except that it joins class names
to member functions rather than instances to members
44. 6.Calling parent functions
Calling parent constructors
● To call the constructor of the parent class from the constructor of the child class,
use following syntax
○ parent::__construct(arguments)
Automatic calls to parent constructors
if a subclass lacks a constructor function(not having constructor) and a superclass has
one, the superclass’s constructor will be invoked
45. Program:
<?php
class student
{
protected $name;
protected $m1;
protected $m2;
public function __construct($name)
{
$this->name = $name;
}
}
class details extends student
{
public function __construct($name,$m1,$m2)
{
student::__construct($name); // call to parent constructor
$this->m1=$m1;
$this->m2=$m2;
}
public function compute()
{
echo $this->name;
echo "<br>";
$total= $this->m1+$this->m2;
echo $total;
}
}
$d= new details("nithi",60,70);
$d->compute();
?>
46. 7.Simulating method overloading
● Method overloading contains same function name and that function performs
different task according to number of arguments
● In PHP overloading means the behavior of method changes dynamically according to
the input parameter.
● The __call() method is invoked automatically when a non-existing method or
inaccessible method is called. The following shows the syntax of the __call() method:
○ public __call ( string $name , array $arguments )
● The __call() method accepts two arguments:
● $name is the name of the method that is being called by the object.
● $arguments is an array of arguments passed to the method call.
47. Program:
<?php
class Shape {
const PI = 3.142 ;
function __call($name,$arg)
{
$count=count($arg);
if($count==1)
{
$c= self::PI*$arg[0];
echo "area of circle=".$c;
}
elseif($count==2)
{
$c= $arg[0]*$arg[1];
echo "area of rect=".$c;
} }
}
$s = new Shape();
$s->area(8,6);
echo "<br>";
$s->area(3);
?>
48. 8.Serialization
● Serialization of data means converting it into a string of bytes in such a way that you can produce
the original data again from the string (via a process known, unsurprisingly, as unserialization).
● PHP provides a mechanism for storing and loading data with PHP types across multiple HTTP
requests.
● This mechanism boils down to two functions: serialize() and unserialize().
Serialization
● A string representation of any object in the form of byte-stream is obtained by serialize()
function in PHP
● All property variables of object are contained in the string and methods are not saved. This string
can be stored in any file
Deserialization
● To retrieve the object from the byte stream, there is unserialize() function
49. Sample serialization output
O:8:"stdClass":1:{s:4:"data";s:10:"Some data!";}
● The O stands for the type of the serialized string. In this case the O maps to a PHP
object.
● The 8 seperated by the colons represents the length of the name of the class
● The following 1 represents the number of properties the serialized object contains
which are stored within curly brackets
● Each property is stored as a serialized string representing the property name, a
semicolon and a serialized string representing the value.
50. Program 1:
<?php
class test1
{
public $name;
function get($arg){
$this->name=$arg;
}
function display()
{
echo $this->name;
}
}
$obj1=new test1();
$obj1->get("nithi");
echo "<b>serialization<br></b>";
$str=serialize($obj1);
echo $str;
echo "<b><br>Unserialization</b>";
$obj2 = unserialize($str);
echo "<br>";
$obj2->display();
?>
51. Program 2:
<?php
class createserialize
{
public $a,$b;
public function __construct($s,$p)
{
$this->a = $s;
$this->b = $p;
}
public function display ()
{
echo $this->a;
echo $this->b;
}
}
$obj1 = new createserialize(10,20);
echo "<b>Serialization<br></b>";
$str = serialize($obj1);
echo $str;
echo "<b><br>Unserialization<br></b>";
$obj2 = unserialize($str);
$obj2->display();
?>
52. Sleep and wakeup
● __sleep and __wakeup are methods that are related to the serialization process.
● Serialize function checks if a class has a __sleep method.
○ If so, it will be executed before any serialization. __sleep is supposed to return
an array of the names of all variables of an object that should be serialized.
● __wakeup in turn will be executed by unserialize if it is present in class.
○ It's intention is to re-establish resources and other things that are needed to
be initialized upon unserialization.
53. Program 1:
<?php
class serializedemo
{
public $message, $message1;
public function __construct($statement)
{
$this->message = $statement;
$this->message1= $this->message."Again";
}
public function __sleep() {
return array('message');
}
public function __wakeup() {
$this->message1 =$this->message . "Again!";
}
public function display ()
{
echo $this->message1;
}
}
$obj1 =new serializedemo("Welocme you!");
$serialization = serialize($obj1);
$obj2 = unserialize($serialization);
$obj2->display();
?>
54. Introspection Functions
● Introspection in PHP offers the useful ability to examine an object's
characteristics, such as its name, parent class (if any) properties,
classes, interfaces, and methods.
● PHP offers a large number of functions that you can use to accomplish
the task.
55.
56.
57. These functions break down into the following four broad categories:
● Getting information about the class hierarchy
● Finding out about member variables
● Finding out about member functions
● Actually calling member functions
58. Program 1:
<?php
class Example
{
public $var1 = "initialized";
public $var2 = "initialized";
public $var3;
public $var4;
public function __construct()
{
$this->var3 = "set";
$this->var1 = "changed";
}
}
$example = new Example();
print_r(get_class_vars("Example"));
echo "<br>";
print_r(get_object_vars($example));
?>
59. Example 1:Class genealogy
<?php
class UIElement {}
class Control extends UIelement {}
class Widget extends Control { }
class Button extends Widget {}
class Clicker extends Button {}
function ancestry($class_name)
{
echo $class_name;
if ($parent = get_parent_class($class_name))
{
print(" => ");
ancestry($parent);
}
}
echo "Class ancestry:”;
ancestry("Clicker");
?>
61. 1.Naming conventions
● we simply pass along the parts of the PEAR coding style that pertain to objects
● PEAR is short for "PHP Extension and Application Repository"
● PEAR recommends that class names begin with an uppercase letter and have that inclusion
path in the class name, separated by underscores
● If your class that counts words, and which belongs to a PEAR package called TextUtils, might
be called TextUtils_WordCounter.
● Member variables and member function names should have their first real letter be lowercase
and have word boundaries be delineated by capitalization.
● In addition, names that are intended to be private to the class should start with an
62. 2.Accessor functions
● Another style of documenting your intent about use of internal variables is to have your
variables marked as private, in general, and
● It provides “getter” and “setter” functions to outside callers.
63. Example 1:
<?php
class Customer
{
private $_name;
private $_rating;
function getName ()
{
$this->_name="nithi";
return($this->_name);
}
function getRating ()
{
return($this->_rating);
}
function setRating($rating)
{
$this->_rating = $rating;
}
}
$obj1 = new Customer();
echo $obj1->getName();
$obj1->setRating(4);
echo $obj1->getRating();
?>