Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal PHP error in ?view=console #4224

Open
onlyjob opened this issue Feb 21, 2025 · 6 comments
Open

Fatal PHP error in ?view=console #4224

onlyjob opened this issue Feb 21, 2025 · 6 comments

Comments

@onlyjob
Copy link
Contributor

onlyjob commented Feb 21, 2025

ZoneMinder 1.36.35 with PHP8.2 on Debian 12 "bookworm" (Debian package).

I'm getting the following server-side error when opening console view in browser:

PHP message: PHP Fatal error:  Uncaught Error:
 Call to a member function UrlToIndex() on null in 
  /usr/share/zoneminder/www/includes/Monitor.php:494
Stack trace:
#0 /usr/share/zoneminder/www/skins/classic/views/js/console.js.php(24): ZM\Monitor->UrlToIndex()
#1 /usr/share/zoneminder/www/skins/classic/includes/functions.php(929): require_once('...')
#2 /usr/share/zoneminder/www/skins/classic/views/console.php(447): xhtmlFooter()
#3 /usr/share/zoneminder/www/index.php(309): require_once('...')
#4 {main}
  thrown in /usr/share/zoneminder/www/includes/Monitor.php on line 494"
@connortechnology
Copy link
Member

connortechnology commented Feb 21, 2025

I think line 182 should be if(!$this->{'Server'}) {
instead of
if (!property_exists($this, 'Server')) {
The line above ensures that the property exists, but is empty if ServerId is not empty but is not valid.

Is it possiblie that the monitor has a non-empty but not valid ServerId?

@onlyjob
Copy link
Contributor Author

onlyjob commented Feb 21, 2025

I'm not sure about the cause... I have no multiserver configuration but I may have changed something after upgrade that caused it... The issue seems to have gone once I've cleared "groups" to "all" in console...

@connortechnology
Copy link
Member

Hmm... yeah I tested my theory and it didn't pan out. So you had a group selected... I wonder if there was a deleted monitor in that group or something like that? Time to do more testing.

@onlyjob
Copy link
Contributor Author

onlyjob commented Feb 21, 2025

I also thought about "non-empty but not valid ServerId" but issue cleared only after manipulation with groups.

Before that I did re-save configuration of all cameras, trying to set server explicitly either to "None" or to "Auto" in attempt to resolve the issue (just in case there was something historical left in camera settings.) I created this bug report after failing to clear the error, but then, unexpectedly, it was gone after I tried selecting groups.

Sorry for lack of clear reproducer. Perhaps null value should be handled somehow, just in case?

@connortechnology
Copy link
Member

I think it is. Normally when we load a db record, it contains an entry for ServerId, so the property gets defined.

If the record didn't exist, then we might do return new ZM\Monitor(); Which would create an empty object, but all those fields aren't actually defined as properties. Hence the test for the property existing.

It appears there though that the property exists, but is null.... and we don't test for that... so I think I see how the code should be improved...

@connortechnology
Copy link
Member

If you are able to make it happen again, can you try replacing the function with the following?
public function Server() { if (!property_exists($this, 'Server')) $this->{'Server'} = $this->ServerId() ? Server::find_one(array('Id'=>$this->{'ServerId'})) : new Server(); if (!$this->{'Server'}) # the find_one can return null $this->{'Server'} = new Server(); return $this->{'Server'}; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants