Uncaught ReflectionException in PHP(How to solve it)


#1

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

<?php
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.


#2

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


#3

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