1
timgno
Bug recurring
  • 2013/6/5 11:06

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


I have found that building modules during the test of TDMCreate, I get errors on the type of programming adopted for foreach loops.

If I use the php function array_keys() and I have a null value, this function generates the following warning:

Warningarray_keys() expects parameter 1 to be array, null given in file /class/xoopsform/grouppermform.php line 129
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 129
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
array_keys() expects parameter 1 to be array, null given in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
array_keys() expects parameter 1 to be array, null given in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
array_keys() expects parameter 1 to be array, null given in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266


while if use, in foreach, the type (array as $k => $v), not only solve the problem of container null, but the performance is better.

WarningInvalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 129
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 253
Warning
Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 266


So at this point I was wondering if it would be inappropriate for aray_keys() function in the next versions of xoops we can be taken of this metod of writing code.

If you look on the php manual, you will notice the same thing that I have shown you some examples of users.

We want to create the appropriate function that can do this

This problem I found with the class grouppermform.php, although the results in hand, I would like to know if any of you has the same effect.

2
zyspec
Re: Bug recurring
  • 2013/6/5 13:50

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


@timgno,

My question is why does the TDMCreate code call render when there are no permission items to render? Seems to me the code should check to see if there's anything to render before it tries.

The problem with array_keys on line 129 can be solved by initializing '_itemTree'.
For now you should be able to get rid of this error by changing ./class/groupperrmform.php line 44 in XOOPS 2.5.5 or XOOPS 2.5.6 to:

var $_itemTree = array();


This should also make all of the foreach() warnings on line 129 disappear but there will need to be additional changes needed in the core to get rid of the rest of the issues.

I'd recommend you submit this to the SVN bug tracker and have one of the core developers look at this for a future release.

3
timgno
Re: Bug recurring
  • 2013/6/5 15:43

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


It came out of this was there too,

zyspec you're right that, I should report it in svn now

I will, because we can not change the codes in all modules as he did in his trabis.

4
irmtfan
Re: Bug recurring
  • 2013/6/7 2:10

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


IMO it is not a bug but an inappropriate usage of core functions in a module.
while you received php errors and warning you should solve it yourself.
Core cannot check everything otherwise codes will be huge.
IMO a program should just have facilities to show errors and warnings in every bad usage.
eg: i will receive errors when i use this code:
if(empty($myClass->myMethod()))


Fatal error: Can't use method return value in write context in ...

So i have to change my codes and i cannot send bug to php.net


@zyspec:
Your improve is nice. IMO We should have it in the 2.5.7

But still i think it is just an improvement.
we cannot call it a bug and a fix is not needed

5
zyspec
Re: Bug recurring
  • 2013/6/7 2:20

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


@irmtfan,

In general terms I agree with you but in this instance the fix for the array_keys issue is solved by initializing a variable, which is good to do anyway.

The remaining issues can be reviewed by the core dev's to see if there's an acceptable solution to help with the foreach() warnings. If so, great! If not, then the warning should suffice.

6
timgno
Re: Bug recurring
  • 2013/6/7 9:25

  • timgno

  • Module Developer

  • Posts: 1504

  • Since: 2007/6/21


To work around this problem, volten added to the file admin/permissions.php, in the news module, the general permissions.php, so the offset will always be set to at least one.

And if I did not want to force the general permissions in my module?

Login

Who's Online

176 user(s) are online (107 user(s) are browsing Support Forums)


Members: 0


Guests: 176


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits