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

Add Late Static Binding and fix some methods call (i.e. static instead of self) #77

Open
iforp opened this issue Oct 9, 2014 · 1 comment
Labels

Comments

@iforp
Copy link

iforp commented Oct 9, 2014

There are a lot of calling like self::connection() in \Purekid\Mongodm\Model.
Why don't you use static::connection()?

Because of this issue I can't override some methods in my subclass.

For example:

class BaseModel extends \Purekid\Mongodm\Model
{
    // override \Purekid\Mongodm\Model::connection()
    protected static function connection()
    {
        die(__METHOD__);
    }
}

class Posts extends BaseModel
{
    // ...
}

Posts::one();

in this simple example method BaseModel::connection() will never be executed.

Moreover you use a lot of constructions like

$class = get_called_class();
$class::$config;
$class::getAttrs();

instead you should use

static::$config;
static::getAttrs();
@iforp iforp changed the title Wrong methods call (i.e. self instead of $this) Add some Late Static Binding and fix some methods call (i.e. static instead of self) Oct 9, 2014
@iforp iforp changed the title Add some Late Static Binding and fix some methods call (i.e. static instead of self) Add Late Static Binding and fix some methods call (i.e. static instead of self) Oct 9, 2014
@jrschumacher
Copy link
Collaborator

@Agent-J please feel free to try this out and run the unit tests to make sure everything works fine and submit a PR.

That said I know that there are issues with using static in PHP v5.3.

With regard to calling $class::... When the method is run it is called from the inherited abstract class but the attributes belong to the child class. This allows access to the child's scope where other options will keep the scope relative to the abstract class. If this has been fixed in later versions we can add that as a conditional.

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