PHP refactoring: function aliases? Need opinions.

Published 4 months ago by godbout

Wondering if there's a way to avoid the duplication of a couple of helper functions I did for my tests:

function birth($action, $arguments)
{
    ...
}

function raw()
{
    return birth(__FUNCTION__, func_get_args());
}

function make()
{
    return birth(__FUNCTION__, func_get_args());
}

function create()
{
    return birth(__FUNCTION__, func_get_args());
}

birth is where everything happens obviously. I'm pretty sure I don't know PHP enough and there's a better way rather than copypasting each function. It doesn't really matter per se, but I'm curious. Any thoughts?

Dry7
Dry7
4 months ago (151,680 XP)

@godbout http://php.net/manual/en/language.oop5.overloading.php

class YourClass {
public function __call($name, $arguments)
    {
    }
}
godbout

Thanks! Although my functions are not methods, they're purely global functions available just for my tests.

Please sign in or create an account to participate in this conversation.