In PHP, is there any way to automatically name a class based on the filename?

67 views Asked by At

I tried to do the following (which did not work):

class basename(__FILE__, '.php')

2

There are 2 answers

0
reko beko On

You can use basename() and $_SERVER['PHP_SELF'] to get current page file name that's what i understood from your question

php file

 $filename = basename($_SERVER['PHP_SELF']);

then compare the class with variable

0
Mike S On

No, you must specify the class name.

http://php.net/manual/en/language.oop5.basic.php