|
-
Apr 16th, 2006, 08:07 AM
#1
[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"???
- ØØ -
-
Apr 16th, 2006, 08:20 AM
#2
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;
}
-
Apr 16th, 2006, 08:30 AM
#3
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....
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...
-
Apr 16th, 2006, 08:30 AM
#4
Re: Warnings...suppress them??
****ing ****ty ****y møkky rotten dot com ****ty rating system....you know what I am on about....
-
Apr 16th, 2006, 08:34 AM
#5
Re: Warnings...suppress them??
 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.
-
Apr 16th, 2006, 08:38 AM
#6
Re: Warnings...suppress them??
Error trapping is for wimps.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|