laruence / php-lua

This extension embeds the lua interpreter and offers an OO-API to lua variables and functions.
http://pecl.php.net/package/lua
Other
149 stars 50 forks source link

Problem with private properties in sub-classes #5

Closed aurora closed 9 years ago

aurora commented 11 years ago

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 commented 9 years ago

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 commented 9 years ago

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.