Doc #70800 [NEW]: Doc error on class definition order
| From: | joel at kociolek dot org | Date: | Tue, 27 Oct 2015 09:29:17 +0000 |
| Subject: | Doc #70800 [NEW]: Doc error on class definition order | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-12843@lists.php.net to get a copy of this message | ||
From: joel at kociolek dot org
Operating system: Any
PHP version: 5.6.14
Package: Class/Object related
Bug Type: Documentation Problem
Bug description:Doc error on class definition order
Description:
------------
---
From manual page: http://www.php.net/language.oop5.inheritance
---
(Followup to Bug #70783)
The doc states that
"Unless autoloading is used, then classes must be defined before they
are used. If a class extends another, then the parent class must be
declared before the child class structure. This rule applies to classes
that inherit other classes and interfaces."
This is not strictly true. There are cases that work and do not even
emit a warning that allows classes to be defined after they are first
used.
Test script:
---------------
All of these do work:
class B extends A {}
class A {}
class B extends A {}
class C extends B {}
class A {}
class C extends B {}
class A {}
class B extends A {}
class B extends A implements I { use T; }
class A {}
trait T {}
interface I {}
All of these produce fatal errors:
class C extends B {}
class B extends A {}
class A {}
(PHP Fatal error: Class 'B' not found)
trait T {}
class B extends A {}
class A { use T; }
(PHP Fatal error: Class 'A' not found)
interface I {}
class B extends A {}
class A implements I {}
(PHP Fatal error: Class 'A' not found)
class A { use U; }
trait U { use T; }
trait T {}
(PHP Fatal error: Trait 'U' not found)
Expected result:
----------------
The doc should use "should" instead of "must" and should ideally explain
when defining classes before they are used is a must and when it is
not.
"Unless autoloading is used, then classes should be defined before they
are used. If a class extends another, then the parent class should be
declared before the child class structure. This rule applies to classes
that inherit other classes and interfaces. As an exception to this rule,
classes that do [... explanation as to when it is not obligatory...] may
be used before they are defined"
Actual result:
--------------
Doc does not state which class definition order really works or not.
--
Edit bug report at https://bugs.php.net/bug.php?id=70800&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70800&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70800&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70800&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70800&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70800&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70800&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70800&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70800&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70800&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70800&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70800&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70800&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70800&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70800&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70800&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70800&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70800&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70800&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70800&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70800&r=mysqlcfg