-1

I'm trying to integrate the Playfab PHP SDK into CakePHP 4.0.4,

but Cake doesn't like the following line (included in the SDK example):

$apiReflection = new ReflectionClass("PlayFab" . $PlayFabApi . "Api");

it outputs the following error:

Class 'App\Controller\ReflectionClass' not found

As far as I know ReflectionClass is native class in PHP, so I understand CakePHP is using some kind of PHP subset that doesn't allow ReflectionClass, probably because this class allows reverse engineering and so on.

Is there anything else I am missing? and most important, how can I make new ReflectionClass() constructor work without compromising the whole project security?

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
MiquelRoan
  • 23
  • 3

2 Answers2

2

As usual: if you want to instantiate a class from the global namespace, while your current code is in another namespace, you have to prefix the class name using a backslash. Try to use :

$apiReflection = new \ReflectionClass
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Nico Haase
  • 11,420
  • 35
  • 43
  • 69
2

After some more research I've found the solution was as simple as including:

use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
MiquelRoan
  • 23
  • 3