>From the RFC:
>
> Code which invokes get_class() without parameters should be modified to
> use __CLASS__ or get_class($this) instead,
I don't think the first option is equivalent:
class C {
function printType() {
echo "__CLASS__ is " . __CLASS__ . "\n";
echo "get_class is " . get_class($this) . "\n";
}
}
class D extends C {
function printTypeInChild() {
echo "__CLASS__ is " . __CLASS__ . "\n";
echo "get_class is " . get_class($this) . "\n";
}
}
(new D)->printType();
(new D)->printTypeInChild();
// Output is:
__CLASS__ is C
get_class is D
__CLASS__ is D
get_class is D
And unless I'm missing something, the second option doesn't appear
usable with static methods, which is also a problem with
get_parent_class()
> while code which invokes
> get_parent_class() without parameters should be modified to use
> get_parent_class($this) instead.
What would the equivalent code get_parent_class() for static methods? e.g.
class A {}
class B extends A {
public static function foo() {
echo get_parent_class() . " \n";
}
}
b::foo();
cheers
Dan
Ack
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php