I have a file that declares a namespace in the beginning, then does an include of two supporting files that defines classes like X, Y, etc.
Now in the main file, after declaring the namespace, I can no longer create classes that extend X. I have not declared a namespace in X or Y, I assumed the definition at the top of the main file, before the includes, would take care of that? Shouldn’t the class just default resolve to my namespace\X?
For example, in my PHP file I do this in the beginning:
namespace SGOAuth;
include 'OAuth.php';
include 'CURL.php';
And later a class I define in this file tries:
class MyClass extends CURL {...}
But I get the error: SGOAuth\CURL not found
Thanks!
Unless the
CURLclass is declared in the namespaceSGOAuth, of course it won’t exist in the namespaceSGOAuth. Just including a file doesn’t mean it’s part of the namespace the file that includes the file is in (now that’s a sentence ;)). That would make namespaces pointless.CURL.phpfoo.phpSo
class CURLby default is in the global namespace. To extend it, you need toextends \CURL.