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

I would like to get a Singleton instance always. #28

Open
shafihuzaib opened this issue Jan 27, 2016 · 1 comment
Open

I would like to get a Singleton instance always. #28

shafihuzaib opened this issue Jan 27, 2016 · 1 comment

Comments

@shafihuzaib
Copy link

I want to get a singleton instance, that is; I instantiate the Blade Class once (automatically) and then use a static function like Blade::instance() to get the object instantiated already. In this way, I won't have to worry about new Objects being made everytime.

F3 uses the following function to get the desired effect. Can I somehow manage to do the same here?

static function instance() {
if (!Registry::exists($class=get_called_class())) {
$ref=new Reflectionclass($class);
$args=func_get_args();
Registry::set($class,
$args?$ref->newinstanceargs($args):new $class);
}
return Registry::get($class);
}

@chrisharrison
Copy link

Why don't you just use a container and inject it, if you don't want to "worry about new objects being made every time"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants