Bug #70783 [Opn->Nab]: Adding a trait to a class produces fatal error
Edit report at https://bugs.php.net/bug.php?id=70783&edit=1
ID: 70783
Updated by: requinix@php.net
Reported by: joel at kociolek dot org
Summary: Adding a trait to a class produces fatal error
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux / Ubuntu 14.04
PHP Version: 5.6.14
Block user comment: N
Private report: N
New Comment:
While classes can often be used before they are "defined" (in terms of where they are
located in a file), this does not apply once you introduce traits. With traits, classes must be
defined before they are used. Which is a good thing to do regardless.
trait wtf {}
class A {
use wtf;
}
class B extends A {}
Previous Comments:
------------------------------------------------------------------------
[2015-10-25 13:11:30] joel at kociolek dot org
Description:
------------
I had perfectly working code. I added a trait to one of the classes and it started to produce fatal
errors. I tried to cut down the complexity of the code and made the simplest example that I could
do. See below.
Test script:
---------------
<?php
class B extends A {}
trait wtf {}
class A {
use wtf;
}
echo "OK\n";
Expected result:
----------------
Should display OK
Actual result:
--------------
Displays:
Fatal error: Class 'A' not found in /home/joel/php-5.6.14/test.php on line 2
Please note that removing the "use" line from the sample code above makes it work (It
display "OK").
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70783&edit=1
Thread (2 messages)