Jump to content

[SOLVED] datatype help


sasori

Recommended Posts

let's say i wanna create a class that will accept either integer or float, is it advisable to make 2 different classes?

<?php
class Customerorder
{
   private $total = 0; //for integer
   function addtotal($amount)
   {
     $this->total = $this->total + $amount;
     echo "$amount was added; current total is $this->total";
   }
}

class Customerorder
{
  private $total = 0.0; //for float
  function addtotal($amount)
  {
    if(is_numeric($amount))
    {
      $this->total = $this->total + $amount;
        echo "$total is added; current total is $this->total";
    }
    else
    {
      echo "the value passed is not numeric";
    }
  }
}
?>

 

(sorry for posting it here,, nobody's answering it in OOP section of the forum) :(

 

Link to comment
https://forums.phpfreaks.com/topic/118043-solved-datatype-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.