Visibility Scope Of Variable And Functions

There are three type of visibility scope:

  • Public
  • Private
  • Protected

PUBLIC:

Variable or function of public scope can be accessed throughout the program.

PRIVATE :

Variable or function of private scope can be accessed only with in the class they are declared.

PROTECTED:

Variable or function of protected scope can be accessed only by its subclass and derived class.
<?php
/**
* Define ClassA
*/
class ClassA
{
public $a = 1;
protected $b = 2;
private $c = 3;
function detail()
{
echo $this->a;
echo $this->b;
echo $this->c;
}
}
$obj = new ClassA();
echo $obj->a; // Works
echo $obj->b; // Fatal Error
echo $obj->c; // Fatal Error
$obj->detail(); // Shows Public, Protected and Private

– See more at: http://findnerd.com/list/view/Visibility-Scope-Of-Variable-And-Functions/3556/

For queries about PHP Programming Questions and Answers

You can also Visit to PHP Developer Forum

Advertisements
Visibility Scope Of Variable And Functions

3 thoughts on “Visibility Scope Of Variable And Functions

  1. […] CakePHP has power to do a lot with conventions by using routes. It’s additionally possible to utilize custom prefixes adjacent to your admin routes for extra flexibility. Prefix routing can be enabled from within the core configuration file by setting the prefixes with Routing.prefixes. […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s