i’m new to PHP objects and i’ve having a problem. I have the following class declaration. I then instantiate an object of the class. but then trying to echo a property value has no effect. what am i doing wrong? thanks.
function fractionToDecimal ( $str ) {
class decimalObject {
var $matchStr;
var $fraction;
var $whole;
var $numerator;
var $denominator;
var $decimal;
var $text;
function _construct ($ma, $fr, $wh, $nu, $den, $dec, $te ) {
$this->matchStr = $ma;
$this->fraction = $fr;
$this->whole = $wh;
$this->numerator = $nu;
$this->denominator = $den;
$this->decimal = $dec;
$this->text = $te;
}
}
$matchStr = "bleh";
$fraction = "no";
$whole = 1;
$numerator = 2;
$denominator = 3;
$decimal = 4;
$text = "wtf";
$a = new decimalObject($matchStr, $fraction, $whole, $numerator, $denominator, $decimal, $text);
return $a;
}
$str = "3/22 slices and hardy harhar";
$result = fractionToDecimal($str);
echo ($result->decimal);
should output “4”. but when i run the code nothing happens. thanks, G