People, I'm in doubt about whether it is me or my computer that is slow here.
I've following coding piece:
class Whatever
{
...
private function requireFile($filePath)
{
if(is_array($filePath))
foreach($filePath as $singleFilePath)
if($this->requireFile($singleFilePath))
break;
elseif(($filePath = stream_resolve_include_path($filePath = $filePath . '.php')) !== false)
return require_once $filePath;
}
}
Besides being an ugly code, it doesn't work as expected. The idea here is to make this method to accept both string and array of strings as parameter and, in case of an array, recurse over itself to work on each of strings.
What is happening it that, when provided an array as parameter, both if and elseif
block are executed, and thus making PHP parser to shout that it's occurring an array to string conversion in elseif
line.
I'm not understanding why adding brackets around if
block (putting them around foreach
or inside if
doesn't change anything) is making everything to work like a charm, since there is only one statement below if
and thus it's not needed to have them there:
class Whatever
{
...
private function requireFile($filePath)
{
if(is_array($filePath)) {
foreach($filePath as $singleFilePath)
if($this->requireFile($singleFilePath))
break;
} elseif(($filePath = stream_resolve_include_path($filePath = $filePath . '.php')) !== false)
return require_once $filePath;
}
}
Can somebody help me here? What's wrong in this code?
Edit: thanks folks. I guess your answers proves that it was me the slow one here, hahaha. Months away from programming makes people to write crazy stuff...