php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69665 Classes must be declared before instantiating if using interfaces
Submitted: 2015-05-19 22:16 UTC Modified: 2017-01-02 14:34 UTC
Votes:4
Avg. Score:3.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:0 (0.0%)
From: mikkelpaulson+phpnet at gmail dot com Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 5.6.9 OS: Ubuntu 12.04.5 LTS
Private report: No CVE-ID: None
 [2015-05-19 22:16 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-19 22:17 UTC] mikkelpaulson+phpnet at gmail dot com
-: me at mikkel dot ca +: mikkelpaulson+phpnet at gmail dot com
 [2015-05-19 22:17 UTC] mikkelpaulson+phpnet at gmail dot com
updated email
 [2015-05-20 12:26 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2015-05-20 12:26 UTC] cmb@php.net
According to Dmitry's comment on bug #39758 I'm changing to
Feature Request. See also #30741.
 [2015-05-20 12:28 UTC] cmb@php.net
Related to bug #30741. See also <http://3v4l.org/jStA3>.
 [2017-01-02 14:34 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2017-01-02 14:34 UTC] nikic@php.net
Duplicate of bug #54708.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 10:03:35 2021 UTC