Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: maomao on February 13, 2013, 03:25:40 AM



Title: 【SOLVED】PHP error help!
Post by: maomao on February 13, 2013, 03:25:40 AM
get this warning in my error logs and wanted to know how to correct this issues in my code.

Warning: PHP Notice: Undefined property: stdClass::$balance in script.php on line 33





$balance = $json->{'balance'} / 100000000; // line 33


Title: Re: PHP error help!
Post by: payb.tc on February 13, 2013, 03:36:46 AM
maomao, before line 33, can you

var_dump($json);

...if possible, pasting the whole script here might help.


Title: Re: PHP error help!
Post by: BCB on February 13, 2013, 03:53:54 AM
did you include the library you are referencing or is the path correct?


Title: Re: PHP error help!
Post by: payb.tc on February 13, 2013, 04:00:49 AM
have you tried this by the way:

$balance = $json->balance / 100000000; // line 33

i'm not familiar with the script you're using... did you copy it from somewhere, or come up with that line yourself?


without further detail, it appears to me that the line you're using is looking inside the $json object for a property or method called $balance and then using the value of $balance to look for a further property or method of $json.

eg.

class jsonClass {
     $balance = 'mybalancevar';
     $mybalancevar = 33;
}

in this case, $json->{'balance'} would equal 33; while $json->balance would be a string: mybalancevar


Title: Re: PHP error help!
Post by: maomao on February 13, 2013, 06:16:14 AM
function check_balance()
{
   

   
      $jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/balance?password=".$GLOBALS['password'];
      $json = file_get_contents($jsonurl,0,null,null);
      $json = json_decode($json);
      
       $balance = $json->balance/ 100000000;
      
      
   
   return $balance;
}


Title: Re: PHP error help!
Post by: payb.tc on February 13, 2013, 09:19:37 AM
function check_balance()
{
   

   
      $jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/balance?password=".$GLOBALS['password'];
      $json = file_get_contents($jsonurl,0,null,null);

echo '<pre>$json = ' . $json . '<br/><br/>';

      $json = json_decode($json);

print_r($json);
echo '</pre>';


       $balance = $json->balance/ 100000000;
      
      
   
   return $balance;
}


let's see what's in that $json var first, so we know why the balance thing is throwing an error


Title: Re: PHP error help!
Post by: maomao on February 13, 2013, 10:23:27 AM
Thank you.  The reason is that there are special characters in my password.


Title: Re: 【SLOVED】PHP error help!
Post by: ingrownpocket on February 13, 2013, 10:30:42 AM
Glad it was 【SLOVED】 ;D