I've been searching through this and other sites and can't solve the notice I got every time I open the back office product page.
Notice on line 279 in file /home/librer16/public_html/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code
[8] Array to string conversion
Piece of code:
...
else {
//var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
//Line 279
if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
// replace nocache_hash
$_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
$_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
}
}
...
The website works, but this notice is very annoying.
Any suggestion to remove the notice?
Try to replace the line with this one:
if (is_array($_template->properties) && !empty($_template->properties['nocache_hash']) && is_array($_template->parent->properties) && !empty($_template->parent->properties['nocache_hash']))
Anyway, if you deactivated Debug Mode warningins won't show anymore.
Good luck.
Related
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
?
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.
}
This works on my test environment, but on my live server there is a later version of PHP which is throwing up an error and breaking my program
The code is
$oldFile = fopen("D:/ftpfolderreport/report/" . $last_file, "r");
while(!feof($oldFile))
{
$buffler = fgets($oldFile);
$bufflerArray = explode(",", $buffler);
$key = $bufflerArray[0];
$oldFileArray[$key] = $bufflerArray[1];
}
fclose($oldFile);
This line:
$oldFileArray[$key] = $bufflerArray[1];
Is throwing out this error
Notice: Undefined offset: 1 in D:\apps\wamp\www\Compliance2\compareFtpReports.php on line 57
I think this is to do with how I'm adding the $key variable inside the argument. I've tried it as ["$key"] and ['$key'] but it doesn't like it.
I have tried defining the key variable earlier in the program but still doesn't like it. I've been searching around online but can't find anything of help. Anyone any ideas?
Thanks,
Stephen.
add checks for empty
if (!empty($bufflerArray[1])) {
$key = $bufflerArray[0];
$oldFileArray[$key] = $bufflerArray[1];
}
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.
I have a php script that interacts with the google weather api.Everything works ok, but if I test it with a false location like "blahblah" I get a slew of errors in the browser despite having some validation in my script. The php code is as follows:
<?php
function googleWeather($location){
$url = "http://www.google.com/ig/api?weather=" . urlencode($location);
$xml = simplexml_load_file($url);
$current_conditions = $xml->xpath("/xml_api_reply/weather/current_conditions");
$temp_c = $current_conditions[0]->temp_c['data'];
$temp_f = $current_conditions[0]->temp_f['data'];
$result = sprintf("Current temperature is %s° Celsius %s° Fahrenheit",$temp_c,$temp_f);
return $result;
}
$loc = "blahblah";
$goog = googleWeather($loc);
if($goog == false){
echo "An error occurred";
}
else{
echo $goog;
}
?>
The error that is rendered in the browser is as follows:
( ! ) Notice: Undefined offset: 0 in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 11
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Trying to get property of non-object in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 11
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Undefined offset: 0 in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 12
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Trying to get property of non-object in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 12
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
Google returns the following for an invalid location
<xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"><problem_cause data=""/></weather></xml_api_reply>
This xml doesnt have the element "current_conditions" inside "weather". Thats casusing the error.
Check if exists then proceed which can be done with some thing like
if($current_conditions){
// you code here
} else {
return false;
}
I replaced blahblah with real city and it started to work.
Probably you enter your city address with wrong syntax.
Try to change your location, for example Zurich
The errors are pretty self-explanatory, $current_conditions doesn't contain what you think it does:
$current_conditions = $xml->xpath("/xml_api_reply/weather/current_conditions");
$temp_c = $current_conditions[0]->temp_c['data'];
// ^^^ undefined index
$temp_f = $current_conditions[0]->temp_f['data'];
// ^^^ Trying to access property of non object
You are not validating the result of $current_conditions:
if (is_array($current_conditions) && isset($current_conditions[0]))
{
$temp_c = $current_conditions[0]->temp_c['data'];
$temp_f = $current_conditions[0]->temp_f['data'];
}
Furthermore, you may need to validate the existence of the object properties, as well as the existence of the data key in those properties:
if (is_array($current_conditions) && isset($current_conditions[0]))
{
$cur = $current_conditions[0];
if (isset($cur->temp_c) && isset($cur->temp_c['data']))
{
$temp_c = $cur->temp_c['data'];
}
if (isset($cur->temp_f) && isset($cur->temp_f['data']))
{
$temp_f = $cur->temp_f['data'];
}
}
This is quite verbose, but to be absolutely sure to avoid these notices - it's what you have to do. You can and should turn off error reporting once you go live with your application. Notices are meant to help you debug code, if you understand how they're being generated and can safely ignore them, it may be OK.
And, if you feel confident that you know the API will return FALSE for an invalid query, just check if $current_conditions === FALSE and you can skip all the extra validation.