Page 1 of 1

Illegal String offset 'is_variation' error - wots the cause?

Posted: Tue Nov 21, 2017 7:42 am
by simonmlewis
[text][20-Nov-2017 03:30:28 UTC] PHP Warning: Illegal string offset 'is_variation' in /var/www/vhosts/domain.co.uk/httpdocs/wp-content/plugins/improved-variable-product-attributes/includes/ivpa-frontend.php on line 741[/text]

Line 741 is:

Code: Select all

if ( $v['is_variation'] == '1' ) { ... 
This is that section.

Code: Select all

					foreach ( $available_attributes as $k => $v ) {
						if ( $v['is_variation'] == '1' ) {
							if ( isset($curr_customizations['ivpa_attr']) && is_array($curr_customizations['ivpa_attr']) && in_array(self::utf8_urldecode( $k ), $curr_customizations['ivpa_attr']) ) {
								$ready_customization[array_search(self::utf8_urldecode( $k ), $curr_customizations['ivpa_attr'])] = $k;
							}
							else {
								$keep_customization[$k] = $k;
							}
						}
						else {
							if ( self::$settings['wc_settings_ivpa_simple_support'] !== 'none' ) {
								if ( isset($curr_customizations['ivpa_attr']) && is_array($curr_customizations['ivpa_attr']) && in_array(self::utf8_urldecode( $k ), $curr_customizations['ivpa_attr']) ) {
									$rCid = array_search(self::utf8_urldecode( $k ), $curr_customizations['ivpa_attr']);
									if ( isset( $curr_customizations['ivpa_svariation'][$rCid] ) && $curr_customizations['ivpa_svariation'][$rCid] == 'yes' ) {
										$ready_customization[$rCid] = array( 'slug' => $k, 'custom' => true );
									}
								}
								else {
									if ( self::$settings['wc_settings_ivpa_simple_support'] == 'full' ) {
										$keep_customization[$k] = array( 'slug' => $k, 'custom' => true );
									}
								}
							}
						}
					}
This is on the latest woocommerce and WP 4.9.

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Tue Nov 21, 2017 8:57 am
by requinix
The message means that $v is a string.

If that's supposed to be possible then you could

Code: Select all

if ( is_array($v) && $v['is_variation'] == '1' ) {
If that's not supposed to be possible then, well, obviously, fix it.

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Tue Nov 21, 2017 9:25 am
by simonmlewis
If I change it to that, the icons that show the colour swatches don't appear on the category or product pages. We are awaiting an answer from the plugin people, but it's taking time.
This is the plugin:
https://codecanyon.net/item/improved-va ... 1511197223

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Tue Nov 21, 2017 9:51 am
by requinix
So maybe you try tweaking the logic of what I wrote just a tiny little bit to make it work the way you want?

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Tue Nov 21, 2017 9:58 am
by simonmlewis
I'm not sure about it - I didn't write it. I'm guessing you have a sense of what tiny adjustment could be made.

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Tue Nov 21, 2017 7:48 pm
by requinix
If

Code: Select all

if ( is_array($v) && $v['is_variation'] == '1' ) {
isn't doing the customization thing, and you know that $v is a string (because of the error message), then that means the is_array($v) is not true. Which means the else branch will execute.

If you want the if branch to execute if $v is a string then you don't want if $v is an array and is_variation=1, but rather if $v is not an array or it is and is_variation=1.

Code: Select all

if ( !is_array($v) || $v['is_variation'] == '1' ) {
But that will also catch every other $v that is a string. But that might be what it should do.

Re: Illegal String offset 'is_variation' error - wots the ca

Posted: Wed Nov 22, 2017 10:30 am
by Christopher
simonmlewis wrote:I'm not sure about it - I didn't write it. I'm guessing you have a sense of what tiny adjustment could be made.
I'd recommend looking at what is in $available_attributes to see what you should be looking for. Use print_r() or var_dump() to see what the elements of $available_attributes actually are.