Leon Matthews wrote: > Hi. > > I'm responsible for writing unit tests for our PHP projects at work. > > I would find C++ style friend classes really useful for getting at another > class's private methods. Since we adopted PHP5 we have been using lots of > private methods to clean our interfaces up. Great news for everyone except > me! > > I'd like to be able to do something like: > > class Coder > { > friend class CoderTest; > > private static function encode() > { > ... > } > } > > class CoderTest > { > $expected = ... > $actual = Coder::encode(...); > if( $expected != $actual ) > ... > }
By definition, if you're accessing it from another class, then perhaps it isn't "private" at all. This can be more easily and intuitively solved by using protected and CoderTest extends Coder, or just making it public and documenting in the code where it should and should not be used. This is one reason that "private" should be used sparingly, and perhaps should be thought of more as "final" than as anything else - once you declare something private, it is inaccessible. Greg -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php