Results 1 to 6 of 6

Thread: [RESOLVED] Warnings...suppress them??

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved [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"???


    - ØØ -

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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;

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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...

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Warnings...suppress them??

    ****ing ****ty ****y møkky rotten dot com ****ty rating system....you know what I am on about....

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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
  •  



Click Here to Expand Forum to Full Width