Skip to content

Instantly share code, notes, and snippets.

@salathe
Created August 18, 2011 08:42
Show Gist options
  • Select an option

  • Save salathe/1153670 to your computer and use it in GitHub Desktop.

Select an option

Save salathe/1153670 to your computer and use it in GitHub Desktop.
string(7) "Example"
object(Example)#1 (0) {
}
Fatal error: Call to private Example::__construct() from invalid context in <file> on line 18
<?php
trait Singleton
{
private function __construct() {
var_dump(get_called_class());
}
public static function getInstance() {
return new static;
}
}
class Example {
use Singleton;
}
var_dump(Example::getInstance());
var_dump(new Example);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment