Skip to content

Instantly share code, notes, and snippets.

@erikfig
Created August 12, 2020 20:57
Show Gist options
  • Save erikfig/0a3030f7568084723a7d15d4e1e73f2d to your computer and use it in GitHub Desktop.
Save erikfig/0a3030f7568084723a7d15d4e1e73f2d to your computer and use it in GitHub Desktop.

Revisions

  1. erikfig created this gist Aug 12, 2020.
    45 changes: 45 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    <?php

    class Model {
    public static function find($name)
    {
    return 'Model::find::' . $name;
    }

    public function save()
    {
    return 'Model';
    }
    }

    class Repository {
    public static function __callStatic($name, $arguments)
    {
    return call_user_func_array([new Model, $name], $arguments);
    }

    public function __call($name, $arguments)
    {
    return call_user_func_array([new Model, $name], $arguments);
    }

    public function __set($name, $value)
    {
    $this->$name = $value;
    }

    public function __get($name)
    {
    return 'Erik';
    }
    }

    echo Repository::save();
    echo PHP_EOL;
    echo (new Repository)->find('Thalisson');

    $repo = new Repository;
    $repo->name = 'Thalisson';
    echo PHP_EOL;

    echo $repo->melhorDevDaWebjump;