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

[BUG] Extended classes can't access their private variables #1851

Closed
zsilbi opened this issue Apr 25, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@zsilbi
Copy link

commented Apr 25, 2019

Hey,

If a class - written in Zephir - contains private variables and extended in PHP, it won't be able to access those variables in its original methods.

I ran into this when I was trying to extend \Phalcon\Session\Manager and \Phalcon\Session\Bag in v4.0.0-alpha.4

Code to reproduce the issue:

/** Example.zep **/

class Example
{
    private privateVariable;

    public function setPrivateVariable(value)
    {
        let this->privateVariable = value;

        return this;
    }

    public function getPrivateVariable()
    {
        return this->privateVariable;
    }
}

In PHP it is extended without any new methods:

/** My/Example.php **/

namespace My;

class Example extends \Example {}

Test code:

$example = new \My\Example;
$example->setPrivateVariable('test');

var_dump($example->getPrivateVariable());

Result:

Notice: Undefined property: My\Example::$privateVariable

Changing private variables to protected solved the errors.

Zephir version: 0.11.12
PHP: 7.3.4 or 7.2.16 (tried both)

Thanks

@sergeyklay

This comment has been minimized.

Copy link
Member

commented Apr 25, 2019

Thank you for the report. We'll try to sort out ASAP.

@Jurigag Jurigag added the bug label Apr 30, 2019

@dreamsxin dreamsxin closed this in df9c16e May 16, 2019

@dreamsxin dreamsxin referenced this issue May 16, 2019

Merged

Fix #1851 #1862

2 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.