Skip to main content
Code Review

Return to Question

Notice removed Content dispute by Community Bot
Post Unlocked by Community Bot
Post Locked by rolfl
Notice added Content dispute by rolfl
Post Unlocked by rolfl
Notice removed Content dispute by rolfl
Post Locked by rolfl
Notice added Content dispute by rolfl
Rollback to Revision 3
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>
deleted 757 characters in body
Source Link

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

Rollback to Revision 3
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

I aim to improve my PHP OOP skills and made a simple calculator. Visitors can choose 2 numbers and a prefix, so they can add, subtract, divide and so forth. The output is the sum. The good thing is it's working, but is it also clean coding? Also, is it wise to use the switch statement in a function?

I hope to get some tips so I can improve and learn.

class calcdata {
public $number1;
public $prefix;
public $number2;
public function __construct() {
 $this->number1 = $number1 = $_POST['number1'];
 $this->prefix = $prefix = $_POST['prefix'];
 $this->number2 = $number2 = $_POST['number2'];
 
 
}
public function result(){
switch($this->prefix){
case "+":
return ($this->number1 + $this->number2);
break;
case "-":
return ($this->number1 - $this->number2);
break;
case "/":
return ($this->number1 / $this->number2);
break;
case "*":
return ($this->number1 * $this->number2);
break;
default:
return "Only use: \" +, -, / of * \" ";
}
}
}
$show = new calcdata();
echo $show->result();
 </body>
 </html>
deleted 757 characters in body
Source Link
Loading
deleted 11 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
deleted 14 characters in body
Source Link
RubberDuck
  • 31.2k
  • 6
  • 74
  • 176
Loading
Source Link
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /