admin管理员组文章数量:1130349
Pressume I have a class:
class TestClass
{
protected $handle;
}
and in that class, I decide that my $handle will be set by a filter, in the constructor:
class TestClass
{
private $handle
public function __construct()
{
$this->handle = apply_filters( 'handle_filter', '' );
}
}
Have I not just violated / nullified the private statement that should dictate that, under no circumstance $handle should change, no matter what inheritance is done. But, due to it being a filter, it can change from anywhere so integrity is not assured.
In other words, private ensures integrity throughout the lifecycle of a class, whether it inherits or it's inherited, protected would allow for extension only by classes that work with my class.
It's really a contradiction and the private statement is useless then or am I missing something?
The other end of the stick is "this variable can change in many ways up until it reaches my class, once it reaches my class, it cannot change anymore and it will remain so unless the parent class decides it wants to change it", so, this could be a non-issue.
If this is true, then filters are violators of visibility until they're not, kind of like when kids do what they want but once the parents arrived home, they're silent?
Pressume I have a class:
class TestClass
{
protected $handle;
}
and in that class, I decide that my $handle will be set by a filter, in the constructor:
class TestClass
{
private $handle
public function __construct()
{
$this->handle = apply_filters( 'handle_filter', '' );
}
}
Have I not just violated / nullified the private statement that should dictate that, under no circumstance $handle should change, no matter what inheritance is done. But, due to it being a filter, it can change from anywhere so integrity is not assured.
In other words, private ensures integrity throughout the lifecycle of a class, whether it inherits or it's inherited, protected would allow for extension only by classes that work with my class.
It's really a contradiction and the private statement is useless then or am I missing something?
The other end of the stick is "this variable can change in many ways up until it reaches my class, once it reaches my class, it cannot change anymore and it will remain so unless the parent class decides it wants to change it", so, this could be a non-issue.
If this is true, then filters are violators of visibility until they're not, kind of like when kids do what they want but once the parents arrived home, they're silent?
本文标签: oopDon39t filters violate the a class39 local variables visibility rules
版权声明:本文标题:oop - Don't filters violate the a class' local variables visibility rules? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749040075a2306994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论