[] operator not supported for strings

henk

Member
When I want to Add an item in a list on the front-end I get this error:

[] operator not supported for strings in ...\components\com_fabrik\models\form.php on line 4900

It occurs in all PHP versions (5.6.19 7.0.25 7.1.11)
Does not occur in the back-end though and also not when protostar template for front-end is used.

Seems that class[] = 'fabrikGroup'; on line 4900 is causing problem.
Maybe class[] needs to be initialized first? (as I read on other forums)

class[] is also used in ...\components\com_fabrik\models\list.php and ...\components\com_fabrik\models\element.php

I saw there was already a thread about the same error, but the solution does not seems to work in my case.
 
Yes, that's the threat I mean.
I have the latest fabrik (3.8) from github on Joomla 3.8.1
So the fix should be in, but I still have the error.
 
Thanks for looking at it Hugh.

I checked and I do see this code on line 992. I even downloaded and updated the latest fabrik from github, just to be sure. Still have this error.
The strange thing is that it seems template depended, but I cannot discover what happens here.
There is a little difference when I use PHP 5.6 (see picture) This gives me some more info as the 7.0 and 7.1 simply say [] operator not supported for strings.

Do you have any idea what could be the reason for this error?
 

Attachments

  • operator-error.PNG
    operator-error.PNG
    68.8 KB · Views: 42
When you say "template dependent" do you mean J! or Fabrik template?

And which one(s) don't work?

It's weird, I really can't see anything in the code which would change depending on the template. The form model calls getGetProperties() at line 4741, which sets $group->class as an array (that line 992 in the group model) and nothing else touches it until line 4900.

-- hugh
 
OK. I just found I did something quite wrong (I had some weird thinking here). I setup the list with a right join to a related table. Then adding a record also adds a record to this related table, which is not what I want.

When I changed things back the way they should, the problem did not occur anymore.

Henk
 
Last edited:
line 992 in group.php is only run
if (!isset($this->groupProperties))

It seems groupProperies are additionally set (or overridden) somewhere else with ->class not defined or defined as string.

Can you answer Hugh's question
When you say "template dependent" do you mean J! or Fabrik template?

And which one(s) don't work?
So Bauer's code makes sense as additionl defensive coding.
But it would be good to find the reason behind.
 
Last edited:
It seems groupProperies are additionally set (or overridden) somewhere else with ->class not defined or defined as string.

But that's just it, there isn't anything. The only code that sets the group model's groupProperties is getGroupProperties(). According to PHP Storm (which I trust), the string groupProperties is used 3 times in the entire project, all within getGroupProperties(). And groupProperties is a protected class variable, so only the group model can see it - it's just a cache, so we don't rebuild the properties if we've already built them (getGroupProperties can be called from the element preRender() function, as well as from the form model).

That said, we're doing something that isn't really "best practise" (converting a variable in place from array to a string) so I've modified it a little so we have a separate classArray and class variable. I'll commit the changes when I've run them for a day or two.

-- hugh
 
A bout that "template dependent":
I only have this error on one site on the front-end and not on the back-end.
I have another (local) site where I don't have this error.
Both sites have the same and the latest joomla and fabrik version.
Only the first site uses a different front-end template, the second site uses protostar.
So that's why it looks to me template dependent.

I agree it's realy a strange error that should not occur.
I have other extensions installed on the first site as well and not on the second site. Maybe they are the cause of this?

I could copy the first site to local and run a debugger on it.
Is there a smart way to debug this?

Henk
 
I'll be committing a change later today that would prevent this from happening under any circumstance.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top