Back to index

php5  5.3.10
Functions
php_assert.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_MINIT_FUNCTION (assert)
 PHP_MSHUTDOWN_FUNCTION (assert)
 PHP_RINIT_FUNCTION (assert)
 PHP_RSHUTDOWN_FUNCTION (assert)
 PHP_MINFO_FUNCTION (assert)
 PHP_FUNCTION (assert)
 PHP_FUNCTION (assert_options)

Function Documentation

Definition at line 141 of file assert.c.

{
       zval **assertion;
       int val;
       char *myeval = NULL;
       char *compiled_string_description;

       if (! ASSERTG(active)) {
              RETURN_TRUE;
       }

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &assertion) == FAILURE) {
              return;
       }

       if (Z_TYPE_PP(assertion) == IS_STRING) {
              zval retval;
              int old_error_reporting = 0; /* shut up gcc! */

              myeval = Z_STRVAL_PP(assertion);

              if (ASSERTG(quiet_eval)) {
                     old_error_reporting = EG(error_reporting);
                     EG(error_reporting) = 0;
              }

              compiled_string_description = zend_make_compiled_string_description("assert code" TSRMLS_CC);
              if (zend_eval_stringl(myeval, Z_STRLEN_PP(assertion), &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
                     efree(compiled_string_description);
                     php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Failure evaluating code: %s%s", PHP_EOL, myeval);
                     if (ASSERTG(bail)) {
                            zend_bailout();
                     }
                     RETURN_FALSE;
              }
              efree(compiled_string_description);

              if (ASSERTG(quiet_eval)) {
                     EG(error_reporting) = old_error_reporting;
              }

              convert_to_boolean(&retval);
              val = Z_LVAL(retval);
       } else {
              convert_to_boolean_ex(assertion);
              val = Z_LVAL_PP(assertion);
       }

       if (val) {
              RETURN_TRUE;
       }

       if (!ASSERTG(callback) && ASSERTG(cb)) {
              MAKE_STD_ZVAL(ASSERTG(callback));
              ZVAL_STRING(ASSERTG(callback), ASSERTG(cb), 1);
       }

       if (ASSERTG(callback)) {
              zval *args[3];
              zval *retval;
              int i;
              uint lineno = zend_get_executed_lineno(TSRMLS_C);
              char *filename = zend_get_executed_filename(TSRMLS_C);

              MAKE_STD_ZVAL(args[0]);
              MAKE_STD_ZVAL(args[1]);
              MAKE_STD_ZVAL(args[2]);

              ZVAL_STRING(args[0], SAFE_STRING(filename), 1);
              ZVAL_LONG (args[1], lineno);
              ZVAL_STRING(args[2], SAFE_STRING(myeval), 1);

              MAKE_STD_ZVAL(retval);
              ZVAL_FALSE(retval);

              /* XXX do we want to check for error here? */
              call_user_function(CG(function_table), NULL, ASSERTG(callback), retval, 3, args TSRMLS_CC);

              for (i = 0; i <= 2; i++) {
                     zval_ptr_dtor(&(args[i]));
              }
              zval_ptr_dtor(&retval);
       }

       if (ASSERTG(warning)) {
              if (myeval) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion \"%s\" failed", myeval);
              } else {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion failed");
              }
       }

       if (ASSERTG(bail)) {
              zend_bailout();
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( assert_options  )

Definition at line 241 of file assert.c.

{
       zval **value = NULL;
       long what;
       int oldint;
       int ac = ZEND_NUM_ARGS();

       if (zend_parse_parameters(ac TSRMLS_CC, "l|Z", &what, &value) == FAILURE) {
              return;
       }

       switch (what) {
       case ASSERT_ACTIVE:
              oldint = ASSERTG(active);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.active", sizeof("assert.active"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_BAIL:
              oldint = ASSERTG(bail);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.bail", sizeof("assert.bail"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_QUIET_EVAL:
              oldint = ASSERTG(quiet_eval);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.quiet_eval", sizeof("assert.quiet_eval"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_WARNING:
              oldint = ASSERTG(warning);
              if (ac == 2) {
                     convert_to_string_ex(value);
                     zend_alter_ini_entry_ex("assert.warning", sizeof("assert.warning"), Z_STRVAL_PP(value), Z_STRLEN_PP(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC);
              }
              RETURN_LONG(oldint);
              break;

       case ASSERT_CALLBACK:
              if (ASSERTG(callback) != NULL) {
                     RETVAL_ZVAL(ASSERTG(callback), 1, 0);
              } else if (ASSERTG(cb)) {
                     RETVAL_STRING(ASSERTG(cb), 1);
              } else {
                     RETVAL_NULL();
              }
              if (ac == 2) {
                     if (ASSERTG(callback)) {
                            zval_ptr_dtor(&ASSERTG(callback));
                     }
                     ASSERTG(callback) = *value;
                     zval_add_ref(value);
              }
              return;
              break;

       default:
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %ld", what);
              break;
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

Definition at line 133 of file assert.c.

Definition at line 112 of file assert.c.

{
       if (ASSERTG(cb)) {
              pefree(ASSERTG(cb), 1);
              ASSERTG(cb) = NULL;
       }
       return SUCCESS;
}

Definition at line 122 of file assert.c.