You are viewing documentation for an outdated version. It is no longer supported!

Method Helper

The MethodHelper offers various function and method utilities.

makeGetterName()

Returns a 'getter' method name for given property

use Aedart\Utils\Helpers\MethodHelper;

$method = MethodHelper::makeGetterName('age');

echo $method; // getAge

makeSetterName()

Returns a 'setter' method name for given property

use Aedart\Utils\Helpers\MethodHelper;

$method = MethodHelper::makeSetterName('age');

echo $method; // setAge

callOrReturn()

Invokes the given method and return it's return value, if possible. Otherwise, the whatever value was given will be returned instead.

This helper is useful when not knowing if a callable has already been invoked.

use Aedart\Utils\Helpers\MethodHelper;

$callable = function(){
    return 'Hi there';
};

$output = MethodHelper::callOrReturn($callable);

echo $output; // Hi there

When method is not a callable

If given method is not a callableopen in new window, then whatever was given will be returned instead.

use Aedart\Utils\Helpers\MethodHelper;

$callable = 'Okay there...';

$output = MethodHelper::callOrReturn($callable);

echo $output; // Okay there...

Passing Arguments

You can state arguments to passed to the callable method, as the second argument.

use Aedart\Utils\Helpers\MethodHelper;

$callable = function(string $name){
    return 'Hi ' . $name;
};

$output = MethodHelper::callOrReturn($callable, [ 'Ryan' ]);

echo $output; // Hi Ryan