ID: 39034 User updated by: james dot gauth at gmail dot com Reported By: james dot gauth at gmail dot com Status: Assigned -Bug Type: Feature/Change Request +Bug Type: cURL related Operating System: Debian PHP Version: 4.4.4 Assigned To: iliaa New Comment:
I'm setting the category back to cURL related, inconsistent return values are not a feature. Previous Comments: ------------------------------------------------------------------------ [2006-10-05 11:58:21] james dot gauth at gmail dot com The source of this problem is the following: [ext/curl/interface.c][1664] if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.len > 0) { --ch->uses; smart_str_0(&ch->handlers->write->buf); RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1); } --ch->uses; RETURN_TRUE; } If the write buffer has no length, the PHP_CURL_RETURN option is ignored and a value of TRUE is returned. This code has been in CVS since revision 1.1. Regardless of the write buffer length, setting PHP_CURL_RETURN option on should case curl_exec() to return a string. If this code is not going to be changed I would recommend the PHP manual be changed to warn the user of this behaviour. One of the issues this problem causes is that if you don't specifically check for the boolean true return value, any normal string comparisons made against curl_exec()'s return value are always true (true == 'string' is true) whereas the expected result would be ('' == 'string' is false). ------------------------------------------------------------------------ [2006-10-04 09:06:33] james dot gauth at gmail dot com Description: ------------ When calling curl_exec() with the CURLOPT_RETURNTRANSFER option set to true, a user expects that curl_exec() will return the string value of the request. When the URL of the request in question points to a zero-byte file, curl_exec() returns bool(true) instead of the expected empty string. The versions I am using are: PHP 4.4.4 (cli) (built: Sep 11 2006 10:00:33) Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies CURL Information => libcurl/7.13.2 OpenSSL/0.9.7e zlib/1.2.3 libidn/0.5.13 Reproduce code: --------------- <?php // fictional URL to an existing file with no data in it (ie. 0 byte file) $url = 'http://www.example.com/empty_file.txt'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); // execute and return string (this should be an empty string '') $str = curl_exec($curl); curl_close($curl); // the value of $str is actually bool(true), not empty string '' var_dump($str); ?> Expected result: ---------------- string(0) "" Actual result: -------------- bool(true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39034&edit=1