<?php

class Groot {
    
    private function __construct() {
        $this->name = "I'm groot!";
    }
    
    public function getName() {
        return $this->name;
    }
    
    public static function create($callback) {
        
        // Cria uma nova instância da classe:
        $new = new self();
        
        // Invoca a função anônima passando a instância como parâmetro:
        $callback($new);
        
    }
    
}


Groot::create(function ($self) {
    echo $self->getName(), PHP_EOL;
});