purekid / mongodm

MongoDB ORM that includes support for references,embed and multilevel inheritance.
MIT License
200 stars 47 forks source link

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

Open iforp opened 10 years ago

iforp commented 10 years ago

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();
jrschumacher commented 10 years ago

@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.