Hello Marcus, Based on 5.0.3 source distribution, inspired of parsekit_compile_string
fred ----- Original Message ----- From: "Marcus Boerger" <[EMAIL PROTECTED]> To: "Frédéric LECOINTRE" <[EMAIL PROTECTED]> Cc: <internals@lists.php.net> Sent: Friday, February 18, 2005 9:25 AM Subject: Re: [PHP-DEV] function proposal - php_check_syntax_string | Hello Frédéric, | | do you have some c code you can post here as a .txt attachment or as a link? | | regards | marcus | | Friday, February 18, 2005, 4:41:06 AM, you wrote: | | > hi all, | | > to check syntax of pieces of code and to avoid wild regular expressions, i | > wrote this: | | > proto bool php_check_syntax_string(string string [, &$error_message]) | | > like php_check_syntax but on string | > it will be useful for applications who have to store valid code like smarty, | > ... | > is it possible to add it? | | > regards | | > fred | | | | | -- | Best regards, | Marcus mailto:[EMAIL PROTECTED] |
--- ext/standard/basic_functions.h.old 2004-03-27 01:50:39.000000000 +0100 +++ ext/standard/basic_functions.h 2005-02-18 03:15:00.000000000 +0100 @@ -83,6 +83,7 @@ PHP_FUNCTION(highlight_string); PHP_FUNCTION(php_strip_whitespace); PHP_FUNCTION(php_check_syntax); +PHP_FUNCTION(php_check_syntax_string); ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini); PHP_FUNCTION(ini_get);
--- ext/standard/basic_functions.c.old 2004-11-16 00:16:20.000000000 +0100 +++ ext/standard/basic_functions.c 2005-02-18 05:11:32.539681544 +0100 @@ -481,7 +481,8 @@ PHP_FE(highlight_string, NULL) PHP_FE(php_strip_whitespace, NULL) PHP_FE(php_check_syntax, second_arg_force_ref) - + PHP_FE(php_check_syntax_string, second_arg_force_ref) + PHP_FE(ini_get, NULL) PHP_FE(ini_get_all, NULL) PHP_FE(ini_set, NULL) @@ -2366,6 +2367,48 @@ return; } /* }}} */ +/* {{{ proto bool php_check_syntax_string(string string [, &$error_message]) + Check the syntax of the specified string. */ +PHP_FUNCTION(php_check_syntax_string) +{ + zval *zcode, *zerrors = NULL; + zend_op_array *ops; + zend_uchar original_handle_op_arrays; + + int old_errors = PG(display_errors); + int log_errors = PG(log_errors); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &zcode, &zerrors) == FAILURE){ + RETURN_FALSE; + } + + convert_to_string(zcode); + + PG(log_errors) = PG(display_errors) = 0; + + original_handle_op_arrays = CG(handle_op_arrays); + ops = compile_string(zcode, "php_check_syntax_string" TSRMLS_CC); + CG(handle_op_arrays) = original_handle_op_arrays; + + if (ops) { + RETVAL_TRUE; + } else { + if (zerrors) { + char *error_str; + + zval_dtor(zerrors); + spprintf(&error_str, 0, "%s on line %d", PG(last_error_message), PG(last_error_lineno)); + ZVAL_STRING(zerrors, error_str, 0); + } + RETVAL_FALSE; + } + + PG(display_errors) = old_errors; + PG(log_errors) = log_errors; + + return; + } + /* }}} */ /* {{{ proto bool highlight_string(string string [, bool return] ) Syntax highlight a string or optionally return it */
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php