6.0.0-git
2019-04-21

[#11949] PHP ERROR: Invalid argument supplied for foreach()
Summary PHP ERROR: Invalid argument supplied for foreach()
Queue Horde Base
Queue Version 5.0.3
Type Bug
State Not A Bug
Priority 1. Low
Owners
Requester zdrahal (at) ipnp (dot) troja (dot) mff (dot) cuni (dot) cz
Created 2013-01-11 (2291 days ago)
Due
Updated 2013-01-15 (2287 days ago)
Assigned 2013-01-15 (2287 days ago)
Resolved 2013-01-15 (2287 days ago)
Milestone
Patch Yes

History
2013-01-15 16:40:48 Jan Schneider Comment #6
State ⇒ Not A Bug
Reply to this comment
According to https://bugs.php.net/bug.php?id=47358 it is planned to 
get fixed in future PHP versions. Since this is also just a warning, 
and only a warning that is caused by administrative tasks, it doesn't 
make much sense to catch this rare case in userland code.
2013-01-15 16:13:25 zdrahal (at) ipnp (dot) troja (dot) mff (dot) cuni (dot) cz Comment #5 Reply to this comment
You are right, it is *supposed* to return an empty array. However, if 
the openbasedir is activated, the glob function returns false instead 
of an empty array. In the case some matching file exists, glob returns 
a populated array regardless of the activation of the openbasedir.
See e.g. 
http://stackoverflow.com/questions/9213249/behaviour-of-glob-function-in-php-is-different-with-open-basedir or 
https://bugs.php.net/bug.php?id=47358

According to PHP guys, searching for a non-existent file in the case 
openbasedir is activated should give an error and not the answer - 
there is no file matching your search (empty array).

So the system configuration required for occurrence of this error is 
non-existence of the files in the given directory and having 
openbasedir activated.
2013-01-15 15:24:26 Jan Schneider Comment #4 Reply to this comment
No, in this situation, glob() is supposed to return an empty array. It 
only returns false if there is some other error condition. But this 
should have created an earlier error messages.
2013-01-15 15:17:48 zdrahal (at) ipnp (dot) troja (dot) mff (dot) cuni (dot) cz Comment #3 Reply to this comment
And what *is* the system configuration this depends on?
I am sorry, I thought it is obvious from the description of the 
solution. In both of the cases the scripts are making lists of files 
in a given folder. The error occurs in the case such a folder does not 
contain any file that should be listed of if the directory does not 
even exist.
For instance the error in Config file occurs if there is no xml file 
in /var/horde/config/conf.d/ directory or if this directory does not 
exist and an administrator goes into Configuration->Configure Horde.
Similarly for the second error.
2013-01-15 14:19:42 Jan Schneider Comment #2
State ⇒ Feedback
Reply to this comment
And what *is* the system configuration this depends on?
2013-01-11 12:58:50 zdrahal (at) ipnp (dot) troja (dot) mff (dot) cuni (dot) cz Comment #1
Type ⇒ Bug
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Summary ⇒ PHP ERROR: Invalid argument supplied for foreach()
Queue ⇒ Horde Base
Milestone ⇒
Patch ⇒ Yes
New Attachment: Config.php.patch Download
Reply to this comment
On two places of the code there is used foreach without checking 
whether the argument is indeed an array. Depending on the system 
configuration, it leads to the following errors:
PHP ERROR: Invalid argument supplied for foreach() [pid 10297 on line 
59 of "/usr/share/php/Horde/Core/Db/Migration.php"]
PHP ERROR: Invalid argument supplied for foreach() [pid 10286 on line 
203 of "/usr/share/php/Horde/Config.php"]

The solution is simple - in both cases just add the check whether the 
variable is unempty and is an array.

Saved Queries