#44848 [Opn->Fbk]: autoload fails with complex loading scheme

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               44848
 Updated by:       [email protected]
 Reported By:      nicolas dot grekas+php at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: *
 PHP Version:      5.*CVS, 6CVS (2009-01-21)
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/




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

[2009-01-05 20:59:06] pinochet dot pl at gmail dot com

I have the same behavior on 5.3 version and 1.01.2009 Snap UBUNTU 8.10

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

[2008-11-03 10:49:21] nicolas dot grekas+php at gmail dot com

Doesn't work with windows snaps [2008-Nov-03 08:00:00].
I got exactly the same behavior

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

[2008-06-05 08:33:59] jille at hexon dot cx

I tried creating a work-around for this.
However, this didn't work:
So class B is half-existent ?
You can not define it, but it also doesn't exists...

<?php

  function __autoload($class)
  {
          switch ($class)
          {
          case 'A':
          case 'B':
                  if(class_exists('B', false))
                    return;
                  class B extends C {};
                  break;

          case 'C':
                  class C {};
                  class A extends B {};
                  break;

          }
  }

  echo (int) class_exists('A');
?>

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

[2008-04-27 21:22:46] nicolas dot grekas+php at gmail dot com

Description:
------------
Hard to explain, see code... I think that PHP should be able to handle
this kind of loading scheme.

Here is what I thought this code would do :
1. __autoload('A') is called
2. inside this call for A:
   2.1 class B is defined, which extends C
   2.2 as C is not defined, __autoload('C') is called
   2.3 inside this call for C:
       2.3.1 class C is defined
       2.3.2 (now we have everything needed for class B, haven't we ?)
       2.3.3 class A extends B
   2.4 we leave the __autoload('C') context
3. we leave the __autoload('A') context

The bug is at step 2.3.3 : "class A extends B" triggers an
autoload('B'), which should not occurs, as B should be already defined,
thanks to 2.3.2...

Reproduce code:
---------------
<?php

function __autoload($class)
{
        switch ($class)
        {
        case 'A':
        case 'B':
                class B extends C {};
                break;

        case 'C':
                class C {};
                class A extends B {};
                break;

        }
}

echo (int) class_exists('A');


Expected result:
----------------
1

Actual result:
--------------
Fatal error: Cannot redeclare class B in [...] on line 9



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


-- 
Edit this bug report at http://bugs.php.net/?id=44848&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.