Porting some code from Javascript, I have such a misunderstanding. For instance:
In javascript we can create this code.
var a, x, y; var r = 10; with (Math) { a = PI * r * r; x = r * cos(PI); y = r * sin(PI / 2); }
Instead
a = Math.PI * r * r; x = r * Math.cos(Math.PI); y = r * Math.sin(Math.PI / 2);
This last example will have the same comportament in PHP, IE, in the second code example Math is redundant.
Does anyone have a solution for clean, elegant code?
I am adding the following code as a new example:
class MyExampleClass { function example { for($i = 0; $i < count($this->Registers); $i++) { $r = "50"; $r .= $this->ZeroFill($this->numericOnly($this->Registers[$i]->Id)), 15) . $this->ZeroFill($this->numericOnly($this->Registers[$i]->Inscription), 25); $r .= $this->ZeroFill($this->Registers[$i]->Model, 2 ); $r .= $this->PadR($this->alpha($this->Registers[$i]->Date), 10 ); $this->WriteRecord( $r); } }
In the third example, I can use temp $ var inside for an expression for $this->Registers[$i] , but if all the treatment code has become in the class, for example, in the Sanitize class.
with (Sanitize) { $r .= ZeroFill(numericOnly($tmp), 15);
I want to make shorter and non-repeating code.