U
U
Uber Noob2016-04-23 13:30:29
PHP
Uber Noob, 2016-04-23 13:30:29

How to pass a value to a class method?

No matter how I twist, then one error then another:

class Calculator
{
    public function add($date)
    {
        $my = trim($date);
            $D = explode(",", $my);
            
            $l = strlen($DArr[2]);
            if(1 <= $D[0] && 31 >= $D[0] && 1 <= $D[1] && 12 >= $D[1] &&  $l == 4){
                return true;
            }
            else{
                return false;
            }
    }
 
}
$class = new Calculator;
//$class->$date='12,11,2009';
$class->add(12,11,2009);

var_dump($class);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Niomin, 2016-04-23
@ubernoob

In add, pass the value in quotes.
And look at the standard DateTime class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question