Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

To assign empty, or suppress error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

To assign empty, or suppress error

Postby Joel » Thu Jul 24, 2003 8:33 pm

I'm wondering how the common way of doing something in a loop is. As in, you have a loop which adds values to a string, something like...

Code: Select all
for ($i = 0, $i < 20, $++) {
    $string .= "new value number: ".$i;
}

Would you suppress the error or assign an empty value to $string, like...

Code: Select all
$string = "";
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby swirlee » Fri Jul 25, 2003 5:40 am

Whenever possible, you should try to prevent an error rather than suppressing it. So yes, set your variable to an empty string before you enter the loops.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Fri Jul 25, 2003 2:19 pm

Thats how I've been doing it, it does kind of feel stupid having to do it though, especially when it works anyway.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.