Fatal PHP Error in FreePBX 2.2.1

I have been running freePBX v.2.2.1 since it was released with no problems. In addition, I’m running Asterisk v.1.2.17, again with no problems. Last week, without making a single change to the system, calls started going directly to follow-me extensions without first ringing the phone. When I logged on to check into the problem, I was presented with blank menus after logging in to Setup or Tools (reports loads fine). Searching through the log files, I found this error in my httpd ssl_freepbx error log. I run my configuration under SSL…

[Mon Apr 02 120014 2007] [error] [client xxx.xxx.xxx.xxx] PHP Fatal error main() [function.main] The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “ampuser” of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /var/www/html/admin/config.php on line 110, referer https//asterisk.my.domain.com/admin/config.php

Can someone please shed some light on this. I have looked at every obvious problem - permissions, ownership, etc. and nothing seems to have changed. I am also running the exact same revision levels on another system and don’t have the same issue.

Thanks,

-mark weiss

Bubba,

After months of trying to figure this problem out, I finally found the solution. It is caused by having session.auto_start in the PHP.ini file turned on. Apparently I had session.auto_start turned on and it was fine under previous versions of PHP. When PHP was upgraded, it caused freePBX to fail.

Here are the clues I found

“You get this error if you have an object in your $_SESSION array and you call session_start() before you have loaded your included classes.”

Here are some excerpts from the PHP manual

The session support allows you to register arbitrary numbers of variables to be preserved across requests. When a visitor accesses your site, PHP will check automatically (if session.auto_start is set to 1) or on your request (explicitly through session_start() or implicitly through session_register()) whether a specific session id has been sent with the request. If this is the case, the prior saved environment is recreated.

This was the final clue

Caution

If you do turn on session.auto_start then you cannot put objects into your sessions since the class definition has to be loaded before starting the session in order to recreate the objects in your session.

If anyone encounters this error

Notice main() [function.main] The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “” of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in on line

Make sure you have set session.auto_start = 0 in php.ini.

http://www.freepbx.org/forums/viewtopic.php?t=1887

Bubba,

Thanks for the link. It seemed completely plausible that this might be the answer. I found that my header.php had the extra “>”. I replaced with his “clean” version but it made no difference.

I’ll keep looking for a solution.

-mark

If this is a php5 upgrade issue, you can check to see if there’s a /etc/php.ini.rpmnew, and if there is, backup the current one and then type mv /etc/php.ini.rpmnew /etc/php.ini

this overwrite the PHP4 .ini file with the php5 (need to restart PHP)

Bubba,

Thanks for the suggestion. I already checked for a php.ini.rpmnew. There wasn’t one. Whatever was upgraded with PHP apparently did not require a change in php.ini. I haven’t been able to find a manifest of what was changed with the most recent upgrade to PHP so I’m still groping in the dark with this problem. Google isn’t even yielding any helpful information.

I’ve swapped the config.php and header.php files from my other running system and it doesn’t matter. There isn’t a problem with login or authentication. For instance, when I click on Setup or Tools, the login pop-up appears. I log in as admin, no problem. the menu screen loads and has the red bar at the top. If I click on the link to anything on the page whether it be extensions or module admin, the next screen contains the header but the body is blank. Thus the Warning error for header.php and the Fatal error for config.php in the logs.

This is really crazy, cause I’m just not getting enough information to point me in the right direction on where the problem is.

Once again, I want to thank you for your thoughts and input.

Kind Regards,

-mark

Maybe you did a yum update???

Check your PHP version

Bubba,

Thanks for the reply. PHP version is php-5.1.6-3.4.fc6. The system has had yum updates since initially configured months ago. I checked for any PHP updates that occurred around the time that this error appeared about two weeks ago and didn’t find any updates to PHP, MySQL or Apache. I’ll look again.

If this version of php is incompatible, is there a way to fix the code or do I need to install a lesser rev?

-mark

It should work with 5 many have had issues…but most are just permission errors

what is line 110 (is it the session var??)

What browser r u using?

Test from other box???

Bubba,

The install was working for several months. After reading your response, I went back through the yum logs and found that PHP was, in fact, updated on 3/11/07. I had not used the FreePBX console until I was presented with a question on 3/19/07, a week later. The system was configured and operational and therefore not something I was checking with on a daily basis.

I use Firefox exclusively as the browser. The Server is Fedora Core 6 and was configured as an update of FC5. The system as been running Apache 2.2.3-5 and MySQL 5.0.27-1 for some time. There has not been an update to these since the beginning of the year. Nothing here seems to be out of rev.

Per your request, here is the config.php code from line 110 to the end of the statement

if ($_SESSION[“AMP_user”]->checkSection($key)) {
// if the module has it’s own translations, use them for displaying menu item
if (extension_loaded(‘gettext’)) {
if (is_dir(“modules/{$key}/i18n”)) {
bindtextdomain($key,“modules/{$key}/i18n”);
bind_textdomain_codeset($key, ‘utf8’);
textdomain($key);
} else {
bindtextdomain(‘amp’,’./i18n’);
textdomain(‘amp’);
}
}
} else {
// they don’t have access to this, remove it completely
unset($fpbx_menu[$key]);
}

I’m also including the statement from line 192 of header.php as it has a PHP Notice error that occurs prior to the Fatal error from config.php

echo _(‘Logged in ‘).$_SESSION[‘AMP_user’]->username;
echo ’ (<a href="http’.(isset($_SERVER[‘HTTPS’])&&$_SERVER[‘HTTPS’]!=’’?‘s’’’).’//’;

            if (!ereg('MSIE', $_SERVER['HTTP_USER_AGENT'])) {
                    // use other logout for Firefox and other browsers
                    echo 'logoutlogout@';
            }

If any other code snippets are needed, please let me know.

Thanks for your help, it is greatly appreciated.

Regards,

-mark

Can anyone venture to guess why I’m getting this error. Freepbx is completely disfunctional at this point with no apparent reason why this error started.

The only thing that I have been able to determine is that class definition “ampuser” for what ever reason, is failing to be properly configured from config.php. I’m not a php programmer nor do I know the internals of the freepbx code but this appears to be a bug that can just show up on a functioning system without warning.