Page 1 of 1

PHP 5 migration issue?

Posted: Tue Aug 19, 2008 7:34 am
by farmersguide
Hi - Several issues have appeared on a website I manage that may be related to recent migration by our host's servers from PHP 4 to PHP 5.

On one section of the site, the page still operates as expected, but I now get the following notices:
Notice: Undefined variable: searchResults in E:\domains\f\farmersguide.co.uk\user\htdocs\includes\viewcategories.inc.php on line 15

Notice: Undefined variable: htmlCode in E:\domains\f\farmersguide.co.uk\user\htdocs\includes\viewcategories.inc.php on line 15
Line 15 reads:

Code: Select all

<p class="MsoNormal" align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?=$searchResults?><?php echo $htmlCode; ?></font>
Can anyone confirm if this is a migration issue? And if it is, how might I resolve it?

Many thanks

FG

Re: PHP 5 migration issue?

Posted: Tue Aug 19, 2008 9:08 am
by nowaydown1
Welcome to the forum! It looks to me that your warning level is set a little higher than you would like. In your PHP configuration file there is an error_reporting directive. I believe you probably want E_ALL & ~E_NOTICE. Right now I would guess you're probably running with just E_ALL.

You can read more about the error_reporting setting here:
http://us.php.net/manual/en/errorfunc.configuration.php

Hope that helps!

Re: PHP 5 migration issue?

Posted: Tue Aug 19, 2008 10:05 am
by farmersguide
nowaydown1 wrote:It looks to me that your warning level is set a little higher than you would like. In your PHP configuration file there is an error_reporting directive. I believe you probably want E_ALL & ~E_NOTICE. Right now I would guess you're probably running with just E_ALL.
Many thanks, you were absolutely right and the pesky notices are no longer an issue.

Re: PHP 5 migration issue?

Posted: Wed Aug 20, 2008 3:28 am
by jmut
Not that I want to be picky or something but I strongly suggest you don't remove those noticy by supressing error_reporting. Your best bet is to fix thouse. Other than that you should just have display_errors no on production environment... this will allow for errors/notices or whatever not to be seen but still be logged (if logging enabled of course). By hiding this problem now, you might totally misunderstand a problem in the future that might be related.

Re: PHP 5 migration issue?

Posted: Wed Aug 20, 2008 6:56 am
by farmersguide
jmut wrote:I strongly suggest you don't remove those noticy by supressing error_reporting. Your best bet is to fix thouse.
It certainly occurred to me that hiding the issue was second-best to fixing it, but as a site manager with a boss demanding that the notices be removed because it affected the user experience, it was a useful first step.
As a postscript, it emerged that the notices - and several othe problems - were all related to a PHP4 to PHP5 upgrade by our webhosts late last week. The original site developer was persuaded to fix all the issue and as of this morning everything is working properly again.

Re: PHP 5 migration issue?

Posted: Wed Aug 20, 2008 8:33 am
by Corvin
farmersguide wrote:As a postscript, it emerged that the notices - and several othe problems - were all related to a PHP4 to PHP5 upgrade by our webhosts late last week.
The notice appeared because your PHP4 installation was configured to surpress notices, but not your PHP5 installation. The notice appears when you do this for example:

Code: Select all

$i++;
instead of

Code: Select all

$i = 0;
$i++;
So your lazy developer caused the notice and not the PHP update. :)

Btw. you should change your webhoster since he seems not to be aware of security risks.

Re: PHP 5 migration issue?

Posted: Wed Aug 20, 2008 9:48 am
by farmersguide
Corvin wrote: you should change your webhoster since he seems not to be aware of security risks.
Thanks for the advice - that's definitely something that's under consideration.

Re: PHP 5 migration issue?

Posted: Wed Aug 20, 2008 3:53 pm
by jmut
Just configure display_errors directive to be off in live environment. thats all. Users will never see problems. At very worst (fatal error) they will see blank screen. But you examining the logs will see it all (including notices etc). So bottom line:
1. Always have error_reporting (E_ALL) unless using some weird 3rd party lib that is <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> and you can't fix and don't want log cludge. For those I usually make wrapper that I can easily lower error_reporting only when calling specific method from 3rd party lib..and back to E_ALL then.
2. Have display errors off in production and enabled logging. Better in project dir than in server /tmp folder...those might get lost ;)
Glad you solved issue.