1

I have this code here which will be used quite a lot throughout my app:

require_once(APPPATH.'libraries/parse/autoload.php');

use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseException;
use Parse\ParseUser;
use Parse\ParseFile;
use Parse\ParseSessionStorage;
use Parse\ParseAnalytics;

I placed all of that code in a file called parse.php, however when I attempt to include that file use classes aren't being found.

Is there something I am doing wrong?

Here is the error I get:

Fatal error: Class 'ParseClient' not found in /xxx/xxx/xxx.php on line 11

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
Peter Stuart
  • 2,362
  • 7
  • 42
  • 73

1 Answers1

3

use doesn't include anything. It just imports the specified namespace (or class) to the current scope. If you want the classes to be autoloaded - read about autoloading functionality of PHP(http://php.net/manual/en/language.oop5.autoload.php)

Needhi Agrawal
  • 1,326
  • 8
  • 14
  • I know it doesn't include anything, but why is it when I place the code in a separate file, I get error, however if I replace require_once "parse.php" with the code above, it works absolutely fine? – Peter Stuart Jan 16 '15 at 12:53
  • You'll have to include/require the class anyway, otherwise PHP won't know about the namespace. – Needhi Agrawal Jan 16 '15 at 12:55
  • I do, if you look at my code I include the file that calls all the classes (the autoload.php) – Peter Stuart Jan 16 '15 at 13:04