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
Closed

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

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

Comments

@zsilbi
Copy link

zsilbi 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
Copy link
Contributor

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

@Jurigag Jurigag added the bug label Apr 30, 2019
@dreamsxin dreamsxin mentioned this issue May 16, 2019
3 tasks
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
* Fix zephir-lang#1851

* Generate c code

* Updated

* Update FcallTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants