|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-05-06 19:55 UTC] cunha17 at gmail dot com
Description:
------------
First of all:
1. Using PHP-RC2 or PHP-CVS (2004-05-06)
2. Using Smarty-2.6.2 with customized tag(function)
3. Mapping PHP errors to exceptions(user error handler)
If there is an error inside the customized Smarty function, the error handler routine raises an exception that doesn't reach any try/catch block outside the Smarty class.
In fact, the exception doesn't propagate outside the fetch function in file Smarty.class.php.
The exception is raised inside an "include" instruction and it's possible to catch it inside the fetch function, but impossible anywhere else.
The fetch function is called from Smarty.class.php:1115 and the "include" instruction is placed at Smarty.class.php:1266.
Cristiano Duarte
Reproduce code:
---------------
<?php
include('Smarty-2.6.2/libs/Smarty.class.php');
function smarty_test($params, $smarty)
{
//Now we raise a notice about name not being defined
//This should get mapped to an Exception
return "{$params[name]}";
}
function my_error($nr, $text, $file, $line, $vars)
{
$e = new Exception($text);
throw $e;
}
error_reporting(E_ALL);
set_error_handler('my_error');
$s = new Smarty();
$s->register_function('test', 'smarty_test');
$s->display('exception_bug.tpl');
?>
Here is the template(exception_bug.tpl):
<html>
<head>
<title>Exception BUG</title>
</head>
<body>
{test name="ExceptionBugTest"}
</body>
</html>
Expected result:
----------------
Uncaught Exception
Actual result:
--------------
Segmentation Fault (core dumped)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 25 14:00:01 2025 UTC |
The debug_backtrace() just before the segmentation fault: Array ( [0] => Array ( [file] => /home/ten_cunha/bug/templates_c/%%595^%%595330115^exception_bug.tpl.php [line] => 10 [function] => smarty_test [args] => Array ( [0] => Array ( [name] => ExceptionBugTest ) [1] => Smarty Object ( [template_dir] => templates [compile_dir] => templates_c [config_dir] => configs [plugins_dir] => Array ( [0] => plugins ) [debugging] => [error_reporting] => [debug_tpl] => [debugging_ctrl] => NONE [compile_check] => 1 [force_compile] => [caching] => 0 [cache_dir] => cache [cache_lifetime] => 3600 [cache_modified_check] => [php_handling] => 0 [security] => [secure_dir] => Array ( ) [security_settings] => Array ( [PHP_HANDLING] => [IF_FUNCS] => Array ( [0] => array [1] => list [2] => isset [3] => empty [4] => count [5] => sizeof [6] => in_array [7] => is_array [8] => true [9] => false ) [INCLUDE_ANY] => [PHP_TAGS] => [MODIFIER_FUNCS] => Array ( [0] => count ) [ALLOW_CONSTANTS] => ) [trusted_dir] => Array ( ) [left_delimiter] => { [right_delimiter] => } [request_vars_order] => EGPCS [request_use_auto_globals] => 1 [compile_id] => [use_sub_dirs] => [default_modifiers] => Array ( ) [default_resource_type] => file [cache_handler_func] => [autoload_filters] => Array ( ) [config_overwrite] => 1 [config_booleanize] => 1 [config_read_hidden] => [config_fix_newlines] => 1 [default_template_handler_func] => [compiler_file] => Smarty_Compiler.class.php [compiler_class] => Smarty_Compiler [config_class] => Config_File [_error_msg] => [_tpl_vars] => Array ( [SCRIPT_NAME] => exception_bug.php ) [_smarty_vars] => [_sections] => Array ( ) [_foreach] => Array ( ) [_tag_stack] => Array ( ) [_conf_obj] => [_config] => Array ( [0] => Array ( [vars] => Array ( ) [files] => Array ( ) ) ) [_smarty_md5] => f8d698aea36fcbead2b9d5359ffca76f [_version] => 2.6.2 [_inclusion_depth] => 0 [_compile_id] => [_smarty_debug_id] => SMARTY_DEBUG [_smarty_debug_info] => Array ( ) [_cache_info] => Array ( ) [_file_perms] => 420 [_dir_perms] => 505 [_reg_objects] => Array ( ) [_plugins] => Array ( [modifier] => Array ( ) [function] => Array ( [test] => Array ( [0] => smarty_test [1] => exception_bug.tpl [2] => 6 [3] => 1 [4] => 1 [5] => ) ) [block] => Array ( ) [compiler] => Array ( ) [prefilter] => Array ( ) [postfilter] => Array ( ) [outputfilter] => Array ( ) [resource] => Array ( ) [insert] => Array ( ) ) [_cache_serials] => Array ( ) [_cache_include] => [_cache_including] => ) ) ) [1] => Array ( [file] => /home/ten_cunha/bug/Smarty-2.6.2/libs/Smarty.class.php [line] => 1266 [args] => Array ( [0] => /home/ten_cunha/bug/templates_c/%%595^%%595330115^exception_bug.tpl.php ) [function] => include ) [2] => Array ( [file] => /home/ten_cunha/bug/Smarty-2.6.2/libs/Smarty.class.php [line] => 1115 [function] => fetch [class] => Smarty [type] => -> [args] => Array ( [0] => exception_bug.tpl [1] => [2] => [3] => 1 ) ) [3] => Array ( [file] => /home/ten_cunha/bug/exception_bug.php [line] => 21 [function] => display [class] => Smarty [type] => -> [args] => Array ( [0] => exception_bug.tpl ) ) )Using the gdb's "next" command, I could get an useful backtrace: Program received signal SIGSEGV, Segmentation fault. 0x00000000 in ?? () (gdb) bt #0 0x00000000 in ?? () #1 0x0819c798 in execute (op_array=0x4076e378, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/Zend/zend_execute.c:1391 #2 0x0819fd9b in zend_do_fcall_common_helper (execute_data=0xbfffd110, opline=0x4076e174, op_array=0x4076f0a0, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/Zend/zend_execute.c:2728 #3 0x0819c798 in execute (op_array=0x4076f0a0, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/Zend/zend_execute.c:1391 #4 0x0819fd9b in zend_do_fcall_common_helper (execute_data=0xbfffd340, opline=0x40505dfc, op_array=0x40505520, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/Zend/zend_execute.c:2728 #5 0x0819c798 in execute (op_array=0x40505520, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/Zend/zend_execute.c:1391 #6 0x081803ec in zend_execute_scripts (type=8, tsrm_ls=0x8203200, retval=0x0, file_count=3) at /usr/src/zend2/php-src/Zend/zend.c:1058 #7 0x0814a191 in php_execute_script (primary_file=0xbffff710, tsrm_ls=0x8203200) at /usr/src/zend2/php-src/main/main.c:1630 #8 0x081a7f8a in main (argc=2, argv=0xbffff794) at /usr/src/zend2/php-src/sapi/cli/php_cli.c:943 #9 0x403d0a67 in __libc_start_main () from /lib/i686/libc.so.6