Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between http_build_str() and http_build_query()?

Tags:

php

I just discover these functions seems redundant. http_build_query() belong to standard php functions. http_build_str() is part of pecl_http package.

are they 100% redundant ?

I am focused on getting the perfect reverse function of parse_str(). since http_build query() is broken. ( see reference ) I wondering if there is some way that http_build_str() could have any advantage to support/tolerate more edge cases.

like image 394
Frederic Bazin Avatar asked Nov 02 '12 14:11

Frederic Bazin


2 Answers

By reading the API, it appears that http_build_str() does not URL encode the parameters, while http_build_query() does.

http_build_str() also can take either an object OR an object as its primary argument, while http_build_query() only takes an array.

like image 192
thatidiotguy Avatar answered Oct 21 '22 23:10

thatidiotguy


Redundant to an extent. But, if you refer to the PHP documentation, you ought to see distinct differences:

http://php.net/manual/en/function.http-build-query.php

http://php.net/manual/en/function.http-build-str.php

In the very least, you ought to see that http_build_query() is core PHP and supports an additional encoding style parameter. And you ought to see that http_build_str() is a PECL extension.

like image 42
svidgen Avatar answered Oct 22 '22 00:10

svidgen