Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

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 97 views
1 answer 87 views
1 answer 95 views
1 answer 86 views
1 answer 108 views
...