Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51260 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10179 invoked from network); 12 Jan 2011 22:54:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2011 22:54:04 -0000 Authentication-Results: pb1.pair.com header.from=marc@easen.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=marc@easen.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain easen.co.uk from 74.125.82.54 cause and error) X-PHP-List-Original-Sender: marc@easen.co.uk X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:58707] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 86/DC-45151-B013E2D4 for ; Wed, 12 Jan 2011 17:54:04 -0500 Received: by wwb31 with SMTP id 31so1206057wwb.11 for ; Wed, 12 Jan 2011 14:54:00 -0800 (PST) Received: by 10.227.135.75 with SMTP id m11mr1605643wbt.122.1294872839873; Wed, 12 Jan 2011 14:53:59 -0800 (PST) Received: from [192.168.0.5] (5acccde2.bb.sky.com [90.204.205.226]) by mx.google.com with ESMTPS id f35sm878059wbf.14.2011.01.12.14.53.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 12 Jan 2011 14:53:58 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: multipart/alternative; boundary=Apple-Mail-11-885536587 Date: Wed, 12 Jan 2011 22:53:52 +0000 In-Reply-To: <4F372AC9-7C88-43E5-BCE1-58B5BFD34135@easen.co.uk> To: internals@lists.php.net References: <4F372AC9-7C88-43E5-BCE1-58B5BFD34135@easen.co.uk> Message-ID: <09CA4F51-E610-4070-ACF0-A35E8BE5EF1D@easen.co.uk> X-Mailer: Apple Mail (2.1082) Subject: Re: [PATCH] Bug #49852 & Bug #53065 - Adding spl_autoload_case_sensitivity() From: marc@easen.co.uk (Marc Easen) --Apple-Mail-11-885536587 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello again, Has anyone had a chance to look at my patch? Forgive me for being quite eager to get this into trunk, as it will = improve the performance of all PHP Frameworks which currently implement = their own autoloader method due to the oddities of the SPL autoloader. Kind Regards Marc On 26 Dec 2010, at 13:20, Marc Easen wrote: > Hello everyone, >=20 > Firstly I would like to introduce myself, my name is Marc Easen and = I've working with PHP for past 6 years or so. I'm really excited to see = where PHP is going with the addition of namespaces and now traits, and = hopefully I'm able to contribute back to PHP community. >=20 > I've currently working on a high performance PHP Framework based on = version 5.3.3+ (5.3.99-dev for traits). Due to the high performance = nature of this framework I've been looking at ways of improving the = loading of the classes. It seems by default the spl_autoload() function = lowercases the class name before trying to locate the file, a couples of = users have reported this previously and have requested a fix (bug #49852 = http://bugs.php.net/bug.php?id=3D49852 & bug #53065 = http://bugs.php.net/bug.php?id=3D53065). spl_autoload() lower casing the = class names when it is trying to locate the file does not work on *nix = based system in a lot of PHP Frameworks - Zend Framework being on of = them. >=20 > Understanding the requirement to support backwards compatibility both = submitters suggested implementing a spl_autoload_case_sensitivity() = function. The patch I have attached adds such a function to the SPL = extension. The patch is against trunk (r306670), it also includes phpt = tests for this function. >=20 > Please could someone review this patch and let me know what you think.=20= >=20 > Kind Regards, >=20 > Marc > --Apple-Mail-11-885536587 Content-Type: multipart/mixed; boundary=Apple-Mail-12-885536587 --Apple-Mail-12-885536587 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hello = again,

Has anyone had a chance to look at my = patch?

Forgive me for being quite eager to get = this into trunk, as it will improve the performance of all PHP = Frameworks which currently implement their own autoloader method due to = the oddities of the SPL autoloader.

= --Apple-Mail-12-885536587 Content-Disposition: attachment; filename=spl_autoload_case_sensitive.patch Content-Type: application/octet-stream; name="spl_autoload_case_sensitive.patch" Content-Transfer-Encoding: 7bit Index: ext/spl/spl.php =================================================================== --- ext/spl/spl.php (revision 306670) +++ ext/spl/spl.php (working copy) @@ -199,6 +199,16 @@ function spl_autoload_extensions($file_extensions) {/**/}; /** @ingroup SPL + * @brief Register and returns the use case sensitive file naming flag + * @since PHP 5.x + * + * @param use_case_sensitive_file_naming optional comma separated list of extensions to use in + * default autoload function. If not given just return the current list. + * @return bool the value of the case sensitive flag + */ +function spl_autoload_case_sensitive($use_case_sensitive_file_naming = null) {/**/}; + +/** @ingroup SPL * @brief Return all registered autoload functionns * @since PHP 5.1 * Index: ext/spl/tests/TestClassCS.php.inc =================================================================== --- ext/spl/tests/TestClassCS.php.inc (revision 0) +++ ext/spl/tests/TestClassCS.php.inc (revision 0) @@ -0,0 +1,12 @@ + \ No newline at end of file Property changes on: ext/spl/tests/TestClassCS.php.inc ___________________________________________________________________ Added: svn:executable + * Index: ext/spl/tests/spl_autoload_015.phpt =================================================================== --- ext/spl/tests/spl_autoload_015.phpt (revision 0) +++ ext/spl/tests/spl_autoload_015.phpt (revision 0) @@ -0,0 +1,70 @@ +--TEST-- +SPL: spl_autoload_case_sensitive() +--INI-- +include_path=. +--FILE-- + +===DONE=== +--EXPECTF-- +return spl_autoload_case_sensitive() == FALSE +Successfully set +Successfully set +===AUTOLOAD testclass_lc (cs = false)=== +%stestclass_lc.php.inc +bool(true) +===AUTOLOAD testclasscs (cs = true)=== +bool(false) +===AUTOLOAD TestClassCS (cs = true)=== +%sTestClassCS.php.inc +bool(true) +===DONE=== Index: ext/spl/tests/testclass_lc.php.inc =================================================================== --- ext/spl/tests/testclass_lc.php.inc (revision 0) +++ ext/spl/tests/testclass_lc.php.inc (revision 0) @@ -0,0 +1,9 @@ + \ No newline at end of file Property changes on: ext/spl/tests/testclass_lc.php.inc ___________________________________________________________________ Added: svn:executable + * Index: ext/spl/php_spl.c =================================================================== --- ext/spl/php_spl.c (revision 306670) +++ ext/spl/php_spl.c (working copy) @@ -59,6 +59,7 @@ spl_globals->autoload_extensions_len = 0; spl_globals->autoload_functions = NULL; spl_globals->autoload_running = 0; + spl_globals->autoload_case_sensitive = 0; } /* }}} */ @@ -219,17 +220,25 @@ } /* }}} */ -static int spl_autoload(const char *class_name, const char * lc_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */ +static int spl_autoload(const char *class_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */ { char *class_file; + char *ps_name; int class_file_len; int dummy = 1; zend_file_handle file_handle; zend_op_array *new_op_array; zval *result = NULL; int ret; + + if (SPL_G(autoload_case_sensitive) == 0) { + ps_name = zend_str_tolower_dup(class_name, class_name_len); + } else { + ps_name = safe_emalloc(class_name_len, 1, sizeof(long) + 1); + strcpy(ps_name, class_name); + } - class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension); + class_file_len = spprintf(&class_file, 0, "%s%s", ps_name, file_extension); #if DEFAULT_SLASH != '\\' { @@ -273,10 +282,12 @@ } efree(class_file); - return zend_hash_exists(EG(class_table), (char*)lc_name, class_name_len+1); + efree(ps_name); + return zend_hash_exists(EG(class_table), (char*)ps_name, class_name_len+1); } } efree(class_file); + efree(ps_name); return 0; } /* }}} */ @@ -284,7 +295,7 @@ Default implementation for __autoload() */ PHP_FUNCTION(spl_autoload) { - char *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); + char *class_name, *file_exts = SPL_G(autoload_extensions); int class_name_len, file_exts_len = SPL_G(autoload_extensions_len), found = 0; char *copy, *pos1, *pos2; zval **original_return_value = EG(return_value_ptr_ptr); @@ -300,20 +311,18 @@ } else { copy = pos1 = estrndup(file_exts, file_exts_len); } - lc_name = zend_str_tolower_dup(class_name, class_name_len); while(pos1 && *pos1 && !EG(exception)) { EG(return_value_ptr_ptr) = original_return_value; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; pos2 = strchr(pos1, ','); if (pos2) *pos2 = '\0'; - if (spl_autoload(class_name, lc_name, class_name_len, pos1 TSRMLS_CC)) { + if (spl_autoload(class_name, class_name_len, pos1 TSRMLS_CC)) { found = 1; break; /* loaded */ } pos1 = pos2 ? pos2 + 1 : NULL; } - efree(lc_name); if (copy) { efree(copy); } @@ -360,6 +369,21 @@ } } /* }}} */ + +/* {{{ proto bool spl_autoload_case_sensitive([bool use_case_sensitive_file_naming]) + Register and returns the use case sensitive file naming flag for spl_autoload */ +PHP_FUNCTION(spl_autoload_case_sensitive) +{ + zend_bool use_case_sensitive = SPL_G(autoload_case_sensitive); + + zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &use_case_sensitive); + + SPL_G(autoload_case_sensitive) = use_case_sensitive; + + RETURN_BOOL(SPL_G(autoload_case_sensitive)); +} /* }}} */ + + typedef struct { zend_function *func_ptr; zval *obj; @@ -849,6 +873,10 @@ ZEND_ARG_INFO(0, file_extensions) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_case_sensitive, 0, 0, 0) + ZEND_ARG_INFO(0, use_case_sensitive_file_naming) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_call, 0, 0, 1) ZEND_ARG_INFO(0, class_name) ZEND_END_ARG_INFO() @@ -869,20 +897,21 @@ /* {{{ spl_functions */ const zend_function_entry spl_functions[] = { - PHP_FE(spl_classes, arginfo_spl_classes) - PHP_FE(spl_autoload, arginfo_spl_autoload) - PHP_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions) - PHP_FE(spl_autoload_register, arginfo_spl_autoload_register) - PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister) - PHP_FE(spl_autoload_functions, arginfo_spl_autoload_functions) - PHP_FE(spl_autoload_call, arginfo_spl_autoload_call) - PHP_FE(class_parents, arginfo_class_parents) - PHP_FE(class_implements, arginfo_class_implements) - PHP_FE(spl_object_hash, arginfo_spl_object_hash) + PHP_FE(spl_classes, arginfo_spl_classes) + PHP_FE(spl_autoload, arginfo_spl_autoload) + PHP_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions) + PHP_FE(spl_autoload_case_sensitive, arginfo_spl_autoload_case_sensitive) + PHP_FE(spl_autoload_register, arginfo_spl_autoload_register) + PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister) + PHP_FE(spl_autoload_functions, arginfo_spl_autoload_functions) + PHP_FE(spl_autoload_call, arginfo_spl_autoload_call) + PHP_FE(class_parents, arginfo_class_parents) + PHP_FE(class_implements, arginfo_class_implements) + PHP_FE(spl_object_hash, arginfo_spl_object_hash) #ifdef SPL_ITERATORS_H - PHP_FE(iterator_to_array, arginfo_iterator_to_array) - PHP_FE(iterator_count, arginfo_iterator) - PHP_FE(iterator_apply, arginfo_iterator_apply) + PHP_FE(iterator_to_array, arginfo_iterator_to_array) + PHP_FE(iterator_count, arginfo_iterator) + PHP_FE(iterator_apply, arginfo_iterator_apply) #endif /* SPL_ITERATORS_H */ {NULL, NULL, NULL} }; Index: ext/spl/php_spl.h =================================================================== --- ext/spl/php_spl.h (revision 306670) +++ ext/spl/php_spl.h (working copy) @@ -67,6 +67,7 @@ HashTable * autoload_functions; int autoload_running; int autoload_extensions_len; + int autoload_case_sensitive; intptr_t hash_mask_handle; intptr_t hash_mask_handlers; int hash_mask_init; --Apple-Mail-12-885536587 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

Kind = Regards
Marc


On = 26 Dec 2010, at 13:20, Marc Easen wrote:

Hello = everyone,

Firstly I would like to introduce myself, = my name is Marc Easen and I've working with PHP for past 6 years or so. = I'm really excited to see where PHP is going with the addition of = namespaces and now traits, and hopefully I'm able to contribute back to = PHP community.

I've currently working on = a high performance PHP Framework based on version 5.3.3+ = (5.3.99-dev for traits). Due to the high performance nature of this = framework I've been looking at ways of improving the loading of the = classes. It seems by default the spl_autoload() function lowercases = the class name before trying to locate the file, a couples of = users have reported this previously and have requested a = fix (bug #49852 http://bugs.php.net/bug.ph= p?id=3D49852 & bug #53065 http://bugs.php.net/bug.ph= p?id=3D53065). spl_autoload() lower casing the class names when = it is trying to locate the file does not work on *nix based system in a = lot of PHP Frameworks - Zend Framework being on of = them.

Understanding the requirement to support = backwards compatibility both submitters suggested implementing = a spl_autoload_case_sensitivity() function. The patch I have = attached adds such a function to the SPL extension. The patch is against = trunk (r306670), it also includes phpt tests for this = function.

Please could someone review this = patch and let me know what you = think. 

Kind = Regards,

Marc
<spl= _autoload_case_sensitive.patch>

= --Apple-Mail-12-885536587-- --Apple-Mail-11-885536587--