Re: Recursive PHP method crashes Apache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Aaron Schiff wrote:
I call my method Assembler::PrefetchComponents with an array of valid
components and it crashes only when I include the line
"self::PrefetchComponents($dependencies);" Please help me solve the
error in this code.

The code below is an infinite loop. Unless there is an error (assuming Error::ThrowError halts execution), at no point does it return and at the end of the function it calls itself. This will never end. Apache crashes because it fills up the stack.

Here's Assembler::PrefetchComponents:

public static function PrefetchComponents($names)
{
	$failed = array();

	if(sizeof($m_arrComponents) > 0)
	{
		$names = array_filter($names,create_function('$var',
			'return(Assembler::GetComponentByName
			($var))==NULL;'));
	}

	$dependencies = array();

	foreach($names as $name)
	{
		if(self::TryIncludingComponent($name))
		{
			$dependencies = array_merge($dependencies,
				call_user_func(array("Component_$name",
				"Dependencies")));
		}
		else
		{
			$failed[] = $name;
		}
	}

	if(sizeof($failed)!=0)
	{
		sort($failed);
		Error::ThrowError(CBD_NO_COMPONENT, $failed);
	}

	self::PrefetchComponents($dependencies);
}

I'm thinking that last line should be...

        if (count($dependencies) > 0)
        {
                self::PrefetchComponents($dependencies);
        }

-Stut

--
http://stut.net/

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux