Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active December 30, 2015 21:25
Show Gist options
  • Select an option

  • Save gabrieljmj/686f41aeaf99516d3b83 to your computer and use it in GitHub Desktop.

Select an option

Save gabrieljmj/686f41aeaf99516d3b83 to your computer and use it in GitHub Desktop.

Revisions

  1. gabrieljmj revised this gist Dec 30, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions oo.php
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,4 @@ private function getName($name)
    }
    }

    $php = new PhpOo;
    echo $php->callUserFuncArray('strlen', ['Hello']);
    echo (new PhpOo)->callUserFuncArray('strlen', ['Hello']);
  2. gabrieljmj revised this gist Dec 30, 2015. No changes.
  3. gabrieljmj renamed this gist Dec 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vanilla.php → oo.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php

    class PhpVanilla
    class PhpOo
    {
    public function __call($name, array $args)
    {
    @@ -20,5 +20,5 @@ private function getName($name)
    }
    }

    $php = new PhpVanilla;
    $php = new PhpOo;
    echo $php->callUserFuncArray('strlen', ['Hello']);
  4. gabrieljmj revised this gist Dec 30, 2015. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions vanilla.php
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,21 @@ class PhpVanilla
    {
    public function __call($name, array $args)
    {
    return call_user_func_array($name, $args);
    $cUFA = $this->getName('callUserFuncArray');
    return $cUFA($this->getName($name), $args);
    }

    private function getName($name)
    {
    foreach (str_split($name) as $l) {
    if (ctype_upper($l)) {
    $name = str_replace($l, '_' . strtolower($l), $name);
    }
    }

    return $name;
    }
    }

    $php = new PhpVanilla;
    echo $php->strlen('Hello');
    echo $php->callUserFuncArray('strlen', ['Hello']);
  5. gabrieljmj created this gist Dec 30, 2015.
    12 changes: 12 additions & 0 deletions vanilla.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?php

    class PhpVanilla
    {
    public function __call($name, array $args)
    {
    return call_user_func_array($name, $args);
    }
    }

    $php = new PhpVanilla;
    echo $php->strlen('Hello');