I am trying to set a value from a method of a class and trying to get it in another method. The example code is as below. I think the below kind of set/get works in a Java class. Googled out but still could not find a relevant solution.
Searched: http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=how+to+share+data+across+functions+in+PHP&aq=f&aqi=&aql=&oq=&gs_rfai= http://stackoverflow.com/questions/2707442/pass-variable-number-of-variables-to-a-class-in-php http://stackoverflow.com/questions/1750837/php-call-member-variables-off-a-class-within-static-method
Thanks in advance.
<?php
class MyClass
{
public $cons;
function showConstant() {
$this->setConstant(100); /* assign value to variable here */
$this->showConstantGetter();
}
/* setter */
function setConstant($aCons) {
$cons = $aCons;
}
/* getter */
function getConstant() {
return $cons;
}
function showConstantGetter() {
echo "<br>getting const : ".$this->getConstant(); /* use the variable's value in this method here */
}
}
$classname = "MyClass";
$class = new MyClass();
$class->showConstant();
?>