Bug #69665 [Opn]: Classes must be declared before instantiating if using interfaces

From: Date: Tue, 19 May 2015 22:17:16 +0000
Subject: Bug #69665 [Opn]: Classes must be declared before instantiating if using interfaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192771@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69665&edit=1 ID: 69665 User updated by: mikkelpaulson+phpnet at gmail dot com Reported by: mikkelpaulson+phpnet at gmail dot com Summary: Classes must be declared before instantiating if using interfaces Status: Open Type: Bug Package: Class/Object related Operating System: Ubuntu 12.04.5 LTS PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: updated email Previous Comments: ------------------------------------------------------------------------ [2015-05-19 22:16:30] mikkelpaulson+phpnet at gmail dot com Description: ------------ PHP parses files for functions and classes before executing code. This is handy and improves code readability, but there's one exception: if a class is using an interface, then it must be declared before being referenced. If this is a technical limitation, the error message in this case should be more descriptive than the current "Class 'MyClass' not found". The PHP 4 to 5.0.x migration guide is the only place I've found in the documentation that mentions this limitation: http://php.net/manual/pl/migration5.incompatible.php "In some cases classes must be declared before use. It only happens if some of the new features of PHP 5 (such as interfaces) are used. Otherwise the behaviour is the old." Maybe after 10 years this should be fixed? Test script: --------------- http://pastie.org/10197520 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69665&edit=1

« previous php.bugs (#192771) next »