colder Sun May 25 12:22:38 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/spl/tests spl_autoload_010.phpt spl_autoload_011.phpt
Modified files: /php-src/ext/spl php_spl.c Log: MFH: Add a prepend param to spl_autoload_register http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.52.2.28.2.17.2.16&r2=1.52.2.28.2.17.2.17&diff_format=u Index: php-src/ext/spl/php_spl.c diff -u php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.16 php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.17 --- php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.16 Tue Apr 29 09:18:26 2008 +++ php-src/ext/spl/php_spl.c Sun May 25 12:22:37 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.17.2.16 2008/04/29 09:18:26 dmitry Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.17.2.17 2008/05/25 12:22:37 colder Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -401,7 +401,14 @@ } } /* }}} */ -/* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true]]) +#define HT_MOVE_TAIL_TO_HEAD(ht) \ + (ht)->pListTail->pListNext = (ht)->pListHead; \ + (ht)->pListHead = (ht)->pListTail; \ + (ht)->pListTail = (ht)->pListHead->pListLast; \ + (ht)->pListTail->pListNext = NULL; \ + (ht)->pListHead->pListLast = NULL; + +/* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend]]]) Register given function as __autoload() implementation */ PHP_FUNCTION(spl_autoload_register) { @@ -410,11 +417,12 @@ char *lc_name = NULL; zval *zcallable = NULL; zend_bool do_throw = 1; + zend_bool prepend = 0; zend_function *spl_func_ptr; autoload_func_info alfi; zval **obj_ptr; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zb", &zcallable, &do_throw) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) { return; } @@ -507,9 +515,17 @@ spl_alfi.obj = NULL; spl_alfi.ce = NULL; zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL); + if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { + /* Move the newly created element to the head of the hashtable */ + HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); + } } zend_hash_add(SPL_G(autoload_functions), lc_name, func_name_len+1, &alfi.func_ptr, sizeof(autoload_func_info), NULL); + if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { + /* Move the newly created element to the head of the hashtable */ + HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); + } skip: efree(lc_name); } http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/spl_autoload_010.phpt?view=markup&rev=1.1 Index: php-src/ext/spl/tests/spl_autoload_010.phpt +++ php-src/ext/spl/tests/spl_autoload_010.phpt --TEST-- SPL: spl_autoload() and prepend --INI-- include_path=. --FILE-- <?php function autoloadA($name) { echo "A -> $name\n"; } function autoloadB($name) { echo "B -> $name\n"; } function autoloadC($name) { echo "C -> $name\n"; class C{} } spl_autoload_register('autoloadA'); spl_autoload_register('autoloadB', true, true); spl_autoload_register('autoloadC'); new C; ?> ===DONE=== <?php exit(0); ?> --EXPECTF-- B -> C A -> C C -> C ===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/spl_autoload_011.phpt?view=markup&rev=1.1 Index: php-src/ext/spl/tests/spl_autoload_011.phpt +++ php-src/ext/spl/tests/spl_autoload_011.phpt --TEST-- SPL: spl_autoload() and object freed --INI-- include_path=. --FILE-- <?php class A { public $var = 1; public function autoload() { echo "var:".$this->var."\n"; } public function __destruct() { echo "__destruct__\n"; } } $a = new A; $a->var = 2; spl_autoload_register(array($a, 'autoload')); unset($a); var_dump(class_exists("C", true)); ?> ===DONE=== <?php exit(0); ?> --EXPECTF-- var:2 bool(false) ===DONE=== __destruct__ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php