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! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.