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

Suggesting for the Template Class #1088

Closed
isholao opened this issue Jan 20, 2018 · 2 comments
Closed

Suggesting for the Template Class #1088

isholao opened this issue Jan 20, 2018 · 2 comments

Comments

@isholao
Copy link

isholao commented Jan 20, 2018

how about a slight improvement to the Template Class

current code ...

function __construct()
 {
        $ref = new ReflectionClass(__CLASS__);
       ...
    }

how about this instead ...

    function __construct()
    {
        $ref = new ReflectionClass(\get_called_class());
       .....
    }

This allows this to happend

class MyTemplate extends Template{
   function  __construct() { parent::__construct(); }

  protected function _begin($node){ .... }
  protected function _end($node){ .... }
  public function getTags(){ return $this->tags;}
}

var_dump(MyTemplate::instance()->getTags());

//result

string(85) "begin|end|set|include|exclude|ignore|loop|repeat|check|true|false|switch|case|default"

and without the change from 'CLASS' to 'get_called_class()'

string(75) "set|include|exclude|ignore|loop|repeat|check|true|false|switch|case|default"
@isholao isholao closed this as completed Jan 20, 2018
@isholao isholao reopened this Jan 20, 2018
@Ayesh
Copy link

Ayesh commented Jan 21, 2018

Template class is meant to be extended, so I think this makes sense.

Instead of get_called_class, you can use static::class as well. This will return same result (https://3v4l.org/4UKd4) for one less function call.

ikkez added a commit to f3-factory/fatfree-core that referenced this issue Mar 15, 2018
@ikkez ikkez reopened this Mar 15, 2018
@ikkez
Copy link
Collaborator

ikkez commented Mar 15, 2018

Cannot do it right now with static::class, because it would raise the minimum required PHP version to 5.5. We're currently on 5.4+ but I'll keep an eye on this one for later.

ikkez added a commit to f3-factory/fatfree-core that referenced this issue Mar 15, 2018
@ikkez ikkez closed this as completed Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants