Does php support friend function like as c++ supports?
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.
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.
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.
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.
You are most likely referring to class/variable scope. In php, you have:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With