Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
backend
php
oop
classes_objects
37visibility_method.php
37visibility_method.php
<?php class A { //definiranje neke public,protected i private metode public function pub(){echo 'PublicMetoda ';} protected function prot(){echo 'ProtectedMetoda ';} private function priv(){echo 'PrivateMetoda ';} //CLASS - pristup metodi unutar self klase public function ispis_a() { $this->pub(); $this->prot(); $this->priv(); } } class B extends A { //SUBCLASS 1 - pristup metodi unutar child klase public function ispis_b() { $this->pub(); $this->prot(); //$this->priv(); javlja gresku } } class C extends B { //SUBCLASS 2 - pristup metodi unutar grandchild klase public function ispis_c() { $this->pub(); $this->prot(); //$this->priv(); javlja gresku } } //WORLD $obj_a=new A; echo $obj_a->pub(); //ispisuje: PublicMetoda //echo $obj_a->prot(); javlja gresku //echo $obj_a->priv(); javlja gresku echo "<br/>"; //CLASS $obj_a->ispis_a(); //ispisuje: PublicMetodaProtectedMetodaPublicMetoda echo "<br/>"; //SUBCLASS 1 $obj_b=new B; $obj_b->ispis_b(); //ispisuje: PublicMetodaProtectedMetoda echo "<br/>"; //SUBCLASS 2 $obj_c=new C; $obj_c->ispis_c(); //ispisuje: PublicMetodaProtectedMetoda var_dump($obj_a); var_dump($obj_b); var_dump($obj_c); ?>
Reload page
Preview
W3C validation
Edit Code