Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created December 6, 2016 12:18
Show Gist options
  • Select an option

  • Save SebDeclercq/7dac64cff82e5ea9294347757632c7d2 to your computer and use it in GitHub Desktop.

Select an option

Save SebDeclercq/7dac64cff82e5ea9294347757632c7d2 to your computer and use it in GitHub Desktop.
<?php
abstract class ModifiableAtRuntime
{
protected $methodes;
public function ajouteMethode($nom, Closure $closure) {
$this->methodes[$nom] = $closure->bindTo($this, __CLASS__);
}
public function __call($methode, $args) {
if (is_callable($this->methodes[$methode])) {
return call_user_func_array($this->methodes[$methode], $args);
}
}
public function __invoke($nom, $closure) {
$this->ajouteMethode($nom, $closure);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment