Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm using a new way to using my classes that don't really need to be constructed, but I'm not sure wether this is a good way to do it or wether I should just construct the class.

The way I'm using the class now is:

$content->setContent(Register::render());

The class looks like this:

class Register
{
    public function render()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST')
        {
            return Register::register();
        }

        return Register::registerForm();
    }
    private function register()
    {

    }
    private function registerForm()
    {
        $registerForm = '';

        return $registerForm;
    }
}

Thanks in advance, Jelle Peters.

share|improve this question
Checking the request type inside of a class that's not modeling a request concerns me. That logic should probably be handled elsewhere. (Also, it's a much safer path to have something non-static and realize it could have been, than have something static and be stuck wishing it never had been -- not to say that static methods should never be used, though.) – Corbin Oct 3 '12 at 15:04

1 Answer

up vote 3 down vote accepted

What you are basically doing is creating a utility class with "static" function which is a good way to go if they class doesn't contain data member which should be unique for every instance of the class.

It's a good way to encapsulate logic for a specific purpose.

share|improve this answer
There will only be one instance of the class at the time. The class does have internal variables though, but I don't think this will be a problem – Jelle Peters Oct 3 '12 at 9:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.