prw Posted June 5, 2011 Share Posted June 5, 2011 I keep get the following warning whilst using the following function which I wrote. Is there a way of getting rid of the warning? I'm aware I can just turn off error_reporting to not see the warning, but just wondering if there's a way of fixing it. function contains($value, $a, $b = '', $c = '') { if (isset($b) && isset($c)) { if (stristr($value, $a) || stristr($value, $b) || stristr($value, $c)) return true; } elseif (isset($b)) { if (stristr($value, $a) || stristr($value, $b)) return true; } else { if (stristr($value, $a)) return true; else return false; } } Link to comment https://forums.phpfreaks.com/topic/238492-warning-stristr-functionstristr-empty-delimiter/ Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 You can use @ to mute warnings or you can properly check that variables exist and not have a warning in the first place. if (!empty($b) -- Since its in a function, you know those variables exist. But are they empty or not? Link to comment https://forums.phpfreaks.com/topic/238492-warning-stristr-functionstristr-empty-delimiter/#findComment-1225548 Share on other sites More sharing options...
prw Posted June 5, 2011 Author Share Posted June 5, 2011 Ah right of course, totally forgot that I set $b and $c to be empty, changing the isset's fixed my problem. Thanks for pointing it out. Link to comment https://forums.phpfreaks.com/topic/238492-warning-stristr-functionstristr-empty-delimiter/#findComment-1225553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.