Jump to content
Psytanium

Notice: Undefined variable allover the website after unknown server update

Recommended Posts

Hello,

Suddenly, without installing any addon or modifying anything, the website is showing "Notice: Undefined variable" in many front and back end pages, I think it's because the server did upgrade.

What could be the solution ?

For e.g.

Notice: Undefined variable: data1 in /home/domain/public_html/includes/modules/boxes/cm_nivo_slider.php on line 84
Notice: Undefined variable: button_act7 in /home/domain/public_html/includes/modules/boxes/cm_user_menu.php on line 86
Notice: Undefined variable: button_act6 in /home/domain/public_html/includes/modules/boxes/cm_user_menu.php on line 87

it looks like if the variable is empty, then a notice will appear. it wasn't like this before.

Any idea please ?

Share this post


Link to post
Share on other sites

Shop version?

Edit the error_reporting in includes/application_top.php in older versions.  Or in the configure.php files in the latest Phoenix.  Adding & ~E_NOTICE should suppress those messages.  If it is already there, this may require a conversation with your host. 

Turn off display_errors in php.ini or however your host does it.  This may require talking to your host, although some allow you to configure this yourself.  It may help to refer your host to https://stackoverflow.com/a/54215956


Always back up before making changes.

Share this post


Link to post
Share on other sites
1 minute ago, ecartz said:

Shop version?

Edit the error_reporting in includes/application_top.php in older versions.  Or in the configure.php files in the latest Phoenix.  Adding & ~E_NOTICE should suppress those messages.  If it is already there, this may require a conversation with your host. 

Turn off display_errors in php.ini or however your host does it.  This may require talking to your host, although some allow you to configure this yourself.  It may help to refer your host to https://stackoverflow.com/a/54215956

OSC 2.3.4

How can I fix the notices ? instead of hiding it ?

Share this post


Link to post
Share on other sites

Note that these notices have been there all along.  The update would only have revealed them.  Most likely by defaulting display_errors to on.  It should never be set on in production.  So you should get that turned off regardless. 

In general, replacing

$variable

with

(isset($variable) ? $variable : null)

will get rid of the notices.  However, this is essentially the same as just turning down the error reporting, as null is the default value of an undeclared variable.  The notice is basically telling you that it is doing this for you. The real fix is often to code the add-ons differently.  E.g. in

if (false) {
  $variable = 'value';
}

if ('value' == $variable) {

If those are the only two occurrences, you could fix this by

$variable = null;
if (false) {
  $variable = 'value';
}

if ('value' == $variable) {

But watch out that it isn't really

if (true) {
  $variable = 'default';
}

// doing $variable = null here would overwrite the previous value

if (false) {
  $variable = 'value';
}

if ('value' == $variable) {

Note that these statements do not have to be in the same file. 

There isn't a strictly mechanical solution.  Removing the notices properly requires understanding why they are shown and changing appropriately to that particular situation.  There isn't a simple rule to apply that would be better than turning down the error reporting. 

Sometimes the notice may be telling you that something is wrong.  E.g.

$typo = true;
if ($tyop) {

Which can be fixed by correcting the spelling in the second line. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

@Psytanium  If I may suggest, log into the Admin side of your shop, and select Tools -> Server Info. Tell us what version of PHP your host is running.

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites
3 minutes ago, ArtcoInc said:

@Psytanium  If I may suggest, log into the Admin side of your shop, and select Tools -> Server Info. Tell us what version of PHP your host is running.

Malcolm

PHP Version 5.6.40
MySQL 5.6.47-log
OSC2.3.4

Share this post


Link to post
Share on other sites

@Psytanium Thank you. I just wanted to make sure your host hadn't upgraded PHP to version 7.x.  Many hosts are moving to v7.x, which will break your version of osC.

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites
1 minute ago, ArtcoInc said:

@Psytanium Thank you. I just wanted to make sure your host hadn't upgraded PHP to version 7.x.  Many hosts are moving to v7.x, which will break your version of osC.

Malcolm

Ah yes.. I'm worried about this upgrade. Thx anyway

Share this post


Link to post
Share on other sites

This is going to be an ongoing problem for the foreseeable future for anyone on osCommerce 2.3.4 (and earlier) and for anyone on very early versions of the Community Edition. 

As hosts start to enforce php7 (as it is more stable and more secure than php5, and by the way php8 is soon out), we will see more and more shopowners who have run their shop only thinking about "today" rather than also thinking (at least a little) about "tomorrow" and what would happen "tomorrow" if their site went down for a day/week while they scramble about trying to get help with an outdated version or moving to a different platform etc.

The Community Edition has been available for over 6 years now - that's a lot of "tomorrow" time ;) 


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites
On 9/1/2020 at 8:24 PM, burt said:

This is going to be an ongoing problem for the foreseeable future for anyone on osCommerce 2.3.4 (and earlier) and for anyone on very early versions of the Community Edition. 

As hosts start to enforce php7 (as it is more stable and more secure than php5, and by the way php8 is soon out), we will see more and more shopowners who have run their shop only thinking about "today" rather than also thinking (at least a little) about "tomorrow" and what would happen "tomorrow" if their site went down for a day/week while they scramble about trying to get help with an outdated version or moving to a different platform etc.

The Community Edition has been available for over 6 years now - that's a lot of "tomorrow" time ;) 

Is there any documentation or forum topic that can help us migrate from 2.3.4 to the latest version ? Because I can't start a new website with all the hardcoded modifications and huge database. Thanks :)

Share this post


Link to post
Share on other sites
1 minute ago, Psytanium said:

Is there any documentation or forum topic that can help us migrate from 2.3.4 to the latest version ? Because I can't start a new website with all the hardcoded modifications and huge database. Thanks :)

No two sites from a decade or more ago are the same, therefore it is not possible to write a generic topic that would cover all sites.

Shopowners need to get out of the habit of jumping to core code changes and instead work out ways to have *similar* functionality without having to resort to core code modifications.  The old awful ways of getting better functionality (in 2.2) were alleviated a bit in the 2.3 series and have been *almost* removed in Phoenix (where it is possible to do most things without touching core).


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×