Bug #19752 [Ana]: connect() returns false even if it successfully connects

From: Date: Sun, 16 Dec 2012 21:50:26 +0000
Subject: Bug #19752 [Ana]: connect() returns false even if it successfully connects
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-9419@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19752&edit=1 ID: 19752 Updated by: heino.gehlsen+php@gmail.com Reported By: lead2gold at gmail dot com Summary: connect() returns false even if it successfully connects Status: Analyzed Type: Bug Package: Net_NNTP Operating System: Centos 5.8 Package Version: 1.5.0RC2 PHP Version: 5.3.19 Roadmap Versions: New Comment: http://svn.php.net/viewvc/pear/packages/Net_NNTP/trunk/docs/examples/phpdoc/con nect.php?revision=202843&view=markup Previous Comments: ------------------------------------------------------------------------ [2012-12-16 21:48:36] heino -Status: Open +Status: Analyzed I agree it seems strange, but it does make sense however... As all protocol related methods connect() returns/'throws' an PEAR_Error object on failure, and one are supposed to check if such an object is returned before one continues. It's good old style PEAR - from before exceptions was accepted. I agree that the posting prohibited status could have been handled differently, but it was meant as a quick way of testing when connecting to post an article. At protocol level there should only be returned either posting allowed or prohibited on a successful connection attempt, and returning the state as boolean seemed natural - since a failure would return an PEAR_Error object. The addition af a returned false was added a long time ago (http://svn.php.net/viewvc/pear/packages/Net_NNTP/trunk/NNTP/Protocol/Client.php? r1=202233&r2=202234&), and changing it now would violate backward compatibility, so that's not an option. Regarding the proposed $_canPost variable, this might have been exactly what I had in mind back when I made the 'to do' comment ;-). There should however also be something like a isPostingAllowed() method or something... ------------------------------------------------------------------------ [2012-12-16 20:46:54] caronc Added #patch bug:19752;patch:canpostflag.patch;revision:1355690814;. ------------------------------------------------------------------------ [2012-12-16 20:43:16] caronc Description: ------------ connect() in Protocol/Client.php returns false if the response code is NET_NNTP_PROTOCOL_RESPONSECODE_READY_POSTING_PROHIBITED This doesn't make sense since it's still possible to scan a newsgroup you connected to with posting disabled. I propose you return true even in this state, but set a public object $canPost to true or false based on what the server responded. There is actually TODO code around this problem saying: // TODO: Set some variable before return Test script: --------------- # You'll need a news group that returns the POSTING_PROHIBITED error code. reader.ssl-news.info for example does. require_once "Net/NNTP/Client.php"; $nntp = new Net_NNTP_Client(); $val = $nntp->connect('reader.ssl-news.info', 'ssl', 563, 10); if ( $val === false ){ echo "fail\n"; // don't get me wrong... you should arrive here if the server is unavailable } else { echo "we're good!\n"; } Expected result: ---------------- we're good! Actual result: -------------- fail ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19752&edit=1

« previous php.pear.bugs (#9419) next »