RuleBritannia Posted December 18, 2013 Share Posted December 18, 2013 I'm curios to know if the OOP approach would suit this problem over procedural.(from your perspective) I am using curl, to fetch and post information. I believe its best broken down into stages login, fetch, post. Before we can fetch or post, login must be done. To improve efficiency, once login is done once and confirmed, if we are fetching or posting any other times(loops, later etc), we don't have to keep logging in(use of constructor applies here) For curl efficiency, Also put curl_init inside constructor? and put curl close inside destructor? Another note here, Im not sure if reusing one handle is buggy?, But it seems logical to do it this way(however google shows otherwise) In the past I have achieved the same final result(without being efficient, also requires more code lines.) wasteful example upload function make handle (ch) login. (perform post) upload (perform post) close handle fetch function make handle (ch) login. (perform post) upload (perform post) close handle whenever its needed, just bang it in a loop and it will work. Sorry if this question seems overdumb, But Ive never done anything too complex to warrant OOP, So it never seemed logical for me to switch over. Maybe even what im trying here doesn't need OOP? But im hitting problems with procedural... Would be interesting to see your views, also any improvements. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/284832-first-real-problem-forcing-me-to-go-oop/ Share on other sites More sharing options...
ignace Posted December 18, 2013 Share Posted December 18, 2013 OOP is more then simply introducing one class into your project. Or a few classes for that matter. So if you want to use a class for it or go with a function, the choice is ultimately yours. You can avoid having to create the handle over and over by passing the handle to the functions that require them: function login($ch, $other, $parameters) { // code }Personally I would prefer a class to signify the cohesion between the functions and not having to pass the same data around between functions, in a class they would simply share the information. But don't take my word for it though, because I am biased. Quote Link to comment https://forums.phpfreaks.com/topic/284832-first-real-problem-forcing-me-to-go-oop/#findComment-1462645 Share on other sites More sharing options...
RuleBritannia Posted December 18, 2013 Author Share Posted December 18, 2013 OOP is more then simply introducing one class into your project. Or a few classes for that matter. So if you want to use a class for it or go with a function, the choice is ultimately yours. You can avoid having to create the handle over and over by passing the handle to the functions that require them: Yes, But this situation seemed to be best approached in a OOP, In regards to passing the handle, I have around 4 different logins(for 4 different sites), So im not sure if passing the same handle to each of them is a good idea, I thought putting each handle inside a construct before each login process. Personally I would prefer a class to signify the cohesion between the functions and not having to pass the same data around between functions, in a class they would simply share the information. But don't take my word for it though, because I am biased. Yes the sharing is where I began to see the better view of OOP. Thanks for your view! Quote Link to comment https://forums.phpfreaks.com/topic/284832-first-real-problem-forcing-me-to-go-oop/#findComment-1462663 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.