Stream online/offline

What is wrong with my php code?

$data = @file_get_contents("https://api.twitch.tv/kraken/streams/36837650?client_id=xxxxxx&api_version=5");
$json = json_decode($data);
  if (($json->stream === "NULL") || ($json->stream === "null")) {
    echo "Stream is offline!";
  }
  else {
    echo "Stream is online!";
  }

I’m offline right now, but it still shows online!

When I do a var_dump($json->stream) in the else part it shows NULL.

=== is strict comparison. So null is only true against null. “null” is a string.

http://php.net/manual/en/types.comparisons.php

The API returns actual null, not "null" string.

$ php -r 'var_dump(null);'
NULL
$ php -r 'var_dump("null");'
string(4) "null"

Thanks guys

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.