Jump to content

memory consumption: pass variable by value vs store as object property


alexweber15

Recommended Posts

one of those situations where I can't decide between 2 similar ways of doing something so just wondering about efficiency and best-practices... thanks!

 

class LoginHelper{
    private $email;
    private $pass;

    function __construct($email, $pass){
        $this->email = $email;
        $this->pass = $pass;
        $this->validate() ? $this->authenticate() : $this->showErr();
    }
    
    private function validate(){
        if(!eregi("pattern here",$this->email){
            return false; // for the sake of simplicity
        }
        return true;
    }

    private function authenticate(){
        $result = new LoginController($this->email, $this->pass);
    }
}

 

this is the way it is right now because i'm considering renaming the functions to something a bit more generic and make them all implement a 'Helper' and 'Controller' interface ('login' is obviously just a small part of the entire thing)

 

another way of doing this would be not storing the values in the class and instead just pass them on to every function ie:

private function validate($email, $pass)

 

is there any particular reason why I should use one or the other approach?

(apart from having less specific function parameters so that I can generalize and make it so that every Helper class has to have a validate() method for example and do some design by contract stuff for the other classes)

 

thanks! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.