Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2013-10-09 15:19:46

LakeXeno
Member
From: La Crosse, WI, USA
Registered: 2013-07-05
Posts: 65
Website

Forum error started this morning? foreach()

Warning: Invalid argument supplied for foreach() in /xxx/index.php on line 96:

foreach ($new_topics[$cur_forum['fid']] as $check_topic_id => $check_last_post)

I did install Flux Rewrite Essentials yesterday, can it stem from that?

Last edited by LakeXeno (2013-10-09 15:20:06)


The Tiger Society Door
Have the Will to Change the world.

Offline

#2 2013-10-09 15:28:05

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,719
Website

Re: Forum error started this morning? foreach()

If that's the only thing you did yesterday, that mod will probably be the origin. Code doesn't change itself wink

Have you double checked that you installed everything correctly?


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2013-10-09 15:29:13

LakeXeno
Member
From: La Crosse, WI, USA
Registered: 2013-07-05
Posts: 65
Website

Re: Forum error started this morning? foreach()

Franz wrote:

If that's the only thing you did yesterday, that mod will probably be the origin. Code doesn't change itself wink

Have you double checked that you installed everything correctly?

Going through my 3rd time lol. smile

I'm considering just commenting out that function atm lol.

Last edited by LakeXeno (2013-10-09 15:33:42)


The Tiger Society Door
Have the Will to Change the world.

Offline

#4 2013-10-16 22:00:37

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,719
Website

Re: Forum error started this morning? foreach()

Okay, I have to take that back. This error might actually start appearing just like that, because the code has to do with the tracking data from cookies, which depends on the time you last visited etc.

This code will be refactored as part of ticket #810, so this should be fixed soon. smile

(The code is somewhat mind-boggling, I'm not really sure what exactly is going wrong, but there's plenty of opportunity in there.)


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#5 2013-11-16 23:48:51

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Forum error started this morning? foreach()

I started receiving this error today out of the blue, my forum has 39,000 posts.

I managed to resolve the issue using the following fix http://fluxbb.org/development/core/tick … #qb54cwz22, but can I ask if there will be any future side effects from doing this? Is the code included in this ticket going into core in the future or have you got an alternative fix that I should be using?

I have not idea why it started happening, everything was working fine then just started reciving the following error for no reason

Warning: Invalid argument supplied foreach () in /xxxxxxxxx on line 101

Which indicates a problem here

foreach ($new_topics[$cur_forum['fid']] as $check_topic_id => $check_last_post)
		{

Squiggles.

Offline

#6 2013-11-18 01:47:24

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Forum error started this morning? foreach()

I think I found an issue. The new posts indicator on the forum homepage (index.php) doesn't clear after viewing new posts.

Anyone got a fix? it's kind of urgent hmm

Offline

#7 2013-11-18 01:56:16

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Forum error started this morning? foreach()

Now here's the really strange part.. I just replaced index.php with my original file (the one throwing the error) and guess what? there's no error anymore yikes

Obviously the new posts indicator is working now but it's got me buggered as to what happened.

Thoughts?

Offline

#8 2013-11-19 00:55:38

quy
Administrator
From: California
Registered: 2008-05-09
Posts: 926

Re: Forum error started this morning? foreach()

When it happened, did you get this error once or repeatedly during your visit? How often has this happened to you?

The new posts indicator on the forum homepage (index.php) doesn't clear after viewing new posts.

Are you certain about this? Can you reproduce it?

Offline

#9 2013-11-19 01:53:18

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Forum error started this morning? foreach()

The error was only presented to Moderators and Members, not visible to the Administrator or Guests. The error was displayed 3 times on the page starting from about 1/4 way down the page. Basically replaced the category title with an error message, but not for all categories. Really weird.

I am certain the new posts indicator wasn't clearing, I tried multiple web browsers, cleared the Fluxbb cache and did a hard refresh. Same result.

I should have taken a screenshot but I was frantically trying to get the problem resolved.

Offline

#10 2013-11-19 04:41:01

quy
Administrator
From: California
Registered: 2008-05-09
Posts: 926

Re: Forum error started this morning? foreach()

If you immediately reload the index page after seeing the error, do you get the error again?

Have you added any modifications to the index page?

Last edited by quy (2013-11-19 05:32:07)

Offline

#11 2015-01-28 14:06:47

mikaw
Member
Registered: 2011-12-20
Posts: 12
Website

Re: Forum error started this morning? foreach()

I got similar error after installing the newest version of the FluxBB (1.5.8). This time below Quick reply there's an error:

Warning: Invalid argument supplied for foreach() in /home/x/forum/include/addons.php on line 29

It also appears after that redirection when posting a message. Everything works though...

Sometime last year I did have one addon for a while but I did remove it. Chances are there might something but everything have been working really well.

Any ideas what what I should look for?

Offline

#12 2015-01-28 14:56:57

GWR
Member
From: Germany
Registered: 2010-08-06
Posts: 214

Re: Forum error started this morning? foreach()

The problem is the following:

- glob() is not available on all platforms (that is why there are other file traversal functions in php)
- glob() might return "false" in the case of a failure ... a "false" cannot get used as foreach-iterator-source
- glob() might return false if something like directory access is not possible - or which is more likely: you have no files stored in the "addon" directory

So what you can try is to open up "include/addons.php" and replace the following code

	function load()
	{
		$this->loaded = true;

		foreach (glob(PUN_ROOT.'addons/*.php') as $addon_file)

with

	function load()
	{
		$this->loaded = true;

		$addon_files = glob(PUN_ROOT.'addons/*.php') or array();
		foreach ($addon_files as $addon_file)

If that helps, the only problem you had was the empty directory.

bye
Ron

Last edited by GWR (2015-01-28 14:58:49)

Offline

#13 2015-01-28 15:07:22

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,381
Website

Re: Forum error started this morning? foreach()

Offline

#14 2015-01-28 20:55:12

mikaw
Member
Registered: 2011-12-20
Posts: 12
Website

Re: Forum error started this morning? foreach()

I tried to the change the code but it didn't help. In addons-directory there is the index.html -file which came with the package.

Offline

#15 2015-01-29 08:05:12

chris98
Member
From: England, United Kingdom
Registered: 2013-05-31
Posts: 1,292
Website

Re: Forum error started this morning? foreach()

That's just to stop people from typing example.com/addons and seeing what files you have there.

Offline

#16 2015-01-29 08:22:08

GWR
Member
From: Germany
Registered: 2010-08-06
Posts: 214

Re: Forum error started this morning? foreach()

Did you try to show all warnings/errors?

Is the error still on the line with the "glob" ?

in that case you might think of replacing

	function load()
	{
		$this->loaded = true;

		foreach (glob(PUN_ROOT.'addons/*.php') as $addon_file)

with

	function load()
	{
		$this->loaded = true;

		$addon_files = array();
		$addon_path = PUN_ROOT.'addons';
		if (file_exists($addon_path) && $handle = opendir($addon_path))
		{
			while (false !== ($entry = readdir($handle)))
				if (preg_match('/\.php$/', $entry))
					$addon_files[] = $addon_path . '/' . $entry;
			closedir($handle);
		}
		foreach ($addon_files as $addon_file)

If this still does not work, then you did not check readability of the folder enough - make sure you enabled all warnings and errors and checked what really fail in the script.


bye
Ron

Offline

#17 2015-01-29 21:20:05

mikaw
Member
Registered: 2011-12-20
Posts: 12
Website

Re: Forum error started this morning? foreach()

This last code change worked (for my forum). In here I don't have control to the server side so I guess this is the way from now on?

Theoretically possibility to get/guess the account name from the directory string might help someone. In this case the error message was shown even when I trid to check the main site without login.

Visman suggested a ticket...

Offline

#18 2015-02-01 03:24:46

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,381
Website

Re: Forum error started this morning? foreach()

Offline

#19 2015-02-01 10:07:53

GWR
Member
From: Germany
Registered: 2010-08-06
Posts: 214

Re: Forum error started this morning? foreach()

@Visman

your code wont work for people who try to use the addons, but somehow are not able to use "glob" (which seems to be an issue on some setups).

My suggested code should work for them.


bye
Ron

Offline

#20 2015-02-01 10:45:36

Visman
Member
From: Siberia
Registered: 2010-07-10
Posts: 1,381
Website

Re: Forum error started this morning? foreach()

GWR, this is not my code wink Author - Quy.

Offline

#21 2015-02-01 12:10:36

GWR
Member
From: Germany
Registered: 2010-08-06
Posts: 214

Re: Forum error started this morning? foreach()

Sorry, I do not know whose nicknames belong to whom ... different platforms, different names (sometimes).

I posted my replacement as comment in the linked commit.


bye
Ron

Offline

#22 2019-09-13 00:23:01

JJones
Banned
Registered: 2019-04-28
Posts: 63

Re: Forum error started this morning? foreach()

why is glob still being used?

foreach (new DirectoryIterator(ROOT.'addons/') as $fileInfo)

Just the addons Dir?

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ROOT.'addons/', RecursiveDirectoryIterator::SKIP_DOTS)) as $fileInfo)

or do you want everything including all directories inside of the addons Dir?

It would be a MUCH better idea to build an array and fill it with whatever data you want from inside the loop ... and then save it your cache system.... to stop from even having this 1 loop on every plugin search ...

Offline

Board footer

Powered by FluxBB