Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting function call to within a class

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
Is there any way to restrict a function so that it can only be called from the class that it is declared in? This might not be very well explained so I will give an example...

Code:
class example {

  function a () {
    echo 'a!';
  }

  function b () {
    echo 'b!';
    $this->a();
  }

}

So you can do...
$example = new example;
$example->a();
$example->b();

and both would work fine. But if I wanted function a to only be called from within function b - would that be possible?


-Geeeeeeeeeeeeeeeeeeeeeeee-
 
Maybe. If you are running PHP v. 5, you could declare the method private.

With PHP v. 4, there is no such mechanism built in.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top