I wanted to include some files from a directory , so my code had :
foreach (glob("inc/*.php") as $filename)
{
include $filename;
}
This syntax is referenced almost in all related items on the net ( example question on SE )
But .. there were no results.
So I tried
foreach (glob(".inc/*.php") as $filename)
{
include $filename ;
}
and then :
foreach (glob("/inc/*.php") as $filename)
{
include $filename;
}
And finally I added dirname(__FILE__)
:
foreach ( glob( dirname(__FILE__) . '/inc/*.php' ) as $filename) {
include( $filename );
}
Which worked .
So everything is ok now ( no need to panic ) , but for the sake of understanding , I have some issues I want to clarify :
1 . Why did glob()
worked for me only when I added dirname(__FILE__)
?
2 . Is there a difference in syntax between *NIX and windows servers ?
3 . It is actually the first time I noticed the syntax include $filename
- where are the parenthesis ? why they are not needed in this context?