xoops forums

timgno

Module Developer
Posted on: 2013/6/5 11:06
timgno
timgno (Show more)
Module Developer
Posts: 1504
Since: 2007/6/21
#1

Bug recurring

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.

zyspec

Module Developer
Posted on: 2013/6/5 13:50
zyspec
zyspec (Show more)
Module Developer
Posts: 1042
Since: 2004/9/21
#2

Re: Bug recurring

@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.

timgno

Module Developer
Posted on: 2013/6/5 15:43
timgno
timgno (Show more)
Module Developer
Posts: 1504
Since: 2007/6/21
#3

Re: Bug recurring

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.

irmtfan

Module Developer
Posted on: 2013/6/7 2:10
irmtfan
irmtfan (Show more)
Module Developer
Posts: 3419
Since: 2003/12/7
#4

Re: Bug recurring

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

zyspec

Module Developer
Posted on: 2013/6/7 2:20
zyspec
zyspec (Show more)
Module Developer
Posts: 1042
Since: 2004/9/21
#5

Re: Bug recurring

@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.

timgno

Module Developer
Posted on: 2013/6/7 9:25
timgno
timgno (Show more)
Module Developer
Posts: 1504
Since: 2007/6/21
#6

Re: Bug recurring

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?