Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/284832-first-real-problem-forcing-me-to-go-oop/
Share on other sites

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.

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!

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.