PHP - warning - Undefined property: stdClass - fix?

后端 未结 9 1080
梦毁少年i
梦毁少年i 2020-11-30 05:22

I 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::$records in script

9条回答
  •  悲&欢浪女
    2020-11-30 05:48

    If you want to use property_exists, you'll need to get the name of the class with get_class()

    In this case it would be :

     if( property_exists( get_class($response), 'records' ) ){
           $role_arr = getRole($response->records);
     }
     else
     {
           ...
     }
    

提交回复
热议问题