|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 12:00:01 2025 UTC |
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?