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
hermanrad...@gmail.com | http://hermanradtke.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to