Re: Net_FTP design issues

From: Date: Thu, 14 Oct 2004 15:10:06 +0000
Subject: Re: Net_FTP design issues
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33847@lists.php.net to get a copy of this message
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);
} } ?> Greg

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