I've got a reCaptcha service working, but passing the return values through PHP's json_decode
function gives some results I don't understand.
If the reCaptcha is valid then the service returns { "success": true }
- which I expect.
Calling
print_r(json_decode($result, $assoc = true)); //where $result is the service call
gives
Array ( [success] => )
...but I was expecting Array ( [success] => 1)
(or similar), to signify a true
value.
In fact, print_r(json_decode('{"success": true}', $assoc = true));
does return Array ( [success] => 1 )
What's different about the json the reCaptcha is returning? (and / or what am I failing to understand?!)
I guess that's what's further confusion here:
echo(gettype($a->success));
echo($a->success === true);
echo($a->success === false);
then I get
boolean
1
1
How can a check against true
and false
both return true
?!
Further info
Even more confusingly (for me at least), I've tried var_dump
too:
echo($a);
var_dump($a);
which returns
{ "success": true }
string(22) "{ "success": false }"
why is the json representation in var_dump
false
when echo
shows that it is true
?!