php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70178 Call class with interface in define
Submitted: 2015-07-31 18:08 UTC Modified: 2015-08-01 13:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: mimic23 at seznam dot cz Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.11 OS: windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mimic23 at seznam dot cz
New email:
PHP Version: OS:

 

 [2015-07-31 18:08 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-01 13:24 UTC] cmb@php.net
See <http://3v4l.org/6EsPe> vs. <http://3v4l.org/iPe7d>.
 [2015-08-01 13:42 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2015-08-01 13:42 UTC] bwoebi@php.net
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.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 10:00:01 2026 UTC