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