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

Problem with private properties in sub-classes #5

Closed
aurora opened this issue Oct 18, 2013 · 2 comments
Closed

Problem with private properties in sub-classes #5

aurora opened this issue Oct 18, 2013 · 2 comments

Comments

@aurora
Copy link
Contributor

aurora commented Oct 18, 2013

I am sometimes extending the Lua class to provide additional functionality. One problem i have is, that "private" properties of the sub-class are treated like properties of the Lua class which leads to the problem, that the values stored in them get lost. The following code for example prints "NULL":

class a extends Lua {
}

class b extends a {
    private $val = 'lua';

    public function test() {
        var_dump($this->val);
    }
}

$b = new b();
$b->test();

I understand, that this happens to "protected" and "public" properties of class b, but shouldn't be the "private" properties treated different?

@hjanuschka
Copy link
Contributor

as the lua class is now final.

lua_ce->ce_flags |= ZEND_ACC_FINAL;

extending the Lua class is not possible anymore.
your sample now ends with

Fatal error: Class a may not inherit from final class (Lua) in /home/admin/tmp/php-lua/1.php on line 3

i think thats fine - and there are otherways to achive a construct you want, and this issue could be closed

@aurora
Copy link
Contributor Author

aurora commented Feb 3, 2015

Ok ... still think that extending native classes is a valid use case, but yep, i am using a different architecture for this anyway. So ... i am closing.

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

No branches or pull requests

2 participants