#39567 [NEW]: Cannot find Class definition when there is one

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #39567 [NEW]: Cannot find Class definition when there is one

    From: imkow at 163 dot com
    Operating system: WinXp sp2+Apache2.2+Mod_PHP
    PHP version: 5.2.0
    PHP Bug Type: Class/Object related
    Bug description: Cannot find Class definition when there is one

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2

    --
    Edit bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39567&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39567&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39567&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39567&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39567&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39567&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39567&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39567&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39567&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39567&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39567&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39567&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39567&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39567&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39567&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39567&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39567&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39567&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39567&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39567&r=mysqlcfg[/url]
    imkow at 163 dot com Guest

  2. Similar Questions and Discussions

    1. How to automatically add class definition to proxy
      I defined two typis in asmx file (.Net/C#/WebService): Class Parent { } Class ChildOne: Parent { }
    2. #25377 [Bgs]: Class variables can be added out of class definition
      ID: 25377 Updated by: helly@php.net Reported By: forseti at oak dot rpg dot pl Status: Bogus Bug Type: ...
    3. #25377 [Opn->Bgs]: Class variables can be added out of class definition
      ID: 25377 Updated by: sniper@php.net Reported By: forseti at oak dot rpg dot pl -Status: Open +Status: ...
    4. Where can I find the IPTC definition?
      I am looking for the (official) definition of the IPTC-tags. I have searched www.iptc.org but all I could find was documents on their news...
    5. Magic at class-definition time
      In an interview on http://www.codegeneration.net/>, Pragmatic Dave showed some interesting tricks. The article has a long URL, so use...
  3. #2

    Default #39567 [Opn->Fbk]: Cannot find Class definition when there is one

    ID: 39567
    Updated by: [email]tony2001@php.net[/email]
    Reported By: imkow at 163 dot com
    -Status: Open
    +Status: Feedback
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 09:55:38] imkow at 163 dot com

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    tony2001@php.net Guest

  4. #3

    Default #39567 [Fbk->Opn]: Cannot find Class definition when there is one

    ID: 39567
    User updated by: imkow at 163 dot com
    Reported By: imkow at 163 dot com
    -Status: Feedback
    +Status: Open
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 10:16:07] [email]tony2001@php.net[/email]

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.

    ------------------------------------------------------------------------

    [2006-11-21 09:55:38] imkow at 163 dot com

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    imkow at 163 dot com Guest

  5. #4

    Default #39567 [Opn]: Cannot find Class definition when there is one

    ID: 39567
    User updated by: imkow at 163 dot com
    Reported By: imkow at 163 dot com
    Status: Open
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:21:27] imkow at 163 dot com

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.

    ------------------------------------------------------------------------

    [2006-11-21 10:16:07] [email]tony2001@php.net[/email]

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.

    ------------------------------------------------------------------------

    [2006-11-21 09:55:38] imkow at 163 dot com

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    imkow at 163 dot com Guest

  6. #5

    Default #39567 [Opn->Bgs]: Cannot find Class definition when there is one

    ID: 39567
    Updated by: [email]tony2001@php.net[/email]
    Reported By: imkow at 163 dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:26:18] imkow at 163 dot com

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.

    ------------------------------------------------------------------------

    [2006-11-21 11:21:27] imkow at 163 dot com

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.

    ------------------------------------------------------------------------

    [2006-11-21 10:16:07] [email]tony2001@php.net[/email]

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.

    ------------------------------------------------------------------------

    [2006-11-21 09:55:38] imkow at 163 dot com

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    tony2001@php.net Guest

  7. #6

    Default #39567 [Bgs->Opn]: Cannot find Class definition when there is one

    ID: 39567
    User updated by: imkow at 163 dot com
    Reported By: imkow at 163 dot com
    -Status: Bogus
    +Status: Open
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    require("file1.php");
    $j= new A;
    $k= new B;
    class B extends A{}

    I've changed the code to ensure class A is defined.
    as shown above, only the line where $k in throws error..


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:33:28] [email]tony2001@php.net[/email]

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.

    ------------------------------------------------------------------------

    [2006-11-21 11:26:18] imkow at 163 dot com

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.

    ------------------------------------------------------------------------

    [2006-11-21 11:21:27] imkow at 163 dot com

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.

    ------------------------------------------------------------------------

    [2006-11-21 10:16:07] [email]tony2001@php.net[/email]

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.

    ------------------------------------------------------------------------

    [2006-11-21 09:55:38] imkow at 163 dot com

    Description:
    ------------
    Two files:
    file1.php:
    class A{}

    file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    when runing file2.php, it throws a Fatal Error, saying Class B can't be
    found in the line where "$obj=new B;" is.

    But, in following code, things will just be fine:
    class A{}
    $obj=new B;
    class B extends A{}


    I use an official release of PHP 5.2.0 under windows. All mods are also
    from Pecl.



    Reproduce code:
    ---------------
    //file1.php:

    class A{}



    //file2.php:
    require("file1.php");
    $obj=new B;
    class B extends A{}

    Expected result:
    ----------------
    nothing..

    Actual result:
    --------------
    ( ! ) Fatal error: Class 'B' not found in file2.php on line 2


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    imkow at 163 dot com Guest

  8. #7

    Default #39567 [Opn->Bgs]: Cannot find Class definition when there is one

    ID: 39567
    Updated by: [email]tony2001@php.net[/email]
    Reported By: imkow at 163 dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    Please read what I said in my previous comment.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:34:51] imkow at 163 dot com

    require("file1.php");
    $j= new A;
    $k= new B;
    class B extends A{}

    I've changed the code to ensure class A is defined.
    as shown above, only the line where $k in throws error..

    ------------------------------------------------------------------------

    [2006-11-21 11:33:28] [email]tony2001@php.net[/email]

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.

    ------------------------------------------------------------------------

    [2006-11-21 11:26:18] imkow at 163 dot com

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.

    ------------------------------------------------------------------------

    [2006-11-21 11:21:27] imkow at 163 dot com

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.

    ------------------------------------------------------------------------

    [2006-11-21 10:16:07] [email]tony2001@php.net[/email]

    Please change require("file1.php"); to
    require("/absolute/path/to/file1.php"); and see if it works.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/39567[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    tony2001@php.net Guest

  9. #8

    Default #39567 [Bgs->Opn]: Cannot find Class definition when there is one

    ID: 39567
    User updated by: imkow at 163 dot com
    Reported By: imkow at 163 dot com
    -Status: Bogus
    +Status: Open
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    do you mean that it's forbidden to write code like
    within one file:
    class A{}
    $j=new B;
    class B extends A{}

    or code like:

    $j=new B;
    class B{}

    is also forbidden.

    But at this moment they all work fine in php. if those mentioned are
    forbidden, maybe we should write something in the manual to clarify
    this...


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:42:44] [email]tony2001@php.net[/email]

    Please read what I said in my previous comment.

    ------------------------------------------------------------------------

    [2006-11-21 11:34:51] imkow at 163 dot com

    require("file1.php");
    $j= new A;
    $k= new B;
    class B extends A{}

    I've changed the code to ensure class A is defined.
    as shown above, only the line where $k in throws error..

    ------------------------------------------------------------------------

    [2006-11-21 11:33:28] [email]tony2001@php.net[/email]

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.

    ------------------------------------------------------------------------

    [2006-11-21 11:26:18] imkow at 163 dot com

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.

    ------------------------------------------------------------------------

    [2006-11-21 11:21:27] imkow at 163 dot com

    i have changed my code to absolute path.
    require("F:/LXH/Webs/pware/file2.php");
    $k= new B;
    class B extends A{}

    the problem is still there. a fatal error was thrown out.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/39567[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    imkow at 163 dot com Guest

  10. #9

    Default #39567 [Opn->Bgs]: Cannot find Class definition when there is one

    ID: 39567
    Updated by: [email]tony2001@php.net[/email]
    Reported By: imkow at 163 dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    No, I didn't mean this.
    I meant exactly what I said - there is no way to declare this class in
    compile time, so it's declared in runtime.
    And you get the error because you're trying to use the class which is
    not yet declared.
    Please keep this report a bogus. Thank you.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:44:52] imkow at 163 dot com

    do you mean that it's forbidden to write code like
    within one file:
    class A{}
    $j=new B;
    class B extends A{}

    or code like:

    $j=new B;
    class B{}

    is also forbidden.

    But at this moment they all work fine in php. if those mentioned are
    forbidden, maybe we should write something in the manual to clarify
    this...

    ------------------------------------------------------------------------

    [2006-11-21 11:42:44] [email]tony2001@php.net[/email]

    Please read what I said in my previous comment.

    ------------------------------------------------------------------------

    [2006-11-21 11:34:51] imkow at 163 dot com

    require("file1.php");
    $j= new A;
    $k= new B;
    class B extends A{}

    I've changed the code to ensure class A is defined.
    as shown above, only the line where $k in throws error..

    ------------------------------------------------------------------------

    [2006-11-21 11:33:28] [email]tony2001@php.net[/email]

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.

    ------------------------------------------------------------------------

    [2006-11-21 11:26:18] imkow at 163 dot com

    require("F:/LXH/Webs/pware/file1.php");
    a correction, it was file1.php, not file2.php
    but im sure the problem is still there.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/39567[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    tony2001@php.net Guest

  11. #10

    Default #39567 [Bgs]: Cannot find Class definition when there is one

    ID: 39567
    User updated by: imkow at 163 dot com
    Reported By: imkow at 163 dot com
    Status: Bogus
    Bug Type: Class/Object related
    Operating System: WinXp sp2+Apache2.2+Mod_PHP
    PHP Version: 5.2.0
    New Comment:

    All right. but you people have to notice this is still a design fault
    that should be addressed in somewhere. we php script developers don't
    know much about php's internal structure. we can hardly distinguish
    what is done in compile time and what is not. The problem isn't on the
    manual where you can learn. So people will be used to write code like
    this until something be pointed out or changed.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-21 11:49:29] [email]tony2001@php.net[/email]

    No, I didn't mean this.
    I meant exactly what I said - there is no way to declare this class in
    compile time, so it's declared in runtime.
    And you get the error because you're trying to use the class which is
    not yet declared.
    Please keep this report a bogus. Thank you.

    ------------------------------------------------------------------------

    [2006-11-21 11:44:52] imkow at 163 dot com

    do you mean that it's forbidden to write code like
    within one file:
    class A{}
    $j=new B;
    class B extends A{}

    or code like:

    $j=new B;
    class B{}

    is also forbidden.

    But at this moment they all work fine in php. if those mentioned are
    forbidden, maybe we should write something in the manual to clarify
    this...

    ------------------------------------------------------------------------

    [2006-11-21 11:42:44] [email]tony2001@php.net[/email]

    Please read what I said in my previous comment.

    ------------------------------------------------------------------------

    [2006-11-21 11:34:51] imkow at 163 dot com

    require("file1.php");
    $j= new A;
    $k= new B;
    class B extends A{}

    I've changed the code to ensure class A is defined.
    as shown above, only the line where $k in throws error..

    ------------------------------------------------------------------------

    [2006-11-21 11:33:28] [email]tony2001@php.net[/email]

    Expected behaviour.
    Class "B" cannot be declared in compile time, because class "A" is
    declared in another file.
    But in runtime, when you execute the line "$obj=new B;", the class "B"
    doesn't exist yet.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/39567[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=39567&edit=1[/url]
    imkow at 163 dot com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139