$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>oop - Don't filters violate the a class' local variables visibility rules?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

oop - Don't filters violate the a class' local variables visibility rules?

matteradmin11PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far