alexweber15 Posted September 27, 2008 Share Posted September 27, 2008 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 https://forums.phpfreaks.com/topic/126097-memory-consumption-pass-variable-by-value-vs-store-as-object-property/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.