php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52230 namespace & __autoload clash
Submitted: 2010-07-02 01:30 UTC Modified: 2010-07-02 14:54 UTC
From: spawn at frostdrake dot tk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: gentoo & ubuntu
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spawn at frostdrake dot tk
New email:
PHP Version: OS:

 

 [2010-07-02 01:30 UTC] spawn at frostdrake dot tk
Description:
------------
when you use __autoload($var) it will get the class needed depending on the file.
by using namespace and getting the class by a full path name
ex
new \class\name

__autload will then try to load classname

Test script:
---------------
/** index.php **/

function __autoload($var) {
  require_once($var.'.php');
}
//It will try to load the file Coreinit.php and not Core/init.php;
new Core\init

/** Core/init.php **/
namespace Core;
class init{
  function __construct(){
    echo 'Bingo..!'; 
  }
}

Expected result:
----------------
that autoload loads Core/init.php

Actual result:
--------------
autoload loads Coreinit.php

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-02 11:31 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-07-02 11:31 UTC] johannes@php.net
It tries to load Core\init.php. you have to translate this yourself to Core/init.php - mind the \ vs. /.
 [2010-07-02 14:47 UTC] felipe@php.net
-Package: Class/Object related +Package: Scripting Engine problem
 [2010-07-02 14:47 UTC] felipe@php.net
See bug #51991
We already fixed this issue. The \ is automatically converted to / on system where / is the dir separator.
 [2010-07-02 14:54 UTC] felipe@php.net
Errr, forgets. The fix was about the spl_autoload only. For custom autoloader it must be done manually. As Johannes said above.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 00:00:02 2025 UTC