php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40147 Bad Socket Example
Submitted: 2007-01-16 17:53 UTC Modified: 2007-01-17 00:16 UTC
From: bnewton at networkmerchants dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: LINUX
Private report: No CVE-ID: None
 [2007-01-16 17:53 UTC] bnewton at networkmerchants dot com
Description:
------------
The first example on the Sockets section of the manual uses socket_bind and socket_listen incorrectly. They manual page for each function correctly states that they return BOOLEAN values, not error return codes. That means the lines:

if (($ret = socket_bind($sock, $address, $port)) < 0) {
   echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}

if (($ret = socket_listen($sock, 5)) < 0) {
   echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
}

Will not fail, if there is an error. If they did fail, they would not report any meaningful error message (error 0 ie false is "success"). 



Reproduce code:
---------------
if (($ret = socket_bind($sock, $address, $port)) < 0) {
   echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}

if (($ret = socket_listen($sock, 5)) < 0) {
   echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
}

Expected result:
----------------
If the socket is not available it should stop the execution of the script and display a meaningful error message. 

Actual result:
--------------
It will continue to run the code below, even if there really was an error. If it did stop, it would not print the correct error message

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-17 00:16 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 17:00:03 2025 UTC