How can I generate custom PHP warnings in the same way that warnings for the built-in functions work.
For example:
php > fopen(null);
PHP Warning: fopen() expects at least 2 parameters, 1 given in php shell code on line 1
php > fopen(null, 'w');
PHP Warning: fopen(): Filename cannot be empty in php shell code on line 1
php > fopen(array('a'), 'w');
PHP Warning: fopen() expects parameter 1 to be a valid path, array given in php shell code on line 1
Let's say I have a function as follows:
function my_func($a, $b, $c);
What code can I use such that my_func will throw similar warnings when called incorrectly?
You're probably looking for trigger_error. These will show a standard error and are handled by the error_log, display_errors, etc. settings in php.ini
A minimal example is:
if (!DoAFunction()) {
trigger_error("DoAFunction returned false!", E_USER_ERROR);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With