2011-12-23 10:02
浏览 70


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?


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


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

图片转代码服务由CSDN问答提供 功能建议

我有一个名为“user”的类,其函数为“createAccount”。 在其中我喜欢通过PostageApp :: mail

访问另一个类但是由于此类不在范围内,因此无法访问。 global 接缝仅适用于变量。 那么如何使类名全局?

  include_once('../../ ext_scripts /'); 
class user {
 function  createAccount(...){
 $ result = PostageApp :: mail($ mailTo,'','verify_email',array()); 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dsomm80482 2011-12-23 10:07

    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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题