If someone writes code so that an internal variable $_fields is accessible without using getter/setter methods, is there a proper term used to describe that?
Something polite enough to use with management :)
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
Besides the lack of encapsulation already mentioned by Oded, depending on the programming language and its paradigms it could also be "plain old data" (where it isn't necessarily an antipattern or code smell).
It's called "not following a specific coding standard".
The OP wrote:
an internal variable $_fields is accessible without using getter/setter methods
That might be against your standard, and (thus) it might be code smell. But it is not necessarily poor encapsulation. Exposing an internal (as in "only of internal use") variable over getter and setters to the outside world would be even worse.
The question is: should
$_fields be accessible for the outside world?
If so, we have a case where you would add getter/setter methods. These methods do not encapsulate anything but the fact that
$_fields is a variable of some kind (as opposed to something calculated/fetched/etc. on the fly). Depending on the language, you'll probably still leak the type (aka an implementation detail) to the outside. Whether you always want getters/setters, or only when "needed" is a coding standard issue.
$_fields should not be accessible, then, well, don't access it. Whether you should keep others from accessing it on the language level (private and friends) or not (which might ease debugging in certain circumstances) is - again - a coding standard issue.
The issue of encapsulation is entirely orthogonal to this. Violating encapsulation is absolutely possible with getters and setters. It's even easier to slip into, because most people's alarm bells don't ring when they see a bunch of getters and setters - code that's seemingly following best practices. Code, that might very well introduce much more dependencies on internal implementation details than a variable called
$_fields that happens not to be specified as
I'm a fan of bad analogies: Calling that poor encapsulation is like calling someone who holds a gun a murderer.