Improve "trying to get property 'id' of non-object" error message

php.internals

David Rodrigues

6 years ago
Hello! Is it possible to improve this error message? It is much more complicated to identify when we have two occurrences on the same line. For example: $availMasterResults->get($availMaster->id . '@' . $sessionUser->id) -> trying to get property 'id' of non-object Is not possible to identify if it is related to $availMaster or $sessionUser variables. Suggestion: -> trying to get property 'id' of non-object (null) from variable $availMaster -> trying to get property 'id' of non-object (int) retrieved from property $some->property -> trying to get property 'id' of non-object (array) retrieved from return of getObject() Atenciosamente, David Rodrigues

Máté Kocsis

6 years ago
Hi David, Please have a look at this example code: https://3v4l.org/IGUcS We've made dozens of error messages more helpful and more consistent for PHP 8. This is one of them. :) Cheers, Máté

David Rodrigues

6 years ago
Seems great, but maybe include more information should be better: Warning: Attempt to read property 'property' on bool <<variable $a>> in /in/IGUcS on line 5 Atenciosamente, David Rodrigues Em qui., 2 de jul. de 2020 às 12:27, Máté Kocsis <kocsismate90@gmail.com> escreveu: