dink

Hola dudettes.  Anno nuevo fleecydadamente!

I have this class (webRequest2) that doesn't have exactly what I need for a particular task.

I have a few functions that I would like to run when I get the results from a webRequest.
I can think of three ways to accomplish same.  1.  Write a new class and set it to extend
webRequest, or 2.  Write a new class and just require both classes at run time, or 3.  Put
the new functions in the original class and rename it webRequest2_ds.

The advantage I see with option 1 is that the new functions would inherit all of the goodies
available in webRequest.

Which of the above (or are there better alternatives) would fit the 'best practice' guidelines?
Are there any hidden gotchas for any of the choices? 

OOOOOP is way far down on my list of 'things I know', plus I'm making the transition from

php

 1.0
to

php

 5.2.2 (some fun too!), so any guidance would be greatly appreciated.

el Dinko

perkiset

It was built to extend. Option 1 is the most correct way, although option 2 is certainly a possibility, it is not to my taste.

Option 3 is a nono. The idea is to make it so that your functionality is not broken or erased if I update the class and you want my updates. See, if you mod the class then I do, you'll undo your mods by taking mine on. If your class extends mine, and provided I've done my work correctly, then you just copy the new code into your class file and the new code will be available to your inherited class without muss or fuss.

Another thought is that there are event pops in the class - onSuccess for example.

Consider this:

<?

php

 
$req = new webRequest2();
$req->onSuccess = 'handleSuccess';
$req->simpleGet('http://www.perkiset.org');

function handleSuccess($sender)
{
// Do some code because the request succeeded...
}
?>


In this example, I've added an event handler for the onSuccess event that is fired after a URL has been successfully pulled down. There is an onFailure as well.

(I noticed that there was a bug in all of this while I was writing this post, so I updated the code in the webRequest thread... - you'll want to go get it... please give'r a shot and let me know if it burps on you at all... looks good from my end)

This is another technique for when you have code you want executed that is really specific to <this> application and you'll never need to use it again... so there is no need to extend the class.

Ping back if you need more,
/p

dink

Cool.  Thanks Perk.  Option 1 it is.

The event pop sounds like some serious fun too.  That would fit with some of my other plans. 


Perkiset's Place Home   Politics @ Perkiset's