Voting

: six minus five?
(Example: nine)

The Note You're Voting On

RQuadling at GMail dot com
10 years ago
With regard to getting the class name from a namespaced class name, then using basename() seems to do the trick quite nicely.

<?php
namespace Foo\Bar;

abstract class
Baz
{
public function
report()
{
echo
'__CLASS__ ', __CLASS__, ' ', basename(__CLASS__), PHP_EOL,
'get_called_class ', get_called_class(), ' ', basename(get_called_class()), PHP_EOL;
}
}

class
Snafu extends Baz
{
}

(new
Snafu)->report();
?>

produces output of ...

__CLASS__ Foo\Bar\Baz Baz
get_called_class Foo\Bar\Snafu Snafu

<< Back to user notes page

To Top