|
Posted by ZeldorBlat on 09/28/27 12:01
On Jan 28, 8:45 pm, Daniel Klein <dani...@featherbrain.net> wrote:
> I've got a class that has a couple of methods that can't be 'private' cos
> they can be called by other classes in the project, but they should not be
> called by user code, so I've had to make them 'public'. In other languages
> these methods would have 'friend' visibility.
>
> I suspect there is no 'friend' access modifier since php has no concept of a
> 'module' or 'assembly' (at least none that I am aware of).
>
> I'm use to coding in dynamic languages where you use the 'honor system'. For
> example, in python you indicate this by placing an underscore character in
> front of the method/function. You also document the method to indicate your
> intentions. So unless there is a similar php convention, I am more than ok
> doing it that way.
>
> So my question is: What is the php way of doing this?
>
> Daniel Klein
None that I'm aware of. If you don't want your user code to call a
method, then don't call that method :)
Besides, I never liked the whole "friend" concept. Objects should be
reusable -- which means that it shouldn't matter who is using them.
If you want to use them from "user code" then go for it. If you want
to use them from other objects then that's fine, too. You give your
methods public visibility and everyone can get to them. If you want
to hide something, make it protected or private.
Why should certain objects be given special access to the internals of
another class while other not-so-special objects don't get any? If
you've designed your classes correctly you shouldn't need friends at
all.
Navigation:
[Reply to this message]
|