j4mie / paris

A lightweight Active Record implementation for PHP5, built on top of Idiorm.
http://j4mie.github.com/idiormandparis/
996 stars 131 forks source link

self:: vs static:: #86

Closed narnaldo closed 10 years ago

narnaldo commented 10 years ago

very good library! really really good!

but might consider using static:: instead of self::. this will add more power to your classes as it will allow also to override your static methods.

class My_Model extends Model
{
    // this is ok. we can override $_table
    public static $_table = 'my_models';

    public static function factory($class_name, $connection_name = NULL)
    {
        $class_name = "{$some_namespace_or_prefix}_$class_name";
        return parent::factory($class_name);
    }

    // currently not ok. will never be called since we use early static binding ::self
    protected static function _get_table_name($class_name) {
        $specified_table_name = static::_get_static_property($class_name, '_table');
        // manipulate table_name here

        return $specified_table_name;
    }
}

p.s. applies also to idiorm

treffynnon commented 10 years ago

It would be lovely to be able to use static::, but unfortunately both Paris and Idiorm target PHP 5.2 and up. Late static binding was introduced in PHP 5.3.2 so we can't implement it. There are numerous closed tickets on this very topic already.

AgelxNash commented 10 years ago

Look at Granada