note 107495 deleted from function.get-class by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:56:24 +0000 |
| Subject: | note 107495 deleted from function.get-class by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187850@lists.php.net to get a copy of this message | ||
Note Submitter: Voitcus at wp dot pl
----
Just to extend what Lanselot wrote on 11-Feb-2009
(http://php.mainseek.com/manual/en/function.get-class.php#88856).
There is a difference if you call this function with or without parameter in the class and one
inherited from it.
Let us consider (Lanselot's example slightly modified):
<?php
class A {
function foo() {
return get_class(); // no parameter
}
}
class B extends A {
}
$instance = new B();
echo $instance->foo(); //Prints 'A', not 'B' as might be expected.
?>
Instead try this:
<?php
class A {
function foo() {
return get_class($this); // the $this parameter!
}
}
class B extends A {
}
$instance = new B();
echo $instance->foo(); //Prints 'B'
?>