[RESOLVED] Warnings...suppress them??
Lets say you have a line like this:
Code:
$index = strpos($sometext, '$', 2);
but the $sometext is empty. Then the offsett 2 will be outside and PHP will send a warning.
What do you usualy do with this. First do an if test to check if the string is long enough? Or do you just use the @ to suppress the warning? Or is that an ugly "hack"???
- ØØ -
Re: Warnings...suppress them??
Niether is an ugly hack. Although personally I would test the string length first. You could also encompass the whole thing into one line:
PHP Code:
$index = (strlen($sometext)>=2)?strpos($sometext, '$', 2):0;
Is identical to:
PHP Code:
if(strlen($sometext) >= 2) {
$index = strpos($sometext, '$', 2);
} else {
$index = 0;
}
Re: Warnings...suppress them??
Well, if non of them is considered an ugly hack then I have to admitt that @ is a much less to write.... :blush:
I try not to use the ? operator too much. It is easy to make the code unreadable...but thanks for the answer. I'll salute you...:)
Re: Warnings...suppress them??
****ing ****ty ****y møkky rotten dot com ****ty rating system....you know what I am on about....
Re: Warnings...suppress them??
Quote:
Originally Posted by NoteMe
****ing ****ty ****y møkky rotten dot com ****ty rating system....you know what I am on about....
Have you been turned down by that italian girl again?
Yes, it is up to your coding style and what you think looks best. The @ operator does not only suppress wanrings it also suppresses notices, so watch for variable spellings when using it. :)
Re: Warnings...suppress them??
Error trapping is for wimps.