I am trying to load a class for a PHP script that I wrote using class documentation to work.
Since my server is running PHP 5.3, the documentation recommends loading the class as follows:
spl_autoload_register(function($class){ if (file_exists('/webgit/webroot/home/myUsername/www/elastica/lib/' . $class . '.php')) { echo " found \n "; require_once('/webgit/webroot/home/myUsername/www/elastica/lib/' . $class . '.php'); } else { echo " not found! "; } });
The only thing that is different is that I included the echo in the set of if and else. Also myUsername is actually my username in the file system path on the server.
Then it (the documentation) assumes that I am making a new instance of the class as follows:
$elasticaClient = new \Elastica\Client();
However, I get an error that the class was not found. Here is exactly what is printed, including the error and the set of my if-else:
not found! Fatal error: Class 'Elastica \ Client' not found in /webgit/webroot/home/myUsername/www/elastica/index.php on line 17
line 17 is the line where I am trying to make an instance of the class.
now, index.php is the code above and it is on my server at / webgit / webroot / home / myUsername / www / elastica /
and all class files are in / webgit / webroot / home / myUsername / www / elastica / lib /
so I donβt understand why it cannot find / load the class.
I really appreciate any help in resolving this issue.
source share