Bug #70178 [Opn->Nab]: Call class with interface in define
| From: | bwoebi@php.net | Date: | Sat, 01 Aug 2015 13:42:08 +0000 |
| Subject: | Bug #70178 [Opn->Nab]: Call class with interface in define | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194874@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70178&edit=1
ID: 70178
Updated by: bwoebi@php.net
Reported by: mimic23 at seznam dot cz
Summary: Call class with interface in define
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: windows 7
PHP Version: 5.6.11
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Classes with interfaces or traits (or which extend other classes defined after them) need to be
always defined before there usage.
That's the result of some optimizations; do not rely on that. Always just put classes before
the code where they're used or use an autoloader.
Previous Comments:
------------------------------------------------------------------------
[2015-08-01 13:24:50] cmb@php.net
See <http://3v4l.org/6EsPe> vs. <http://3v4l.org/iPe7d>.
------------------------------------------------------------------------
[2015-07-31 18:08:38] mimic23 at seznam dot cz
Description:
------------
Hi, i found a bug with use static function or normal function in define. If class has any interface
-> Fatal error.
Tested in PHP 5.4.x, 5.6.x and 7.x
Test script:
---------------
// Fatal error (if class is without interface it's ok)
define ('XXX', Bagr::GetNew()->n); // Fatal error
interface IBagr {}
class Bagr implements IBagr
{
public $n = 1;
public static function GetNew() { return new Bagr(); }
}
echo XXX;
Expected result:
----------------
1
Actual result:
--------------
Fatal error: Uncaught Error: Class 'Bagr' not found in demo.php:3 Stack trace: #0 {main}
thrown in demo.php on line 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70178&edit=1