Warning: http_build_query(): Parameter 1 expected to be Array or Object whm api

Multi tool use
I have warning with my coding whm plugins
Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in /module_functions.php on line 50
Line 150 is: $query .= '?' . http_build_query($params);
Full line:
public function whmaapicall()
{
$whmusername = $_ENV['REMOTE_USER'];
$whmpassword = $_ENV['REMOTE_PASSWORD'];
$query = 'https://127.0.0.1:2087/json-api/listpkgs?api.version=1';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: Basic ' . base64_encode($whmusername . ':' . $whmpassword) . "nr";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if (!$result) {
error_log('curl_exec threw error "' . curl_error($curl) . '" for ' . $query);
}
curl_close($curl);
return json_decode($result);
}
public function whmapi($function = NULL, $params = NULL)
{
$whmusername = 'root';
if ($function == 'listpkgs') {
$whmusername = $_ENV['REMOTE_USER'];
return $this->whmapi2();
}
$whmhash = $this->gethash();
$query = 'https://127.0.0.1:2087/json-api/' . $function;
$query .= '?' . http_build_query($params); //line mentioned
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: WHM ' . $whmusername . ':' . preg_replace(''(' . "r" . '|' . "n" . ')'', '', $whmhash);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
php curl cpanel whm cpanel-xmlapi
add a comment |
I have warning with my coding whm plugins
Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in /module_functions.php on line 50
Line 150 is: $query .= '?' . http_build_query($params);
Full line:
public function whmaapicall()
{
$whmusername = $_ENV['REMOTE_USER'];
$whmpassword = $_ENV['REMOTE_PASSWORD'];
$query = 'https://127.0.0.1:2087/json-api/listpkgs?api.version=1';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: Basic ' . base64_encode($whmusername . ':' . $whmpassword) . "nr";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if (!$result) {
error_log('curl_exec threw error "' . curl_error($curl) . '" for ' . $query);
}
curl_close($curl);
return json_decode($result);
}
public function whmapi($function = NULL, $params = NULL)
{
$whmusername = 'root';
if ($function == 'listpkgs') {
$whmusername = $_ENV['REMOTE_USER'];
return $this->whmapi2();
}
$whmhash = $this->gethash();
$query = 'https://127.0.0.1:2087/json-api/' . $function;
$query .= '?' . http_build_query($params); //line mentioned
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: WHM ' . $whmusername . ':' . preg_replace(''(' . "r" . '|' . "n" . ')'', '', $whmhash);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
php curl cpanel whm cpanel-xmlapi
$params
isn't defined anywhere. Also,$params
clearly isn't an array or object. You need to figure out why. You can start withvar_dump($params);
to see what type it is...if it is even defined at all.
– John Conde
Dec 29 '18 at 17:00
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Wrap it inIf (!empty($params))
or declare the function argument default as=array()
for simplicity.
– mario
Dec 29 '18 at 17:25
add a comment |
I have warning with my coding whm plugins
Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in /module_functions.php on line 50
Line 150 is: $query .= '?' . http_build_query($params);
Full line:
public function whmaapicall()
{
$whmusername = $_ENV['REMOTE_USER'];
$whmpassword = $_ENV['REMOTE_PASSWORD'];
$query = 'https://127.0.0.1:2087/json-api/listpkgs?api.version=1';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: Basic ' . base64_encode($whmusername . ':' . $whmpassword) . "nr";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if (!$result) {
error_log('curl_exec threw error "' . curl_error($curl) . '" for ' . $query);
}
curl_close($curl);
return json_decode($result);
}
public function whmapi($function = NULL, $params = NULL)
{
$whmusername = 'root';
if ($function == 'listpkgs') {
$whmusername = $_ENV['REMOTE_USER'];
return $this->whmapi2();
}
$whmhash = $this->gethash();
$query = 'https://127.0.0.1:2087/json-api/' . $function;
$query .= '?' . http_build_query($params); //line mentioned
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: WHM ' . $whmusername . ':' . preg_replace(''(' . "r" . '|' . "n" . ')'', '', $whmhash);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
php curl cpanel whm cpanel-xmlapi
I have warning with my coding whm plugins
Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in /module_functions.php on line 50
Line 150 is: $query .= '?' . http_build_query($params);
Full line:
public function whmaapicall()
{
$whmusername = $_ENV['REMOTE_USER'];
$whmpassword = $_ENV['REMOTE_PASSWORD'];
$query = 'https://127.0.0.1:2087/json-api/listpkgs?api.version=1';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: Basic ' . base64_encode($whmusername . ':' . $whmpassword) . "nr";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if (!$result) {
error_log('curl_exec threw error "' . curl_error($curl) . '" for ' . $query);
}
curl_close($curl);
return json_decode($result);
}
public function whmapi($function = NULL, $params = NULL)
{
$whmusername = 'root';
if ($function == 'listpkgs') {
$whmusername = $_ENV['REMOTE_USER'];
return $this->whmapi2();
}
$whmhash = $this->gethash();
$query = 'https://127.0.0.1:2087/json-api/' . $function;
$query .= '?' . http_build_query($params); //line mentioned
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$header[0] = 'Authorization: WHM ' . $whmusername . ':' . preg_replace(''(' . "r" . '|' . "n" . ')'', '', $whmhash);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
php curl cpanel whm cpanel-xmlapi
php curl cpanel whm cpanel-xmlapi
edited Dec 29 '18 at 17:10
Hendra Setyawan
asked Dec 29 '18 at 17:00
Hendra SetyawanHendra Setyawan
15118
15118
$params
isn't defined anywhere. Also,$params
clearly isn't an array or object. You need to figure out why. You can start withvar_dump($params);
to see what type it is...if it is even defined at all.
– John Conde
Dec 29 '18 at 17:00
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Wrap it inIf (!empty($params))
or declare the function argument default as=array()
for simplicity.
– mario
Dec 29 '18 at 17:25
add a comment |
$params
isn't defined anywhere. Also,$params
clearly isn't an array or object. You need to figure out why. You can start withvar_dump($params);
to see what type it is...if it is even defined at all.
– John Conde
Dec 29 '18 at 17:00
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Wrap it inIf (!empty($params))
or declare the function argument default as=array()
for simplicity.
– mario
Dec 29 '18 at 17:25
$params
isn't defined anywhere. Also, $params
clearly isn't an array or object. You need to figure out why. You can start with var_dump($params);
to see what type it is...if it is even defined at all.– John Conde
Dec 29 '18 at 17:00
$params
isn't defined anywhere. Also, $params
clearly isn't an array or object. You need to figure out why. You can start with var_dump($params);
to see what type it is...if it is even defined at all.– John Conde
Dec 29 '18 at 17:00
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Wrap it in
If (!empty($params))
or declare the function argument default as =array()
for simplicity.– mario
Dec 29 '18 at 17:25
Wrap it in
If (!empty($params))
or declare the function argument default as =array()
for simplicity.– mario
Dec 29 '18 at 17:25
add a comment |
1 Answer
1
active
oldest
votes
in the whmapi function, $params has a default value of NULL, and NULL is not a legal argument for http_build_query, and you pass $params straight to http_build_query without first checking if it's null. stop giving http_build_query NULL's, do something like
$query .= '?';
if($params!==NULL){
$query.=http_build_query($params);
}
You could also change the definition of the function to set the default value to be an empty array.Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..function f($v=){var_dump($v);} f(NULL);
=>NULL
- however, if you're running PHP7+, this would be safe but not accept objects:function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well:function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971547%2fwarning-http-build-query-parameter-1-expected-to-be-array-or-object-whm-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
in the whmapi function, $params has a default value of NULL, and NULL is not a legal argument for http_build_query, and you pass $params straight to http_build_query without first checking if it's null. stop giving http_build_query NULL's, do something like
$query .= '?';
if($params!==NULL){
$query.=http_build_query($params);
}
You could also change the definition of the function to set the default value to be an empty array.Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..function f($v=){var_dump($v);} f(NULL);
=>NULL
- however, if you're running PHP7+, this would be safe but not accept objects:function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well:function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
add a comment |
in the whmapi function, $params has a default value of NULL, and NULL is not a legal argument for http_build_query, and you pass $params straight to http_build_query without first checking if it's null. stop giving http_build_query NULL's, do something like
$query .= '?';
if($params!==NULL){
$query.=http_build_query($params);
}
You could also change the definition of the function to set the default value to be an empty array.Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..function f($v=){var_dump($v);} f(NULL);
=>NULL
- however, if you're running PHP7+, this would be safe but not accept objects:function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well:function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
add a comment |
in the whmapi function, $params has a default value of NULL, and NULL is not a legal argument for http_build_query, and you pass $params straight to http_build_query without first checking if it's null. stop giving http_build_query NULL's, do something like
$query .= '?';
if($params!==NULL){
$query.=http_build_query($params);
}
in the whmapi function, $params has a default value of NULL, and NULL is not a legal argument for http_build_query, and you pass $params straight to http_build_query without first checking if it's null. stop giving http_build_query NULL's, do something like
$query .= '?';
if($params!==NULL){
$query.=http_build_query($params);
}
answered Dec 30 '18 at 0:13
hanshenrikhanshenrik
9,82921738
9,82921738
You could also change the definition of the function to set the default value to be an empty array.Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..function f($v=){var_dump($v);} f(NULL);
=>NULL
- however, if you're running PHP7+, this would be safe but not accept objects:function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well:function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
add a comment |
You could also change the definition of the function to set the default value to be an empty array.Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..function f($v=){var_dump($v);} f(NULL);
=>NULL
- however, if you're running PHP7+, this would be safe but not accept objects:function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well:function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
You could also change the definition of the function to set the default value to be an empty array.
Array $params =
– John Conde
Dec 30 '18 at 3:52
You could also change the definition of the function to set the default value to be an empty array.
Array $params =
– John Conde
Dec 30 '18 at 3:52
@JohnConde uhm..
function f($v=){var_dump($v);} f(NULL);
=> NULL
- however, if you're running PHP7+, this would be safe but not accept objects: function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well: function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
@JohnConde uhm..
function f($v=){var_dump($v);} f(NULL);
=> NULL
- however, if you're running PHP7+, this would be safe but not accept objects: function f(array $v=){var_dump($v);}
, but if you're running PHP7.1+, this would work and accept objects as well: function f(iterable $v=){var_dump($v);}
– hanshenrik
Dec 30 '18 at 12:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971547%2fwarning-http-build-query-parameter-1-expected-to-be-array-or-object-whm-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Gx9OEfB VdLuRiAxUD2BG,5xBJL,M6yfcy,GKue345,i,n,Z IAiJvx
$params
isn't defined anywhere. Also,$params
clearly isn't an array or object. You need to figure out why. You can start withvar_dump($params);
to see what type it is...if it is even defined at all.– John Conde
Dec 29 '18 at 17:00
Should $query .= '?' . var_dump($params); ?
– Hendra Setyawan
Dec 29 '18 at 17:09
Wrap it in
If (!empty($params))
or declare the function argument default as=array()
for simplicity.– mario
Dec 29 '18 at 17:25