| 1 | <?php |
||
| 8 | class ReflectionParameter extends \ReflectionParameter |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Parameter function. |
||
| 13 | * |
||
| 14 | * @var mixed |
||
| 15 | */ |
||
| 16 | private $function; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Constructor. |
||
| 20 | * |
||
| 21 | * @param string $function The function to reflect parameters from. It can be also be in the format: array('className', 'methodName'). |
||
| 22 | * @param string $parameter The parameter name. |
||
| 23 | */ |
||
| 24 | 18 | public function __construct($function, $parameter) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Gets a class. |
||
| 32 | * |
||
| 33 | * @return \Wingu\OctopusCore\Reflection\ReflectionClass |
||
| 34 | */ |
||
| 35 | 3 | public function getClass() |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Gets the declaring class. |
||
| 47 | * |
||
| 48 | * @return \Wingu\OctopusCore\Reflection\ReflectionClass |
||
| 49 | */ |
||
| 50 | 6 | public function getDeclaringClass() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Gets the declaring function. |
||
| 62 | * |
||
| 63 | * @return \Wingu\OctopusCore\Reflection\ReflectionMethod|\Wingu\OctopusCore\Reflection\ReflectionFunction |
||
| 64 | */ |
||
| 65 | 3 | public function getDeclaringFunction() |
|
| 73 | } |
||
| 74 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.