you have to create var in the class, not in the function, because when the function ends, the variable will be disabled (due to termination of the function) ...
class helloWorld {
private $var;
function sayHello() {
echo "Hello";
$this->var = "World";
}
function sayWorld() {
echo $this->var;
}
}
?>
public, , private, .
<?php
Class First {
private $a;
public $b;
public function create(){
$this->a=1;
$thia->b=2;
}
public function geta(){
return $this->a;
}
private function getb(){
return $this->b;
}
}
Class Second{
function test(){
$a=new First;
$a->create();
echo $a->b;
echo $a->a;
echo $a->geta();
echo $a->getb();
}
}
?>