5.2 perform initialization when declaring local variables. The only reason for not doing so is that the initial value of the variable depends on some previous calculations. 5.3 The layout only declares variables at the beginning of the code block. (A block refers to any code contained in braces {and .) Do not use this variable SyntaxHighlighter. all () for the first time ();
5.2 initialization
Try to initialize the local variable while declaring it. The only reason for not doing so is that the initial value of the variable depends on some previous calculations.
5.3 layout
Declare variables only at the beginning of the code block. (A block refers to any code contained in braces "{" and .) Do not declare the variable when it is used for the first time. This will confuse unfocused programmers and impede code portability in this scope.
Function myMethod (){
Int $ int1 = 0; // start of the method block
If ($ condition ){
Int $ int2 = 0; // start of the "if" block
...
}
}
An exception to this rule is the index variable of the for loop.
For (int $ I = 0; I <$ maxLoops; $ I ++ ){...}
Avoid declaring local variables to overwrite the variables declared at the upper level. For example, do not declare the same variable name in the internal code block:
Int $ count;
...
Function myMethod (){
If ($ condition ){
Int $ count = 0; // avoid this declaration
...
}
...
}