Skip to content

Commit a5c37f3

Browse files
committed
- Add ability to fail silently
1 parent cee979d commit a5c37f3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ext/spl/php_spl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,16 @@ PHP_FUNCTION(spl_autoload_call)
352352
}
353353
} /* }}} */
354354

355-
/* {{{ void spl_autoload_register([string autoload_function = "spl_autoload"])
355+
/* {{{ void spl_autoload_register([string autoload_function = "spl_autoload" [, throw = true]])
356356
Register given function as __autoload() implementation */
357357
PHP_FUNCTION(spl_autoload_register)
358358
{
359359
char *func_name, *lc_name;
360360
int func_name_len;
361+
zend_bool do_throw = 1;
361362
zend_function *spl_func_ptr, *func_ptr, **func_ptr_ptr;
362363

363-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &func_name, &func_name_len) == FAILURE) {
364+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &func_name, &func_name_len, &do_throw) == FAILURE) {
364365
return;
365366
}
366367

@@ -369,13 +370,17 @@ PHP_FUNCTION(spl_autoload_register)
369370
zend_str_tolower_copy(lc_name, func_name, func_name_len);
370371

371372
if (!strcmp(lc_name, "spl_autoload_call")) {
372-
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered", func_name);
373+
if (do_throw) {
374+
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered", func_name);
375+
}
373376
free_alloca(lc_name);
374377
return;
375378
}
376379

377380
if (zend_hash_find(EG(function_table), lc_name, func_name_len+1, (void **) &func_ptr) == FAILURE) {
378-
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%s' not found", func_name);
381+
if (do_throw) {
382+
zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%s' not found", func_name);
383+
}
379384
free_alloca(lc_name);
380385
return;
381386
}

0 commit comments

Comments
 (0)