A book I'm reading has this code but cant understand why so many backslashes in preg_match
. The first \ might mean to match literal backslash but why two more in the expression?
This is code to "provide namespace support" with autoload:
// listing 05.18
$namespaces = function ($path) {
if (preg_match('/\\\\/', $path)) {
$path = str_replace('\\', DIRECTORY_SEPARATOR, $path);
}
if (file_exists("{$path}.php")) {
require_once("{$path}.php");
}
};
\spl_autoload_register($namespaces);
$obj = new util\LocalPath();
$obj->wave();