/    Sign up×
Community /Pin to ProfileBookmark

How to get rid of PHP’s echo warning messages?

I am having an XHR call for php script.
Php script returns a JSON object that has the following structure:
`
$json_return_data = array(
“ReturnCode” => 0,
“ReturnMessage” => ”,
“ID” => 0,
“XML_Reference_ID” => ”,
“Name” => ”,
“Vendor” => ”,
“Description” => ”,
“Price” => ”,
“Oldprice” => ”,
“Param” => ”,
“Picture” => ”,
“Url” => ”
);
`

As you can see, the first 2 are for detecting the return type and messages.
However, this all falls apart if there is a PHP warning. Because then not only the JSON object gets returned to JavaScript, but the warning does as well.
This makes the `JSON.parse(this.responseText);` not work! Because the error message comes first, and then the JSON object.

What I do in my PHP is:
`
$json_file_contents = file_get_contents(“../../../XML-uploaded/variadbles.json”) or
exit(json_encode(`
{“ReturnCode”=>-1,”ReturnMessage”=>”Can’t access variables.json”}`));
`

Is there a way to get rid of these annoying warnings and only keep my JSON?

Thank you,
Andrei

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @weareandrei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...