Hi,
I think you're idea is pretty good, however not the way you
engaged the current behaviour imho.
PHP also supports 'lint'ing of source code aka. checking for
parserer errors. It's just a few minutes work to provide the
same functionality for a new function:
$retval = lint($code);
This would also throw parserer errors right at you, if you
don't want, use '@' to supress it. It could be named
'eval_test' as someone on IRC (hey guys, btw:) suggested, or
an optional argument to eval() to do only linting of the
source, whatever.
I've attached a small patch against
Zend/zend_builtin_functions.c from CVS a few days ago (but it
can be done everywhere, e.g. ext/standard ). I didn't
commited it because a) I wasn't unsure if ppl want it and b)
if it's the proper way to do it that way ("it works for me").
Any of the developers care reviewing, (fixing,) commiting ?
:)
- Markus
On Fri, Jun 21, 2002 at 08:57:43AM -0000, [EMAIL PROTECTED] wrote :
> From: [EMAIL PROTECTED]
> Operating system: Any
> PHP version: 4.2.1
> PHP Bug Type: Feature/Change Request
> Bug description: Error Handling for eval()
>
> I want to handle Parse_Errors and similar Fatals with my custom error
> handler when they occur in eval()'d code.
>
> This is necessary when i want to execute custom code in my console script
> and prevent this code from crashing my entire program if there is only a
> simple typo in there...
>
> I have achieved this by a little hack in the "zend_execute.c" but i don't
> know if this handles any errors right that don't occur in eval'd()
> code...
> This is what i changed (to even prevent a segmentation fault)
> (zend_execute.c, line 1563):
>
> if (zend_hash_find(active_function_table, function_name->value.str.val,
> function_name->value.str.len+1, (void **) &function)==FAILURE) {
> zend_error(E_USER_ERROR, "Call to undefined function: %s()",
> function_name->value.str.val);
> return;
> }
>
> --
> Edit bug report at http://bugs.php.net/?id=17892&edit=1
> --
> Fixed in CVS: http://bugs.php.net/fix.php?id=17892&r=fixedcvs
> Fixed in release: http://bugs.php.net/fix.php?id=17892&r=alreadyfixed
> Need backtrace: http://bugs.php.net/fix.php?id=17892&r=needtrace
> Try newer version: http://bugs.php.net/fix.php?id=17892&r=oldversion
> Not developer issue: http://bugs.php.net/fix.php?id=17892&r=support
> Expected behavior: http://bugs.php.net/fix.php?id=17892&r=notwrong
> Not enough info: http://bugs.php.net/fix.php?id=17892&r=notenoughinfo
> Submitted twice: http://bugs.php.net/fix.php?id=17892&r=submittedtwice
> register_globals: http://bugs.php.net/fix.php?id=17892&r=globals
--
GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
Did I help you? http://guru.josefine.at/wish_en
Konnte ich helfen? http://guru.josefine.at/wish_de
"uhmm.. the dates in the bug db.. aren't they printed a bit wrong, i mean, did
i miss when we changed to 53 days/month ( +2002-02-53) ? =P - N0v3ll
Index: zend_builtin_functions.c
===================================================================
RCS file: /repository/Zend/zend_builtin_functions.c,v
retrieving revision 1.118
diff -u -r1.118 zend_builtin_functions.c
--- zend_builtin_functions.c 12 Jun 2002 17:02:22 -0000 1.118
+++ zend_builtin_functions.c 21 Jun 2002 09:52:25 -0000
@@ -68,6 +68,7 @@
#if ZEND_DEBUG
static ZEND_FUNCTION(zend_test_func);
#endif
+static ZEND_FUNCTION(lint);
ZEND_API unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE };
ZEND_API unsigned char second_arg_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
@@ -119,6 +120,7 @@
#if ZEND_DEBUG
ZEND_FE(zend_test_func, NULL)
#endif
+ ZEND_FE(lint, NULL)
{ NULL, NULL, NULL }
};
@@ -1185,3 +1187,31 @@
}
}
/* }}} */
+
+/* {{{ proto bool lint(string code)
+ Returns true of "code" doesn't throw any parser error, else false */
+ZEND_FUNCTION(lint)
+{
+ zval **phpcode;
+ zend_op_array *op_array;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &phpcode)) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ convert_to_string_ex(phpcode);
+
+ zend_try {
+ op_array = compile_string(*phpcode, "-" TSRMLS_CC);
+
+ if (op_array) {
+ destroy_op_array(op_array);
+ efree(op_array);
+ RETURN_TRUE;
+ } else {
+ RETURN_FALSE;
+ }
+ } zend_end_try();
+
+ RETURN_FALSE;
+}
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php