$rain='<p>обсяг дощу за останні 3 години: '.$lists->rain->3h.'</p>'; 

Parse error: syntax error, unexpected '3' (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C: \ xampp \ htdocs \ pog.php on line 16

I understand that I swear at the name of the field ->3h , but I can't change the name because I use the API of another site

  • The error indicates an unexpected number when waiting for a string or variable - Mr. Black
  • one
  • Such an error: Cannot use object of type stdClass as array in - Alexandr Polishchyk

1 answer 1

Fields that have an invalid name from the point of view of the PHP parser can be accessed using the following syntax:

 $rain='<p>обсяг дощу за останні 3 години: '.$lists->rain->{"3h"}.'</p>'; 
  • used this syntax gives another error Undefined property: stdClass :: $ 3h in C: \ xampp \ htdocs \ pog.php on line 16 - Alexandr Polishchyk
  • Everything turned out, nada, still check first isset $ lists-> rain -> {"3h"} - Alexandr Polishchyk