ckrudelux Posted December 2, 2011 Share Posted December 2, 2011 I don't get any errors and for me this would be a good way to do this, but is this bad practice and should this be avoided? if(!isset($var1) && !isset($var2)) ($var1 = 1).($var2 = 2); echo $var1."\n";echo $var2; Link to comment Share on other sites More sharing options...
justsomeguy Posted December 2, 2011 Share Posted December 2, 2011 The concatenation operator doesn't do anything in that case. I guess you can use a construct like that if you want to avoid using curly brackets to enclose the two statements, but you're not saving the result of the concatenation so it's not really doing anything other than setting the two variables. Link to comment Share on other sites More sharing options...
ckrudelux Posted December 2, 2011 Author Share Posted December 2, 2011 The concatenation operator doesn't do anything in that case. I guess you can use a construct like that if you want to avoid using curly brackets to enclose the two statements, but you're not saving the result of the concatenation so it's not really doing anything other than setting the two variables.I was not intressed in saving but only setting the variables, removing the concatenation operator would result in an error. I just saw that it's just as big job at using curly brackets as using parentheses, easy thing to overlook I guess. Edit: What I was looking for was something simular to this:$var1 = 1, $var2 = 2; Link to comment Share on other sites More sharing options...
Ingolme Posted December 3, 2011 Share Posted December 3, 2011 Why do you want to condense the code like that? Link to comment Share on other sites More sharing options...
Synook Posted December 3, 2011 Share Posted December 3, 2011 Assignment is just a normal statement that returns the value that was assigned — there is no requirement that it goes on a line by itself. This is why things like for ($row = mysql_fetch_assoc($query)) ... work. You could do anything: $a = "a" . ($a = 5) + ($a = 10) ? $a = 10 / $a = 5 : $a = "thing"; Maybe you are thinking about list()? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.