Req #69665 [Opn]: Classes must be declared before instantiating if using interfaces
| From: | cmb@php.net | Date: | Wed, 20 May 2015 12:28:09 +0000 |
| Subject: | Req #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-192785@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
Updated by: cmb@php.net
Reported by: mikkelpaulson+phpnet at gmail dot com
Summary: Classes must be declared before instantiating if
using interfaces
Status: Open
Type: Feature/Change Request
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:
Related to bug #30741. See also <http://3v4l.org/jStA3>.
Previous Comments:
------------------------------------------------------------------------
[2015-05-20 12:26:20] cmb@php.net
According to Dmitry's comment on bug #39758 I'm changing to
Feature Request. See also #30741.
------------------------------------------------------------------------
[2015-05-19 22:17:16] mikkelpaulson+phpnet at gmail dot com
updated email
------------------------------------------------------------------------
[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