doushe2513 2013-10-21 21:46
浏览 144
已采纳

扩展时找不到类

I have a class MyClass that works fine. When I create an instance using $obj = new MyClass() works like a charm. The problem is, if I extend this class MyClass extends MyExtends, it gives me an error: class MyClass not found.

Because the devil is in the details, here are some:

1) MyClass instance is created in the same file (called MyClass.php).

$obj = new MyClass();
class MyClass extends MyExtends{
}

2) The creation of obj is called using ajax

if($_POST['myAjaxFlag']){
    $obj = new MyClass();
} 

3) The ajax call returns as success, but if I print the data returned, I get that class not found error php message.

  • 写回答

3条回答 默认 最新

  • dougutuo9879 2013-10-21 21:51
    关注

    This is because you declare the class "MyClass" after your initialisation

    obj = new MyClass();
    class MyClass extends MyExtends{
    
    }
    

    Corrected:

    class MyClass extends MyExtends{
    }
    obj = new MyClass();
    

    Should work then ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据