Bug #75771 [NEW]: When using traits, class must be written prior to calling in same file.
| From: | sybrew at gmail dot com | Date: | Sun, 07 Jan 2018 04:18:12 +0000 |
| Subject: | Bug #75771 [NEW]: When using traits, class must be written prior to calling in same file. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213400@lists.php.net to get a copy of this message | ||
From: sybrew at gmail dot com
Operating system: *
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Bug
Bug description:When using traits, class must be written prior to calling in same file.
Description:
------------
When a class is called from the same file it's written, you should be
able to call them in any order.
However, when a class uses a trait, the order is strict.
Test script:
---------------
<?php
new A; // good.
new B; // fatal error.
class A {
function __construct() {
echo 'constructed A', "<br>\n";
}
}
class B {
use T;
function __construct() {
echo 'constructed B', "<br>\n";
$this->traitfunc();
}
}
new B; // good.
trait T {
function traitfunc() {
echo 'traitfunc called', "<br>\n";
}
}
Expected result:
----------------
constructed A
constructed B
traitfunc called
Actual result:
--------------
constructed A
FATAL ERROR Class 'B' not found on line number 4
--
Edit bug report at https://bugs.php.net/bug.php?id=75771&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75771&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75771&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75771&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75771&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75771&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75771&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75771&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75771&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75771&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75771&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75771&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75771&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75771&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75771&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75771&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75771&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75771&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75771&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75771&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75771&r=mysqlcfg