Re: Re: Net_FTP design issues

From: Date: Thu, 14 Oct 2004 23:37:56 +0000
Subject: Re: Re: Net_FTP design issues
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33869@lists.php.net to get a copy of this message
On Thu, 14 Oct 2004 11:10:06 -0400, Greg Beaver <cellog@php.net> wrote: > Tobias Schlitt wrote: > > Hi all! > > > > I recently got a new member for maintainance/development of Net_FTP. A > > friend of Helgi (CC'ed) started implementing the FTP functions provided > > by PHP using sockets and we will develop the new backend together. > > > > Now we're hanging at the decision of implementing the new backend in an > > OO or procedural manner. On the one hand I would preffer OO style, since > > all in PEAR is OO. On the other hand, if native FTP is not available one > > can simple include the code (if it's procedural) and will have the > > functions available with the same API. Forethat I'd preffer to have it > > procedural. > > On the other hand, if native ftp is available, one can't include the > code at all. This will make the user's job much more complex. Instead of > > <?php > require_once 'Net/Ftp.php'; > ?> > > we will then have to go > > <?php > if (!function_exists('ftp_whatever')) { > include_once 'Net/Ftp.php'; > } > ?> > > Also, what if you decide you want to add new functionality later? You > can't. Procedural code is completely inappropriate for a package like > Net_FTP. > > > What do you think? > > > > The procedural way would have another difficulty to ship around: Storage > > of the config stuff and Co., which would have been stored in the object > > in an OO way. I would suggest to store all of that in a global array > > (e.g. $_NET_FTP), which should not affect most of the scripts it would > > be used in. > > This also smacks of greater-than-needed complexity in the > implementation. Better is to expect that speed-hungry users will use > the native ftp functions no matter what, and that everyone else will > welcome the abstraction that allows a redistributable application to run > without the ftp extension dependency. > > A good compromise solution is to provide a file that has wrapper > functions to the procedural functions. This will satisfy the users who > want to only use the procedural stuff. > > user file: > <?php > require_once 'Net/Ftp/Proecedural.php'; > ?> > > Procedural.php: > <?php > if (!function_exists('ftp_whatever')) { > include_once 'Net/FTP.php'; > $GLOBALS['_NET_FTP_INSTANCE'] = &new Net_FTP; > function ftp_whatever(blahblah) > { > $GLOBALS['_NET_FTP_INSTANCE']->doWhatever(blahblah); > } > } > ?> > This is the method I wholeheartedly agree with. Any code in PEAR should be OO by default. Having a Procedural wrapper for those who want it is cool, but it should absolutely not be the default way of doing things. PEAR packages provide abstraction and OO interfaces to underlying functionality, not drop-in replacements for missing functionality (PHP_Compat excepted). Actually, if you're looking to give the user replacements for built-ins, I would suggest adding to PHP_Compat (or making something similar) which provides ftp_ functions which then use Net_FTP (the class) for the real functionality, as show above. -- paperCrane --Justin Patrin--

« previous php.pear.dev (#33869) next »