[ create a new paste ] login | about

Link: http://codepad.org/kBb8RzNh    [ raw code | output | fork ]

PHP, pasted on Oct 15:
<?php

class Injector {
    public function test() {
        $names = array();

        // the instanceof is clearly superfluous here
        if ($this instanceof Injector) {
            $class = get_class($this);

            do {
                $names[] = $class;
                $class = get_parent_class($class);
            } while ($class !== 'Injector');
        }

        return $names;
    }
}

class User extends Injector {}
class SpecialUser extends User {}

$t = new SpecialUser;
var_dump($t->test());


Output:
1
2
3
4
5
6
array(2) {
  [0]=>
  string(11) "SpecialUser"
  [1]=>
  string(4) "User"
}


Create a new paste based on this one


Comments: