What is the difference between __CLASS__, get_class() and get_called_class() in PHP

2 Answers

0 votes
class test {

  public function show() {
     echo '__CLASS__ : ' . __CLASS__ . "<br />";
     echo 'get_called_class() : ' . get_called_class() . "<br />";
     echo 'get_class($this) : ' . get_class($this) . "<br />";
     echo 'get_class() : ' . get_class() . "<br />";
  }
  
}

$c = new test();
$c->show();


  
/*
run:
   
__CLASS__ : test
get_called_class() : test
get_class($this) : test
get_class() : test
   
*/

 



answered Oct 8, 2017 by avibootz
0 votes
class test {

  public function show() {
     echo '__CLASS__ : ' . __CLASS__ . "<br />";
     echo 'get_called_class() : ' . get_called_class() . "<br />";
     echo 'get_class($this) : ' . get_class($this) . "<br />";
     echo 'get_class() : ' . get_class() . "<br />";
  }
  
}

class AClass extends test {}

$c = new AClass();
$c->show();


  
/*
run:
   
__CLASS__ : test
get_called_class() : AClass
get_class($this) : AClass
get_class() : test
   
*/

 



answered Oct 8, 2017 by avibootz

Related questions

1 answer 111 views
1 answer 100 views
1 answer 116 views
1 answer 101 views
1 answer 133 views
...