New to OOP, the idea is to instantiate an object in a class passing two properties in the process and using a method within the class to generate a third property that i would later need to use.
Does this make sense in OOP terms? I would have thought that my dostuff method would create my thirdproperty ready for use for my next methods in the class?
Here's my code:
<?php
class Nameofclass {
public $firstproperty = '';
public $secondproperty ='';
public $thirdproperty ='';
public function __construct ($firstproperty, $secondproperty) {
$this->firstproperty = $firstproperty;
$this->secondproperty = $secondproperty;
}
public function dostuff($firstproperty) {
do a lot of clever stuff here to calculate a $value;
$this->thirdproperty = $value
}
}
$newInstance = new Nameofclass('firstproperty', 'secondproperty');
echo $newInstance->thirdproperty;
?>
What am I doing wrong? My var_dump($newInstance->thirdproperty) returns Null - as initially set i suppose.... slightly confused here?!