fonksiyon sona zaman değişken (nedeniyle fonksiyon sona ermesi) unset olacak çünkü, değil fonksiyonu, sınıfında VAR oluşturmanız gerekir ...
class helloWorld {
private $var;
function sayHello() {
echo "Hello";
$this->var = "World";
}
function sayWorld() {
echo $this->var;
}
}
?>
Eğer public olarak değişkeni bildirirseniz size private olarak değişken bildirirseniz, sadece aynı sınıfta erişilebilir ise, bu, tüm diğer sınıflar tarafından doğrudan erişilebilir ..
<?php
Class First {
private $a;
public $b;
public function create(){
$this->a=1; //no problem
$thia->b=2; //no problem
}
public function geta(){
return $this->a;
}
private function getb(){
return $this->b;
}
}
Class Second{
function test(){
$a=new First; //create object $a that is a First Class.
$a->create(); // call the public function create..
echo $a->b; //ok in the class the var is public and it's accessible by everywhere
echo $a->a; //problem in hte class the var is private
echo $a->geta(); //ok the A value from class is get through the public function, the value $a in the class is not dicrectly accessible
echo $a->getb(); //error the getb function is private and it's accessible only from inside the class
}
}
?>