Hi,
I have just started learning OOP
and have a couple of questions.
Is it correct to say that if I write a constructor method for my class
then I will not need to use he set method to add values to properties ?
i.e. with this:
this will not be needed:
because in my html I will use this:
True - or have I got things mixed up ?
I have just started learning OOP
and have a couple of questions.
Is it correct to say that if I write a constructor method for my class
then I will not need to use he set method to add values to properties ?
i.e. with this:
Code:
<?php
class person {
var $name;
var $sp_number;
public $height;
protected $social_insurance;
function __construct($persons_name) {
$this->name = $persons_name;
}
function get_name() {
return $this->name;
}
} // end class
?>
this will not be needed:
Code:
function set_name($new_name) {
$this->name = $new_name;
}
Code:
<?php
$stefan = new person("Stefan Mischook");
echo "Stefan's full name: " . $stefan->get_name()."<br>";
?>
Comment