Opened 16 years ago
Closed 16 years ago
#9044 closed defect (bug) (fixed)
http_build_query: third arg not added until PHP v. 5.1.2
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | blocker | Version: | 2.7 |
Component: | HTTP API | Keywords: | has-patch |
Focuses: | Cc: |
Description
In wp-includes/compat.php:
// Added in PHP 5.0 if (!function_exists('http_build_query')) { function http_build_query($data, $prefix=null, $sep=null) { return _http_build_query($data, $prefix, $sep); } }
But according to: http://us2.php.net/http_build_query
The third argument wasn't added until PHP Version 5.1.2
This caused my install to fail when trying to use the automatic plugin upgrade function. In research, I found several occurrences of others fighting with this error:
Warning: http_build_query() expects at most 2 parameters, 3 given in /stor/ezines/htdocs/wp-includes/http.php on line 248
Line 248 has:
$r['body'] = http_build_query($r['body'], null, '&');
I believe this should call _http_build_query:
$r['body'] = _http_build_query($r['body'], null, '&');
Which fixed my installation.
I'm not sure if this is accurate but I also believe that the logic in compat.php to test for the function http_build_query should also test for php version... something like:
if (!function_exists('http_build_query') || version_compare(PHP_VERSION, '5.1.2') === -1 ) { if(function_exists('http_build_query')) { override_function('http_build_query', '$data, $prefix=null, $sep=null', 'return _http_build_query($data, $prefix, $sep);'); }else{ function http_build_query($data, $prefix=null, $sep=null) { return _http_build_query($data, $prefix, $sep); } } }
But that requires APD functions to override the native function so I don't know if that's the best approach or if it's even necessary since http.php was the only file I could find that called http_build_query directly. I'll leave that up to the gurus I guess ;)
Attachments (3)
Change History (15)
#2
in reply to:
↑ 1
@
16 years ago
Replying to jacobsantos:
Dude, what about upgrading to like at least 5.2.3?
But yeah, it should use the _http_build_query().
Upgrading isn't an issue for me - but it might be for some. I submitted it as a bug because there is a case where it doesn't work and not everyone has control over their PHP version.
#3
@
16 years ago
- Keywords has-patch tested dev-feedback added; http_build_query bug http plugins removed
- Milestone changed from 2.7.2 to 2.8
#4
follow-up:
↓ 7
@
16 years ago
- Keywords has-patch tested removed
We must force the separator to be '&'. We'll have to use _http_build_query() then. Maybe add a version check and have it call the builtin http_build_query() if the version is >= 5.1.2.
#7
in reply to:
↑ 4
@
16 years ago
Replying to ryan:
We must force the separator to be '&'. We'll have to use _http_build_query() then. Maybe add a version check and have it call the builtin http_build_query() if the version is >= 5.1.2.
'&' is the default seperator with PHP. So it must not be explicitly named here. Or do I get something wrong here?
#10
@
16 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
According to http://us2.php.net/http_build_query we should use "&" as separator instead of "&".
Dude, what about upgrading to like at least 5.2.3?
But yeah, it should use the _http_build_query().