Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spl_autoload() doesn't support namespaces #2308

Closed
ezruneko opened this issue Apr 3, 2014 · 7 comments
Closed

spl_autoload() doesn't support namespaces #2308

ezruneko opened this issue Apr 3, 2014 · 7 comments

Comments

@ezruneko
Copy link

ezruneko commented Apr 3, 2014

The error:

\nFatal error: Class undefined: DI in /home/runeko/www/index.php on line 7

My folder structure:

  • core
    • DI.php
  • index.php
// index.php:
<?php
set_include_path( __DIR__ );
spl_autoload_extensions('.php');
spl_autoload_register();

$di = new core\DI();

//i tested too: 
//use core;
//$di = new DI();
//DI.php
<?php
namespace core;

class DI {
}
HHVM version:
root@akai:/var/log/hhvm# hhvm --version
HipHop VM 3.0.0-dev+2014.04.03 (rel)
Compiler: heads/master-0-g6398683df312015ebc40066dfe4b9242cc933a60
Repo schema: b4303360e484eee1f582365b9994eee150d450b0

is hhvm bugged? thanks.

@staabm
Copy link
Contributor

staabm commented Apr 3, 2014

php docs says the following about the 1. param for spl_register_autoload

The autoload function being registered. If no parameter is provided, then the default implementation of spl_autoload() will be registered. 

@scannell scannell changed the title Problem with spl_autoload_register(); Problem with default spl_autoload() Apr 3, 2014
@scannell
Copy link
Contributor

scannell commented Apr 3, 2014

Thanks for reporting this. I think this is probably just a bug with our implementation of spl_autoload() which is used if no SPL autoloader is registered. Feel free to submit a PR if you (or someone else reading this) gets to this before we do.

@nubs
Copy link

nubs commented Apr 3, 2014

There does appear to be a bug, but the code as written doesn't run under zend php. The DI.php file should be di.php (lowercase is important here) and there's a missing new in the index.php.

@ezruneko
Copy link
Author

ezruneko commented Apr 3, 2014

Miss edit. I remove the new keyword on post. But the poblem persist. On ubuntu 13.10 throws the error with DI.php and di.php.

@fredemmott fredemmott added this to the Lockdown milestone May 22, 2014
@fredemmott fredemmott self-assigned this May 22, 2014
@fredemmott
Copy link
Contributor

Here's a simpler index.php which shows the same problem

<?php
spl_autoload('core\DI', '.php');

@fredemmott fredemmott changed the title Problem with default spl_autoload() spl_autoload() doesn't support namespaces May 22, 2014
@fredemmott
Copy link
Contributor

Fix for spl_autoload() namespace support up for internal review (FB: D1344376)

This won't be much use until #2729 is fixed though

@fredemmott
Copy link
Contributor

Better fix (also for the wider issue): D1344838

fredemmott added a commit that referenced this issue May 30, 2014
Summary: - support namespaces
 - no need for it to be in C++
 - the C++ version didn't actually work when invoked via the autoloader or spl_autoload_call()

fixes #2729
fixes #2308

Reviewed By: @ptarjan

Differential Revision: D1344838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants