Find a better logic to remove duplicated code from two different methods I have to update a class property with the method name and then call a method that executes some code based on this property. The code is the same in both methods, but I am not seeing a way to remove this code duplication. I am trying to avoid using a parameter.

public function register(){
    $this-&gt;operation = __FUNCTION__;
    $this-&gt;handleOperation();
}

public function unregister(){
    $this-&gt;operation = __FUNCTION__;
    $this-&gt;handleOperation();
}


Update 1

As Yoda suggested, here is a more complete code. It is a class to manipulate multiple functions for PHP autoloading. Now I am using parameters in handleOperation(). Example of use:

$Autoloader = new Autoloader();
$Autoloader-&gt;setFunctions(array('controllers', 'commons'));
$Autoloader-&gt;setModule('default');
$Autoloader-&gt;register();


Class code:

class Autoloader {

    private $functions_to_handle = array();
    private $module;
    private $function;
    private $paths = array();

    public function setFunctions($functions){
        $this-&gt;functions_to_handle = is_array($functions) ? $functions : array($functions);
    }

    public function setModule($module){
        $this-&gt;module = $module;
    }

    public function register(){
        $this-&gt;handleOperation(__FUNCTION__);
    }

    public function unregister(){
        $this-&gt;handleOperation(__FUNCTION__);
    }

    private function handleOperation($operation){
        $built_in_function = $this-&gt;mountBuiltInFunctionName($operation);

        foreach($this-&gt;functions_to_handle as $function){
            $built_in_function(array($this, $function));
        }
    }

    private function mountBuiltInFunctionName($operation){
        return 'spl_autoload_' . $operation;
    }

    private function controllers($classe) {
        $this-&gt;function = __FUNCTION__;

        $this-&gt;refreshPaths($classe);
        $this-&gt;loadClass();
    }

    private function commons($classe) {
        $this-&gt;function = __FUNCTION__;

        $this-&gt;refreshPaths($classe);
        $this-&gt;loadClass();
    }

    private function refreshPaths($classe){
        switch ($this-&gt;function) {

            case 'commons' :
                $this-&gt;paths = array(
                    '/usr/share/evokernel/core/common/' . $classe . '.php',
                );
            break;

            case 'controllers':
                $this-&gt;paths = array(
                    'core/controllers/' . $classe . '.php',
                    'modules/' . $this-&gt;module . '/controllers/' . $classe . '.php',
                    'shared/modules/' . $this-&gt;module . '/controllers/' . $classe . '.php'
                );
            break;

            default:
                throw new Exception('Invalid function: ' . $this-&gt;function);
        }
    }

    private function loadClass(){
        foreach ($this-&gt;paths as $path) {
            if (is_file($path)) {
                require_once($path);
                break;
            }
        }
    }
}
Short version: Use a parameter!

public function handleOperation($action) {}
public function register() { $this-&gt;handleOperation("register"); }
public function unregister() { $this-&gt;handleOperation("unregister"); }




Slightly longer version: Don't be a smartass

You don't need to dynamically call spl_autoload_$function, it's pointless and unreadable. Just call spl_autoload_registerand spl_autoload_unregisterwhen you need it. It's unlikely for the function names to change.