Is there any way to show, or throw, a PHP warning?

前端 未结 3 1193
盖世英雄少女心
盖世英雄少女心 2020-12-29 17:57

I have a select() method in a database class, that has an optional boolean argument $sum. This argument is used to say if the method should use

相关标签:
3条回答
  • 2020-12-29 18:33

    If you want to generate a warning, you should write

    trigger_error($yourErrorMessage, E_USER_WARNING);
    

    trigger_error() has the $error_type parameter for setting the error level (Notice, Warning or Fatal error). The constants are, respectively:

    E_USER_NOTICE             // Notice (default)
    E_USER_WARNING            // Warning
    E_USER_ERROR              // Fatal Error
    

    Note that Fatal error stops the execution of subsequent PHP code, while Notice and Warning let it continue.

    From PHP 5.5, you should also consider the Finally statement.

    0 讨论(0)
  • 2020-12-29 18:34

    You're going the object-oriented approach, so I suggest a look into exceptions.

    0 讨论(0)
  • 2020-12-29 18:50

    You could try trigger_error().

    0 讨论(0)
提交回复
热议问题