Home › Forums › Back End › Not getting it? › Reply To: Not getting it?
September 16, 2014 at 11:46 pm
#183341
Participant
First thing you don’t have a constructor that takes arguments, so the line $animal = new animal(‘dog’); does nothing with the argument you provided
Ah __construct
is what is required when using new
.
<?php
class animal {
public function __construct($name) {
$this->name = $name;
}
public function name() {
return $this->name;
}
}
$animal = new animal('dog');
var_dump($animal->name());
//Output: string(3) "dog"
?>
I just figured I could do this with only one function.