Uncaught ReflectionException in PHP(How to solve it)

While trying to learn how to use the PHP ReflectionClass, I run into this problem Fatal error: Uncaught ReflectionException: Class \DatabaseTable does not exist in C:\xampp\htdocs\img\index.php:5 Stack trace: #0 C:\xampp\htdocs\img\index.php(5): ReflectionClass->__construct(‘\DatabaseTable’) #1 {main} thrown in C:\xampp\htdocs\img\index.php on line 5 .

Meanwhile (just for testing purposes), index.php, classInfo.php and DatabaseTable.php are all in the same folder.

This is the index.php file

require 'classInfo.php';
require 'DatabaseTable.php';

$class = new ReflectionClass('\\DatabaseTable');

echo classInfo::getData($class);

The classInfo.php class has just a single method and it is static.

Why are you passing the name of the file as “\DatabaseTable”?

That is where the problem is. I thought of namespacing it before. It is now working after removing the namespace

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.