Adsense 728 * 15

Search

Custom Search

OOPs Concept in PHP



PHP Classes Tutorial


Concept of Public ,Private and Protected in PHP


Public variables are accessed anywhere




<?php


class calculate
{
public $value=40; //It can be accessed anywhere
}


$calculate =new calculate;


echo $calculate->value; // No need of $ sign before value

?>

Output-

40

Protected fields in PHP


when you declare variable or function Protected it means it is available only within the class, or any class that is derived from the class

<?php


class calculate
{
public $value=40; //It can be accessed anywhere
}


$calculate =new calculate;


echo $human->value; // No need of $ sign before value

?>

Output-

Fatal error: Cannot access protected property calculate


In case of private member



<?php


class calculate
{
public $value=40; //It can be accessed anywhere
}


$calculate =new calculate;


echo $human->value; // No need of $ sign before value

?>



Output-


Fatal error: Cannot access private property




PHP Tutorial

No comments:

Post a Comment