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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
Post Reply