Zen Cart Logo
Forums / Code Collaboration / Cannot use string offset as an array?

Cannot use string offset as an array?

Views: 4,899

Results 1 to 7 of 7
10 Feb 2018, 7:41 AM
#1
tmccaff avatar

tmccaff

Zen Follower

Join Date:
Jan 2018
Posts:
157
Plugin Contributions:
0

Cannot use string offset as an array?

I am not sure what mod this is from but it has to do with additional images; I think it's from Zen lightbox.

When I add additional images in the admin and go to my store I get this error in my log. I am guessing because of php7.

PHP Fatal error: Uncaught Error: Cannot use string offset as an array

$image_regular = zen_image($products_image_medium, $products_ar['products_name'], $width, $height, 'class="adt-img"');
		$large_link = zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $products_id . '&pic=' . $i . '&products_image_large_additional=' . $products_image_medium, 'SSL');
		$script_link = '<a href="'.$product_link.'" title="' . $products_ar['products_name'] . '">' . $image_regular .'</a>';
		// List Box array generation:
		$list_box_contents[$row][$col] = array('params' => 'class="item "', 'text' => array("imglink"=>$script_link, "img"=>$image_regular));
		$col ++;
		if ($col > (IMAGES_AUTO_ADDED -1)) {
		  $col = 0;
		  $row ++;
		}
10 Feb 2018, 7:49 AM
#2
tmccaff avatar

tmccaff

Zen Follower

Join Date:
Jan 2018
Posts:
157
Plugin Contributions:
0

Re: Cannot use string offset as an array?

I think its from Image Handler nevermind

10 Feb 2018, 8:04 AM
#3
tmccaff avatar

tmccaff

Zen Follower

Join Date:
Jan 2018
Posts:
157
Plugin Contributions:
0

Re: Cannot use string offset as an array?

I am guessing need to add $list_box_contents = array();

10 Feb 2018, 12:35 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Cannot use string offset as an array?

tmccaff:

I am not sure what mod this is from but it has to do with additional images; I think it's from Zen lightbox.

When I add additional images in the admin and go to my store I get this error in my log. I am guessing because of php7.

PHP Fatal error: Uncaught Error: Cannot use string offset as an array

$image_regular = zen_image($products_image_medium, $products_ar['products_name'], $width, $height, 'class="adt-img"');
$large_link = zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $products_id . '&pic=' . $i . '&products_image_large_additional=' . $products_image_medium, 'SSL');
$script_link = '<a href="'.$product_link.'" title="' . $products_ar['products_name'] . '">' . $image_regular .'</a>';
// List Box array generation:
$list_box_contents[$row][$col] = array('params' => 'class="item "', 'text' => array("imglink"=>$script_link, "img"=>$image_regular));
$col ++;
if ($col > (IMAGES_AUTO_ADDED -1)) {
$col = 0;
$row ++;
}

Hold up there buck-a-roo.
Once (twice? Or third time?) again, there is insufficient information provided to begin to help...
Here is why I say that:
There is a problem with an array assignment (jist of the error message), almost 50% of the provided lines of code have an array in them.
If there was some sort of formatting applied internal to the snippet of code to try to point out which line was the problem, well the ```
[PHP][/PHP] tags were used instead of [CODE][/CODE] tags
``` the tags used offer syntax formatting which yes can help identify say unbalanced quotes and other general syntax errors (forgot a $ at the start of a variable, etc...)
The description of the process of the log generation doesn't identify at what point in the process the log is generated (ie. If it is an admin mydebug log or a catalog mydebug log)
There is no identification in this post about what ZC version is involved and other than possibly blaiming another plugin it is not identified what else is installed but then shortly after this a similar message (double posting) has been posted to Image Handler 4.
As to "fault", php7 and above is where the php community is going. The majority of issues "raised" in php7 are for the most part preventable at early php 5 if not php 4 days, but... it is only/mostly now in php 7 that the expectations of programmers and code are stricter. This is a good thing.

So, okay all that above, but that's just what's made available here, those that have read other posts or followed along or had similar comments would expect to be able to say that we're talking about ZC 1.5.5 I thought sub-version f was applie, I could be wrong. At any rate, as another note where one needs to read as part of installation, IH4 was basically abandoned at the point of ZC 1.5.5 and a new version generated that has its own support thread. Meaning, if you are using ZC 1.5.5 then you should be using IH5 not IH4 which would likely be part of the problem from above.

Beyond that, more than likely one of those "array" variables was previously declared as a string which was the "old" way to declare such empty values. Afterall, a string is/was an array of characters right?
So you would look for a condition like $array_name = ''; somewhere above what has been provided because there is no initial code assignment in the above snippet.
11 Feb 2018, 1:09 AM
#5
tmccaff avatar

tmccaff

Zen Follower

Join Date:
Jan 2018
Posts:
157
Plugin Contributions:
0

Re: Cannot use string offset as an array?

I searched for Image handler and only found Image handler 4 not 5. Do you know where it's located?

11 Feb 2018, 1:21 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Cannot use string offset as an array?

tmccaff:

I searched for Image handler and only found Image handler 4 not 5. Do you know where it's located?
Why, unlike image handler 2, 3, and 4 it doesn't show up on a simple search for image handler (other than the added -5) I'm not sure, but the download area is: https://www.zen-cart.com/downloads.php?do=file&id=2169