2

For debugging and testing purposes, I have created an "external" php file in the top directory of my Symfony project, and I call it with php from the command line. So far I did not succeed in using Symfony's default autoloading in that external file. I tried each of the following in turn the beginning of the file :

require 'app/autoload.php'; 

require 'vendor/autoload.php'

require 'composer/autoload_real.php'

But none of them work : every time I try something like

$check=class_exists(AppBundle/Entity/User);

my debugger tells that $check is set to false so that my User class is not recognized by php. What is the correct way to do this ?

1 Answer 1

2

The first require is sufficient (that's the Symfony autoloader) it loads the other two files itself.

class_exists returns false because the class isn't autoloaded yet therefore the function returns false.

require 'app/autoload.php'; // This autoloader loads also your vendors and composer
$user = new AppBundle/Entity/User(); // now the autoloader is called!
$check=class_exists(AppBundle/Entity/User); // the class is autoloaded so true!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.