symisc / PH7

An Embedded Implementation of PHP (C Library)
http://ph7.symisc.net
Other
494 stars 68 forks source link

Cannot extend from class inside include #5

Closed thekid closed 6 years ago

thekid commented 10 years ago

Define a class inside an include to see this happen:

$ cat main.php
<?php
include("x.php");

class Y extends X {

}

var_dump(new Y());

$ cat x.php
<?php
class X {

}

$ ./ph7.exe hello.php
hello.php: 4 Error: Inexistant base class 'X'
Compile error
thekid commented 10 years ago

This definitely is one of the harder parts to get right with PHP: While it seems quite straight-forward in the beginning, it actually means that during compilation, we most probably cannot verify the class yet. Instead we need to execute the source until class becomes available (which happens inside the include() statement), the go back to the verification phase. Beware: Not all other classes / interfaces / traits etc. may be available yet, so we might need to wait for them, too.

An idea might be to defer the verification until the first time the class actually gets used / in the above example, that's the new statement.