<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                用于測試,在編寫單元測試時非常有用 早期assert是一個函數,php7是一個語法結構(在php語言中是用來判斷一個表達式是否成立。返回true or false;) 老版本的API出于兼容目的**將繼續被維護**,assert()現在是一個語言結構,它允許第一個參數是一個返回值的表達式(簡單但卻最精確的定義一個*表達式*的方式就是**任何有值的東西**,如條件表達式,賦值表達式,比較表達式,三元運算,函數等等),而不僅僅是一個待計算的string或一個待測試的boolean。 **PHP 5** `assert ( mixed $assertion [, string $description ] ) : bool ` **PHP 7** `assert ( mixed $assertion [, Throwable $exception ] ) : bool` ## **php7的ini配置** **zend.assertions** 1:生成并執行代碼(開發模式) 0:生成代碼,但在運行時繞過它 -1:不生成代碼(生產模式) >[info]**zend.assertions=1** ## **assert.exception** //1:當斷言失敗時拋出,方法是拋出作為異常提供的對象,或者在沒有提供異常時拋出一個新的AssertionError對象 //0:使用或生成一個Throwable,如前所述,但只生成一個基于該對象的警告,而不是拋出它(兼容PHP 5行為) >[info]**assert.exception=0** ``` assert(true?==?false); echo?'Hi!'; zend.assertions=0時輸出: Hi! zend.assertions=1并且assert.exception=0時輸出: Warning: assert(): assert(true == false) failed in - on line 2 Hi! zend.assertions=1并且assert.exception=1時輸出: Fatal error: Uncaught AssertionError: assert(true == false) in -:2 Stack trace: #0 -(2): assert(false, 'assert(true == ...') #1 {main} thrown in - on line 2 ``` ## **斷言選項** | 標志 | INI 設置 | 默認值 | 描述 | | --- | --- | --- | --- | | ASSERT\_ACTIVE | assert.active | 1 | 啟用assert()斷言 | | ASSERT\_WARNING | assert.warning | 1 | 為每個失敗的斷言產生一個 PHP 警告(warning) | | ASSERT\_BAIL | assert.bail | 0 | 在斷言失敗時中止執行 | | ASSERT_QUIET_EVAL | assert.quiet\_eval | 0 | 在斷言表達式求值時禁用 error_reporting | | ASSERT\_CALLBACK | assert.callback | (**`NULL`**) | 斷言失敗時調用回調函數 | ``` // 處理斷言失敗時的函數 function assert_failure() { echo 'Assert failed'; } // 我們的測試函數 function test_assert($parameter) { assert(is_bool($parameter)); } // 設置斷言標志 assert_options(ASSERT_ACTIVE, true);//啟用assert()斷言 assert_options(ASSERT_BAIL, true);//在斷言失敗時中止執行 assert_options(ASSERT_WARNING, false);//為每個失敗的斷言產生一個 PHP 警告 assert_options(ASSERT_CALLBACK, 'assert_failure');//斷言失敗時調用回調函數 assert_options(ASSERT_QUIET_EVAL ,false);//在斷言表達式求值時禁用 error_reporting // 讓一個斷言會失敗 test_assert(1); // 由于 ASSERT_BAIL 是 true,這里永遠也到不了 echo 'Never reached'; ``` **例子:** ``` // 斷言操作選項函數 assert_options(ASSERT_ACTIVE, 1); // 默認是打開斷言的 $s = 123; assert("is_int($s)");//從這個例子可以看到字符串參數會被執行,這跟eval()類似 php7 class CustomError extends AssertionError {} assert(true == false, new Exception('True is not false!')); //assert(true == false, new CustomError('True is not false!')); echo 'Hi!'; 輸出 Warning: assert(): Exception: True is not false! in D:\phpstudy_pro\WWW\www.test.com\index.php:5 Stack trace: #0 {main} failed in D:\phpstudy_pro\WWW\www.test.com\index.php on line 5 Hi! ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看