PHP Strange NULL variable situation

Tackalelt

New Member
I'm having a tough time with this one, I have a class which populates an array.Sometimes the array will not be populated and I want make an edge-case for when this happens however I can't seem to tell when its null! Here's the code: \[code\]$results_dev = $class->get_data_nologin("4a9d-4f41-9566-7705",$key,"Sensors"); echo "something"; print_r($results_dev); if(is_null($results_dev)) { echo "thisisNULL"; $counter--; }\[/code\]"something" does get echoed out, but when I print_r $results_dev, it prints "null" and the if statement never executes! I've also tried\[code\]if(!$results_dev)\[/code\]and\[code\]if($results_dev == "null")\[/code\]and\[code\]if($results_dev == null)\[/code\]But it still doesn't execute whats in the if loop, how else could I check this?BTW: my class curls an API and retrieves a JSON, however sometimes the URL is incorrect in curl so it returns null. What's even worse is after this I have:\[code\]if($results_dev['location']) { echo "data".$results_dev['location'];\[/code\]And It executes even when its null! It prints "data" and absolutely nothing afterwards.code for get_data_nologin:\[code\] $url = 'https://api.url/'.$scf.'/'.$deviceid.'?key='.$apikey; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $cookie_file_path); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) { echo 'Something went wrong :('; } else { $decodedBuffer = json_decode($buffer, TRUE); return $decodedBuffer; }\[/code\]Any advice would help!
 
Back
Top