patrick24601 Posted May 20, 2008 Share Posted May 20, 2008 If I want to pass data to a class method I can do it one of two ways: $result = $cls1->updateit($id, $name,$address); or $cls1->id = 100; $cls1->name = "me"; $cls1->address = "mine"; $result = $cls1->updateit(); Which is preferred and why? Thanks, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/106468-using-properties-or-parms/ Share on other sites More sharing options...
rhodesa Posted May 20, 2008 Share Posted May 20, 2008 I prefer the first method. That way you can do error checking on the values (like making sure ID is a valid number) before actually modifying the properties of the object. Quote Link to comment https://forums.phpfreaks.com/topic/106468-using-properties-or-parms/#findComment-545725 Share on other sites More sharing options...
patrick24601 Posted May 20, 2008 Author Share Posted May 20, 2008 Can't you validate using either one? I don't see how come with the 2nd one you would not be able to. Thanks, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/106468-using-properties-or-parms/#findComment-545737 Share on other sites More sharing options...
rhodesa Posted May 20, 2008 Share Posted May 20, 2008 I guess...but what if it doesn't validate? The old value is gone and can't be brought back. ...the first option is also less code furthermore...i rarely ever have public properties inside my classes. all access to the data (read and write) goes through a function. that way, later on, if I want to change how it is read/written (maybe use title instead of name), i just modify the class instead of all the code using it Quote Link to comment https://forums.phpfreaks.com/topic/106468-using-properties-or-parms/#findComment-545754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.