I have this PrestaShop install which shows the following errors on the front-end:
Notice: Undefined offset: 0 in /home/username/public_html/modules/categoriesnc/categoriesnc.php on line 1677
Warning: array_key_exists() expects parameter 2 to be array, null given in /home/username/public_html/modules/categoriesnc/categoriesnc.php on line 1677
Line 1677 in categoriesnc.php has:
for ($i = 2; $i <= ($max_depth > 0 && $max_depth < $depth ? $max_depth : $depth) && array_key_exists('lev'.$i, $result[0]); $i++)
$breadcrumbs[] = $result[0]['lev'.$i];
Any advise on how to resolve it?
You can turn error reporting off to not see the message any more. But that is a custom non standard Prestashop module, so I would contact the developer with the error. They are just warning messages and they will not hurt anything if they are not addressed.
Related
The error is in below lines of the addressed file below (Line 186 & 187):
Website (Live): www.healthyminds.world
Tried restoring an earlier back-up(24 hours back), but that didn't work also.
Line 186 & 187 from source line:
$collections = get_option('google_typography_collections');
$google_fonts_all = $this->get_fonts();
$import_fonts = array();
if ($collections) {
foreach ($collections as $collection) {
$font_family = $collection['font_family'];
$font_index = array_search($font_family,
array_column($google_fonts_all,'family'));//Line 186
$font_variants = implode(',', $google_fonts_all[$font_index ['variants']); //Line 187
array_push(
$import_fonts,
array(
'font_family' => $collection['font_family'],
'font_variant' => $font_variants,
Error Messages (On All Pages Of Website, these are just few of the lines):
content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: array_search() expects parameter 2 to be array, null given in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: Illegal string offset 'variants' in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
Warning: implode(): Invalid arguments passed in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
You are getting the errors because on line 186 the $google_fonts_all either does not contain an array with 'family' key or it is not an array. In either case the expression, array_column($google_fonts_all, 'family'), returns empty.
You can extract the later expression into a variable:
$family = array_column((array)$google_fonts_all, 'family');
On the line 187, check for the isset( $google_fonts_all[$font_index]['variants'] ) either in a conditional statement or itenary.
Regards
Eliasu
Wisdom Labs has posted a patch to fix the problem.
We are getting a couple of notices in prestashop when customers add products to cart, namely the following:
Impossible to add the product to the cart.
textStatus: 'parsererror'
errorThrown: 'SyntaxError: Unexpected token < in JSON at position 0'
responseText:
Notice: Use of undefined constant id_customization_field_width - assumed
'id_customization_field_width' in
/home/public_html/override/controllers/front/CartController.php
on line 83
Notice: Use of undefined constant id_customization_field_height - assumed
'id_customization_field_height' in
/home/public_html/override/controllers/front/CartController.php
on line 83
The code (line 83) which this refers to is as follows:
/*add new customization cart*/
$id_customization = 0;
if ($this->_newCustomization && id_customization_field_width && id_customization_field_height) {
if ($this->context->customer->isLogged()) {
$id_adv = $this->context->cart->id_address_delivery;
} else {
$id_adv = 0;
}
Can anyone help with this? We can't seem to find where the issue lies.
what is:
id_customization_field_width
and
id_customization_field_height
is it possible that it is:
$id_customization_field_width && $id_customization_field_height
or
$this->id_customization_field_width && $this->id_customization_field_height
?
Does anyone have a clue what it is about this bit of php code that would cause an apache2 webserver with nginx to throw a server error 500?
function cycleColsDbl() {
static $cols = ['transparent;', '#efefef;'], $i = 0;
$selectCol = ($i++/2 % 2 == 0) ? 0 : 1;
return $cols['$selectCol'];
}
The server suexec.log spat out a rather nonsensical claim:
[2016-04-17 08:34:34]: uid: (10003/usr) gid: (1003/1003) cmd: cgi_wrapper
And error.log says nothing at all about this.
The 500 is thrown on page load so the function never actually gets called.
Ideas anyone?
This $cols['$selectCol']; will look for a key $selectCol, not 0 or 1. It would look for 0 or 1 if you didn't make it literal, i.e. remove the single quotes.
Also, static $cols = ['transparent;', '#efefef;'] is not correct syntax to create an array in PHP.
function cycleColsDbl() {
static $cols = array('transparent;', '#efefef;'), $i = 0;
$selectCol = ($i++/2 % 2 == 0) ? 0 : 1;
return $cols[$selectCol];
}
My code sometimes give code undefinet offset error.
Error:
[03-Sep-2015 13:06:44] NOTICE: "Undefined offset: 6"
File: /home/mdmeds/public_html/includes/pages/game/class.ShowBuildingsPage.php | Line: 111
and
[04-Sep-2015 17:38:57] NOTICE: "Undefined offset: 8"
File: /home/mdmeds/public_html/includes/pages/game/class.ShowBuildingsPage.php | Line: 111
This is the part of the code
$Element = $CurrentQueue[$QueueID - 2][0]; /**this give the error*/
$BuildEndTime = $CurrentQueue[$QueueID - 2][3];
unset($CurrentQueue[$QueueID - 1]);
$NewQueueArray = array();
foreach($CurrentQueue as $ID => $ListIDArray)
{
if ($ID < $QueueID - 1) {
$NewQueueArray[] = $ListIDArray;
} else {
if($Element == $ListIDArray[0] || empty($ListIDArray[0]))
continue;
$BuildEndTime += BuildFunctions::getBuildingTime($USER, $PLANET, $ListIDArray[0]);
$ListIDArray[3] = $BuildEndTime;
$NewQueueArray[] = $ListIDArray;
}
}
I read lot of articles about this kind of errors but i do not know how to fix my code. Can someone help me please ?
You are trying to play with indexes that you are not sure they even exist...
things like
$CurrentQueue[$QueueID - 2]
is a guess... Get to find another way..
In this piece of code $CurrentQueue[$QueueID - 2][0], the key is generated dynamically based on $QueueID. WHen you get the error, it means that the specified key is not available in the array $CurrentQueue.
To avoid such run time exceptions, you can do something like this
if (!empty($CurrentQueue[$QueueID - 2])) {
// the actual functionality goes here.
}
I am trying to run my cake shell script but the output looks like the following:
-bash-3.2$ ../cake/console/cake audit
../cake/console/cake: line 30:/root/site/app: is a directory
Array
(
[0] => /root/site/cake/console/cake.php
[1] => -working
[2] =>
[3] => audit
)
Notice: Uninitialized string offset: 0 in /root/site/cake/console/cake.php on line 550
What am I doing wrong? Here are the contents of this file:
cake.php
function __parseParams($params) {
$count = count($params);
for ($i = 0; $i < $count; $i++) {
if (isset($params[$i])) {
if ($params[$i]{0} === '-') {
$key = substr($params[$i], 1);
$this->params[$key] = true;
unset($params[$i]);
if (isset($params[++$i])) {
if ($params[$i]{0} !== '-') {//This is line 550
$this->params[$key] = str_replace('"', '', $params[$i]);
unset($params[$i]);
} else {
$i--;
$this->__parseParams($params);
}
}
} else {
$this->args[] = $params[$i];
unset($params[$i]);
}
}
}
}
Focus on the first error
Whenever debugging something that's broken, it's a good idea to focus on the first error and not the fallout from it. The first error message is this line:
line 30:/root/site/app: is a directory
It comes from the cake bash script, before calling php. That line in the most recent 1.3 version is blank, so it's not obvious what specific version of cake you are using, but it isn't the latest 1.3 release.
The consequence of the above error is that the following is the command called:
exec php -q "/root/site/cake/console/"cake.php -working "" "audit"
^^
The parameters passed to cake.php specify that the working directory is an empty string, something which is abnormal and later causes an undefined index error.
Upgrading cures all ailes
Most likely, this specific error can be solved by copying cake.php from the latest version of the same release cycle you are using.
Also consider simply upgrading CakePHP itself to the latest release (from the same major version in use) which will likely fix this specific problem, and others - especially relevant if there have been security releases, which recently there have been.