Closed supernovasurfer closed 3 years ago
Well, this is more than a phpvms issue/bug.
Let me explain why; Trying to get property 'name' of non-object
error is thrown only when the main referenced object is deleted or not present, but your phpvms theme (or phpvms core code) is still trying to use it (as expected).
Here our main object is an airport, precisely speaking it is Frankfurt / EDDF. Imagine you insert flights to your database using EDDF as dep/arr, and then have some flights to/from EDDF, send pireps. Then all of sudden for some reason you want to delete EDDF.
Both your flights and old pireps will still have references to EDDF (this is the id of the object
referenced) , and some blades/widgets will try to read it's name
(like Frankfurt International Airport) , some do try to get its IATA/ICAO code, country etc etc.
All those attempts will end up Trying to get property 'name' of non-object
'cause EDDF is not there anymore. It is still in your pirep or flight, but not in your airports to be clear.
For airports correcting this error is easy, just add EDDF back and use auto lookup feature to get all fields back (or manually insert all fields). But for users, flights, pireps, subfleets etc this may not be that easy.
From you screenshots ;
{{ $flight->arr_airport->name }}
: Arrival airport is deleted
return $first_name.' '.$last_name[0]
: User is deleted
So simply re-producing steps you mentioned are not working for me 'cause I do not have any deleted airports or users. ( I do have some removed airports and users, but done in a proper way to prevent errors of course )
Also when you see this kind of errors I would kindly suggest switching to default theme and checking the same page there 'cause this may be a theme issue (lack of failsafe - cause i really do not like putting fail safe protections to every single variable in the blade)
Anyway, for theme side, I am working on Disposable v2 and hopefully it will be able to cover more errors regarding deleted references but I can not quarantee that it will 100% safe.
Safe flights and thanks for your kind thoughts. Disposable ;)
What a detailed and prompt response :-)
I guess for the time being I'll take my amateurs coder self :-) and add the airport/s showing errors as suggested.
Looking forward to your disposable v2 whenever you do release it, thanks again !
P.S. I had 38 Thousand pireps to import, I know i know dont ask :-)) so it is just errors caused by my own work
:) You can make the variables optional if you do not want to have the airports back ... (That is what I am doing in theme v2 though)
For example {{ $flight->arr_airport->name ?? '' }}
will make the arrival airport and its name optional , that ?? ''
is the failsafe of some sort.
{{ $flight->arr_airport->name ?? '' }}
: Will display nothing
{{ $flight->arr_airport->name ?? 'Deleted Airport' }}
: Will display 'Deleted Airport' instead of throwing an error
{{ $flight->arr_airport->name ?? $flight->arr_airport_id }}
: Will use the airport id from the flights table instead of getting its name from airports table
So if you are importing v5 records to v7, above tricks may be needed for Pireps too like
{{ $pirep->arr_airport->icao ?? '' }}
{{ $pirep->arr_airport->name ?? 'Not Existing Airport' }}
{{ $pirep->arr_airport->name ?? $pirep->arr_airport_id }}
Hope this little info helps.
Is this still valid?
No lets close it , solved in the new version as he had mentioned Thanks
Firstly thanks to the Developer for all the work on the project. Thanks also to the other devs for supporting on the forums. Thanks to B. Fatih for work on the skin and modules.
Describe the bug When clicking only some of the airport ICAO codes from the pirep list pages on the front end: Two types of Errors thrown Uninitialized string offset Trying to get property 'name' of non-object
Version phpVMS 7.0.0-dev
To Reproduce Steps to reproduce the behavior:
Go to 'domain/pireps.'
Click on '.domain/airports/EDDF' for example
....n/a
Errors described above lead to stack trace page
Expected behavior Page showing Details of the Airport ( Wx reports , inbound / outbound flights , map etc
Screenshots Attached
Additional context Laravel log attached
laravel-2021-04-30.log