php 7 - Why php adds null bytes to private and protected property names? -
i new php world , learning php.net. know when casting object array null byte added around private , protected property names when classname or asterisk key (*) prepended private , protected property names in array keys.
but question why php add null bytes what reason ?
can tell in simple , easy words.
examples lot.
thanks
the point of private
/protected
properties you're not supposed access them outside class itself. not security measure or that, it's enforce contracts between different pieces of code. when mark private
/protected
, you're declaring explicitly thing isn't general public consumption , no external code should coupled it.
this reminder , other developers , @ worst give light slap on wrist if disobey marker; it's not ironclad protection means. there number of ways around that, e.g. using reflection. but, if made too easy access private parts, developers doing left , right , negate entire point.
since properties included in array when casting object array, @ least it's not obvious how access them directly due added nul
bytes. if take time figure out how access them, know you're doing.
tl;dr: (i believe) it's minimum attempt try enforce minimal coding standards , not let newbies violate oop principles once figure out array cast is.
Comments
Post a Comment