Can anyone give me some insight on how to use / share variables within a class across the different methods(functions)?
<?php
class myClass {
var $myVar = 1;
var $myString = "My number is: ".$myVar;
function testFunc1 () {
$myVar = $myVar + 1;
return $myVar;
}
function testFunc2() {
$myCombo = "What is your number<br />".$myString;
return $myCombo;
}
}
$my_test = new myClass();
// below should result in '2' and does not
print($my_test->testFunc1());
// below should result in displaying both sentences with variables inserted, but does not
print($my_test->testFunc2());
?>
Obviously what I have here is wrong since variables/values are not being seen within the methods/functions.
and I get the following error upon loading this. Unless I comment out line 6 of course in order to get no errors, but I still do not get the intended results:
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/mypath/myfolder/test.php on line 6
I'm still pretty new to all of this, but there must be a way to essentially have 'global' variables for this type of situation shouldn't there be?