differences in the way spl_autoload() works on windows and *nix with namespaces

From: Date: Sat, 24 Oct 2009 16:27:31 +0000
Subject: differences in the way spl_autoload() works on windows and *nix with namespaces
Groups: php.internals 
Request: Send a blank email to internals+get-45877@lists.php.net to get a copy of this message
It appears that spl_autoload() has implicit namespace autoloading support on windows due to the fact that the namespace operator is the same as the directory separator on windows. For example, the class foo\Bar will evaluate to the path "foo\Bar.php" on windows. I think spl_autoload() should also implicitly work on *nix to avoid confusion and allow for portability. I have started a patch below. I can provide tests if this is agreeable. Patch: Index: ext/spl/php_spl.c =================================================================== --- ext/spl/php_spl.c (revision 289895) +++ ext/spl/php_spl.c (working copy) @@ -229,8 +229,28 @@ zval *result = NULL; int ret; - class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension); +#ifdef PHP_WIN32 + char *ns_name = estrndup(lc_name, class_name_len); +#else + char *ns_name; + if (strchr(lc_name, '\\')) { + ns_name = estrndup(class_name, class_name_len); + char *c = ns_name; + while(*c) { + if (*c == '\\') { + *c = '/'; + } + *c++; + } + } else { + ns_name = estrndup(lc_name, class_name_len); + } +#endif + class_file_len = spprintf(&class_file, 0, "%s%s", ns_name, file_extension); + + efree(ns_name); + ret = php_stream_open_for_zend_ex(class_file, &file_handle, ENFORCE_SAFE_MODE|USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); if (ret == SUCCESS) { -- Herman Radtke hermanradtke@gmail.com | http://hermanradtke.com

« previous php.internals (#45877) next »