Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protected function can still be called outside the class #16332

Open
vher2 opened this issue May 29, 2018 · 2 comments
Open

protected function can still be called outside the class #16332

vher2 opened this issue May 29, 2018 · 2 comments
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@vher2
Copy link

vher2 commented May 29, 2018

What steps will reproduce the problem?

Declare a class then extends BaseObject

class Sample extends \yii\base\BaseObject {
    private $_mode = 'mode';
  
    protected function getMode()
    {
        return $this->_mode;
    }
}

Now create new instance

$sample = new Sample();
echo $sample->mode;

// output:
// mode

Though you can't call the getMode() method directly but still I think this is an issue.

I think this is because how the __get($name) magic function works. When it checks if a method exists or not, it will return true because it has access to that method.

Additional info

Q A
Yii version 2.0.15.1
PHP version 5.6
@dmirogin
Copy link
Contributor

I think it is BC. Some apps can use this by accident, for example.

@samdark
Copy link
Member

samdark commented Jun 17, 2018

Well, that is really a bug. If someone uses such behavior it's totally incorrect.

@samdark samdark removed this from the 2.0.17 milestone Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants