Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Class in PHP | How create classes in PHP

Classes in PHP

Php Classes.Classes in Php is a new Concept like C++.It covers the OOPs concept in PHP.OOPs stands for Object Oriented Programming.you can create classes in PHP like c++ with functions.

To do this:


class abc
{
function add1()
{
$a=10;
$b=20;
$c=$a+$b;
echo $c;
}
}
$obj=new abc;
$obj->add1();
?>

In the above PHP class example, we create a class with name "abc" also create function name "add1"
we declare two variable a and b and assign them value.Add them and assign the result to another variable c and show the result with echo command.

After this, we create an object of the class and call the function using that object. 

We can add multiple classes and functions in PHP.


class abc
{
function add1()
{
$a=10;
$b=20;
$c=$a+$b;
echo $c;
}
function mul()
{
$a=10;
$b=20;
$c=$a*$b;
echo $c;
}
}
$obj=new abc;
$obj->add1();
echo "";
$obj->mul();

?>

PHP Class



Php Class
Php Class





This post first appeared on The Code Developer, please read the originial post: here

Share the post

Class in PHP | How create classes in PHP

×

Subscribe to The Code Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×