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 default array data if extends [$10 awarded] #537

Closed
mruz opened this issue Sep 14, 2014 · 9 comments
Closed

Can't overwrite the default array data if extends [$10 awarded] #537

mruz opened this issue Sep 14, 2014 · 9 comments
Labels

Comments

@mruz
Copy link
Contributor

mruz commented Sep 14, 2014

I can't set the default array data if extends:

class Test
{

    protected _data = [] { set, get };
}
<?php

class Users extends Test
{

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

array(0) { }

Issue related to #520

@ovr ovr added the bug label Sep 14, 2014
@mruz
Copy link
Contributor Author

mruz commented Nov 6, 2014

@ovr any progress on this issue?

@mruz
Copy link
Contributor Author

mruz commented Dec 12, 2014

Also if Test use eg. Di in the __constructor:

namespace Pro\Di;

use Pro\Di;

class Test
{

    protected _di;

    public function __construct()
    {
            let this->_di = Di::getDefault();
    }
}

I get something like this:

Zephir\CompilerException: Class name: Pro\Users\Di does not exist

It occurs if I set some default attribute as array in the Pro\Users.

@ovr ovr self-assigned this Dec 27, 2014
@phalcon phalcon changed the title Can't overwrite the default array data if extends Can't overwrite the default array data if extends [$10] Apr 22, 2015
@phalcon phalcon added the bounty label Apr 22, 2015
@mruz
Copy link
Contributor Author

mruz commented May 14, 2015

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

It looks like it calls this assign after extends, @ovr could you confirm?

@steffengy
Copy link
Contributor

@mruz Sure it does:
User::construct calls parent::construct (Test::construct),
which it has to ensure that parent properties are set.
(which leads to the behavior you're experiencing)

Can't think of a solution, which wouldn't require refactoring how it currently works.

@mruz
Copy link
Contributor Author

mruz commented May 14, 2015

@steffengy could user construct calls parent construct before user?

Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. If the child does not define a constructor then it may be inherited from the parent class just like a normal class method (if it was not declared as private).

@ovr ovr closed this as completed in 9448a9c Jun 2, 2015
ovr added a commit that referenced this issue Jun 2, 2015
Fix #537: Make sure class properties are initialized in the right order
mruz added a commit to ice/base that referenced this issue Jun 27, 2015
@phalcon phalcon unassigned ovr Aug 24, 2015
@phalcon phalcon changed the title Can't overwrite the default array data if extends [$10] Can't overwrite the default array data if extends [$10 awarded] Feb 9, 2017
@mruz
Copy link
Contributor Author

mruz commented Apr 29, 2020

@sergeyklay @dreamsxin I have a feeling this issue returned. I will check/confirm it later.

@sergeyklay
Copy link
Contributor

Feel free to open a new issue if the problem appears again.

@sergeyklay
Copy link
Contributor

@mruz I found the issue. Working on solution

@sergeyklay sergeyklay reopened this May 8, 2020
@sergeyklay
Copy link
Contributor

Closing this one in favor of #2089

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

4 participants