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
42scope_methods.php
42scope_methods.php
<?php //upotreba scope operatora (::) class A { //definiranje metoda public function pub(){echo 'PublicMet ';} protected function prot(){echo 'ProtectedMet ';} private function priv(){echo 'PrivateMet ';} //definiranje static metoda public static function pubs(){echo 'PublicStatMet ';} protected static function prots(){echo 'ProtectedStatMet ';} private static function privs(){echo 'PrivateStatMet ';} //definiranje final metode public final function pubf(){echo 'PublicFinalMet ';} protected final function protf(){echo 'ProtectedFinalMet ';} private final function privf(){echo 'PrivateFinalMet ';} public function ispisA() { self::pub(); A::prot(); self::priv(); } public function ispisA_stat() { self::pubs(); A::prots(); self::privs(); } } class B extends A { public function ispisB() { parent::pub(); A::prot(); //parent::priv(); javlja gresku jer je private } public function ispisB_stat() { parent::pubs(); A::prots(); //parent::privs(); javlja gresku jer je priv } } /** WORLD **/ echo A::pub(); //echo A::prot(); javlja gresku //echo A::priv(); javlja gresku echo A::pubs(); //echo A::prot(); javlja gresku //echo A::priv(); javlja gresku echo A::pubf(); //echo A::protf(); javlja gresku //echo A::privf(); javlja gresku echo "<br/><br/>"; /** CLASS **/ $obj_a=new A; $obj_a->ispisA(); echo "<br/>"; $obj_a->ispisA_stat(); echo "<br/><br/>"; /** SUBCLASS **/ $obj_b=new B; $obj_b->ispisB(); echo "<br/>"; $obj_b->ispisB_stat(); ?>
Reload page
Preview
W3C validation
Edit Code