[phpa] Explanation of class not found error

  • From: "Nick Lindridge" <nick@xxxxxxxxxxxxxxxxxxxxx>
  • To: phpa@xxxxxxxxxxxxx
  • Date: Tue, 2 Apr 2002 12:22:53 +0100 (BST)

All,

Here's the scenario that leads to the obscure case (in that noone has found
this up until now) that Tom reported with a class not being found. 

1. Class A inherits from class B, and class A gets loaded by PHPA.

2. Class B isn't defined yet.

3. When class A was cached, class B *was* defined. In this situation, as
PHPA expected B to be defined but wasn't, it will look for class B in an
attempt to bind class A after each subsequent file is compiled.

4. Class B is a class that inherits from class C, and class C *wasn't*
defined when class B was cached. In this case PHPA didn't expect class C to
be defined when it loaded class B. It loaded class B as an 'as yet unbound'
class, and Class B will get defined and bound to class C by PHP itself when
the file declaring class B it executes.

5. The file declaring class B is the last file to be compiled.

Point 5 is the crucial one. PHPA attempts to bind missing classes after
compilation of each file, but after the last compilation, in this scenario
class B will still be invisible and won't be made visible by PHP until the
file declaring it actually executes. Because that's after the final
compilation, PHPA never gets to bind class A to B once B is actually
visible.

The workaround in therefore to include a dummy and empty file after the
declaration of class B but within the same file. The include happens at
execution time, will be after PHP has made class B visible, and so causes
PHPA to perform another attempt at binding classes (of class A in this
case). As class B will now be defined, the binding of class A will succeed.

This will probably be fixed in 1.2p5

nick


------------------------------------------------------------------------
  www.php-accelerator.co.uk           Home of the free PHP Accelerator

To post, send email to phpa@xxxxxxxxxxxxx
To unsubscribe, email phpa-request@xxxxxxxxxxxxx with subject unsubscribe


Other related posts:

  • » [phpa] Explanation of class not found error