100% found this document useful (1 vote)
126 views2 pages

OOPS

The document discusses classes and objects in PHP. It defines a class as a blueprint that contains methods and properties to define objects. An object bundles variables and functions into a single entity that can be called rather than its individual components. The key differences between an abstract class and interface are that an abstract class can contain non-abstract methods but must have at least one abstract method, while an interface consists only of abstract methods that must be defined in any implementing class.

Uploaded by

bhaway2k8
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
126 views2 pages

OOPS

The document discusses classes and objects in PHP. It defines a class as a blueprint that contains methods and properties to define objects. An object bundles variables and functions into a single entity that can be called rather than its individual components. The key differences between an abstract class and interface are that an abstract class can contain non-abstract methods but must have at least one abstract method, while an interface consists only of abstract methods that must be defined in any implementing class.

Uploaded by

bhaway2k8
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Classes:

A class is the blueprint for your object. The class contains the methods and properties, or
the characteristics of the object. It defines the object You declare class in PHP by using
the class keyword.

<?php
class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}

class B
{
function bar()
{
A::foo();
}
}

$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>

The above example will output:

$this is defined (a)


$this is not defined.
$this is defined (b)
$this is not defined.
Objects:

Simply put, an object is a bunch of variables and functions all lumped


into a single entity. The object can then be called rather than calling
the variables or functions themselves. Within an object there are
methods and properties. The methods are functions that manipulate data
within the object. The properties are variables that hold information
about the object.

What are the difference between abstract class and interface?

Abstract class: abstract classes are the class where one or more
methods are abstract but not necessarily all method has to be abstract.
Abstract methods are the methods, which are declare in its class but
not define. The definition of those methods must be in its extending
class.

Interface: Interfaces are one type of class where all the methods are
abstract. That means all the methods only declared but not defined. All
the methods must be define by its implemented class.

You might also like