Category Archives: programming

How to read directory in PHP fast

We need to get a list of specific files from a directory.

Say we need to find all *.php files in our c:\inetpub\wwwroot folder. There are a couple of options to do it in PHP: opendir(), glob(), scandir() and RecursiveDirectoryIterator class. If we need to search through subfolders then the simplest solution in my opinion is to use the RecursiveDirectoryIterator class. Continue reading

How to iterate date and time in PHP

We need to iterate date and time between two predefined time moments with a predefined time step.

For example 30 minutes step

$start = new \DateTime(...);
$end = new \DateTime(...);
for ($temp=$start; $temp<=$end; $temp->add(new \DateInterval('PT30M')))
{..}

1 day step

for ($temp=$start; $temp<=$end; $temp->add(new \DateInterval('P1D')))
{..}

 

Constructor overloading in PHP

Method overloading is a partial case of polimorphism. With method overloading we can define different methods with the same name, and these methods can vary on type and a number of arguments. This is especially useful for class constructors. But PHP is a weak-type language and it does not allow several constructors in a class. How we can use method overloading in PHP even it is not a strong-type language?
Continue reading