那么如何在PHP中创建一个全局类名?

I have a class called "user" with a function "createAccount". Within it I like to access another class via PostageApp::mail

But as this class is outside the scope it is not accessible. global seams to work for variables only. So how do I make a class name global?

include_once('../../ext_scripts/postageapp_class.inc');

class user {
  function createAccount(...) {
    global PostageApp;

    [...]

    $result = PostageApp::mail($mailTo, '', 'verify_email', array());
  }
}

If you are absolutely sure that the class has been defined in an included file, there is only one thing affecting its visibility in another file: I suppose the PostageApp class is in another namespace, as this is the only reason another class could have a different scope in PHP.

The keyword global is only necessary for global variables. Functions and classes are always accessible in any scope as soon as they have been declared.

The class have to be defined before you use it, so you have use require or require_once to include the file with your PostageApp class definition.

There is no notion of global for classes.

If you don't want to add the require, I advise you to look into autoloading.