On Sun, 2015-11-01 at 17:04 +0100, georges wrote: > I recently discovered the "friendship concept" in c++ and i really > love the concept. > And i wonder if the php internals would be interested to implements it > in the next 7.x major version.
Could you provide use cases where this provides a better interface than
other alternatives? I think there are only very few cases ...
In C++ the primary use-case are binary operators which have to be
written as a free function but need access to private elements. i.e.
class Complex {
int _real, _im;
public:
Complex(int r, int i) : _real(r), _im(i) {}
friend Complex operator+(int a, const Complex& b);
};
Complex operator+(int a, const Complex& b) {
return Complex(a + b._real, b._im);
}
Here the operator+(int, const Complex&) can't be part of a class as the
first operand is a built-in while logically it belongs to the class's
interface.
(note: this specific example isn't good as we could provide accessors to
the real and imaginary part of our complex number but there are cases
where this isn't possible/wanted)
We don't have this situation in PHP, though.
johannes
signature.asc
Description: This is a digitally signed message part
