note 116364 added to function.get-class

From: Date: Fri, 19 Dec 2014 15:09:45 +0000
Subject: note 116364 added to function.get-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-201227@lists.php.net to get a copy of this message
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 ---- Server IP: 72.52.91.14 Probable Submitter: 78.32.68.180 ---- Manual Page -- http://php.net/manual/en/function.get-class.php Edit -- https://master.php.net/note/edit/116364 Del: integrated -- https://master.php.net/note/delete/116364/integrated Del: useless -- https://master.php.net/note/delete/116364/useless Del: bad code -- https://master.php.net/note/delete/116364/bad+code Del: spam -- https://master.php.net/note/delete/116364/spam Del: non-english -- https://master.php.net/note/delete/116364/non-english Del: in docs -- https://master.php.net/note/delete/116364/in+docs Del: other reasons-- https://master.php.net/note/delete/116364 Reject -- https://master.php.net/note/reject/116364 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201227) next »