Generating PHP warnings
How can I generate PHP custom warnings in the same way as warnings for inline functions.
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 like this:
function my_func($a, $b, $c);
What code can I use to my_func
give similar warnings when called incorrectly?
+3
Joshua spence
source
to share
2 answers
You are probably looking for trigger_error. They will show standard error and will be handled by error_log, display_errors, etc. In php.ini
Minimal example:
if (!DoAFunction()) {
trigger_error("DoAFunction returned false!", E_USER_ERROR);
}
+4
Mark ormston
source
to share
trigger_error("Here is your herror", E_WARNING);
0
AlienWebguy
source
to share