Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

friend function in php?

Tags:

php

Does php support friend function like as c++ supports?

like image 625
Tejas Patel Avatar asked Sep 14 '10 09:09

Tejas Patel


People also ask

What is the function of friends?

Friends can help you celebrate good times and provide support during bad times. Friends prevent isolation and loneliness and give you a chance to offer needed companionship, too. Friends can also: Increase your sense of belonging and purpose.

What is the benefit of using friend function?

Advantages of Friend Function in C++It allows the sharing of private class information by a non-member function. It accesses the non-public members of a class easily. It is widely used in cases when two or more classes contain the interrelated members relative to other parts of the program.

What is friend function syntax?

Syntax of friend functions: class className{ // Other Declarations friend returnType functionName(arg list); }; As we can see above, the friend function should be declared inside the class whose private and protected members are to be accessed.

What is friend function and its properties?

Characteristics of a Friend function: It cannot be called using the object as it is not in the scope of that class. It can be invoked like a normal function without using the object. It cannot access the member names directly and has to use an object name and dot membership operator with the member name.


1 Answers

You are most likely referring to class/variable scope. In php, you have:

  • public
  • private
  • protected

But not friend visibility. The protected though is used when an object's members are to be made visible only to other extending/inheriting objects.

More Info:

  • http://php.net/manual/en/language.oop5.visibility.php
like image 170
Sarfraz Avatar answered Oct 10 '22 06:10

Sarfraz