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

Can't overwrite the class property if default is array #520

Closed
mruz opened this issue Sep 10, 2014 · 5 comments
Closed

Can't overwrite the class property if default is array #520

mruz opened this issue Sep 10, 2014 · 5 comments
Labels

Comments

@mruz
Copy link
Contributor

mruz commented Sep 10, 2014

class Test
{

    protected _data = ["key": "value"] { set, get };

    public function __construct()
    {
        let this->_data = [1, 2, 3];
        //this->setData([1, 2, 3]); // also not work
    }
}
$test = new Test();
var_dump($test->getData());

array(1) { ["key"]=> string(5) "value" }

Works fine if the data is without default array:

protected _data { set, get };
@ovr ovr added the bug label Sep 10, 2014
ovr added a commit to ovr/zephir that referenced this issue Sep 10, 2014
@ovr
Copy link
Contributor

ovr commented Sep 10, 2014

This bug is caused because PHP is not support default array value for properties
And we assign default array value in __constructor

I added fix bug soon we need to added optimizer for it

@ovr ovr closed this as completed in f53b4e2 Sep 14, 2014
phalcon pushed a commit that referenced this issue Sep 14, 2014
@mruz
Copy link
Contributor Author

mruz commented Sep 14, 2014

Thanks @ovr

@ovr
Copy link
Contributor

ovr commented Sep 14, 2014

Not a problem, Happy coding with Zephir 😸

@mruz
Copy link
Contributor Author

mruz commented Sep 14, 2014

One more small related issue :) I can't set the default data if extends:

<?php

class Users extends Test
{

    protected $_data = [
        'id', 
        'username', 
        'password', 
    ];
}
$user = new Users();
var_dump($user->getData())

I'm trying without constructor now:

class Test
{

    protected _data = ["key": "value"] { set, get };
}

@ovr
Copy link
Contributor

ovr commented Sep 14, 2014

Open new issue please, I will try to fix it as soon as I can

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

2 participants