php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63915 Fatal error before spl_autoloading a trait
Submitted: 2013-01-06 01:53 UTC Modified: 2013-02-18 00:36 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: necktrox at gmail dot com Assigned:
Status: No Feedback Package: Dynamic loading
PHP Version: 5.4.10 OS: Windows 8 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: necktrox at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-06 01:53 UTC] necktrox at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.traits
---

Traits are not handled as classes and spl_autoload won't autoload them when they
are needed / when the class which uses it gets loaded.

Test script:
---------------
// File: /system/traits/Singleton.trait.php
namespace system\traits;
trait Singleton
{
    public static function getInstance() { /* ... */ }
}

// File: /system/classes/MyClass.class.php
namespace system\classes;
class MyClass
{
    use Singleton;
}

// File: /index.php
use system\traits;
use system\classes;

// My autoload takes the namespaces and use them as folders
// Autoload::registerLoader(BASE_PATH);
// Autoload::registerExtension("class");
// Autoload::registerExtension("trait");

$obj = Bootstrap::getInstance(); 
// Fatal error: Call to undefined method system\classes\Bootstrap::getInstance() in [Filepath] on line [Line]

//> When I include the Singleton-file in the MyClass-file there is no error

Expected result:
----------------
// No Error

Actual result:
--------------
Fatal error: Call to undefined method system\classes\Bootstrap::getInstance() in C:\xampp\htdocs\~\index.php on line 13

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-06 06:18 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-01-06 06:18 UTC] laruence@php.net
I think it should not be a "autoload" issue:

function autoload($name) {
    var_dump($name);
}

spl_autoload_register("autoload");

class A {
    use T;
}

//output:

"T"

could you please give us a simple reproduce script?
 [2013-02-18 00:36 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC