Hello Readers
Oops was introduced in php version 4 but the area of php version 4 is not very fast, as version 4 consists few features, hence the major concept of Oops are introduced in php version 5 which is called php5.
Oops include the below things:
Classes and objects
Magic functions
Specifiers(private, public and protected)
Static method and property
Abstract classes and interface
Overloading and overriding
Cloning
Type hinting
It is a technique to design the application and application could be any type like it could be web based application or any other application.
In oops everything is around the classes and objects.
Advantages of Oops:
Open source
stable
re-usability of code
easy to maintain
Good level of abstraction
clear structure of code
much suitable for large projects
memory management features
Late binding
Basic example of oops using class and its object in php
<?php
class oopsClass
{
// Class properties and methods go here
}
?>
After creating the class, a new class can be instantiated and stored in a variable using the new keyword:
$obj = new oopsClass;
To see the contents of the class, use var_dump():
var_dump($obj);
Now we merge all the above code and save in php file name called demo.php
<?php
class oopsClass
{
// Class properties and methods go here
}
$obj = new oopsClass;
var_dump($obj);
?>
Load the page in your browser at http://localhost/demo.php and the following should display:
object(oopsClass)#1 (0) { }
0 Comment(s)