php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52406 spl_autoload support phar with namespace
Submitted: 2010-07-22 16:08 UTC Modified: 2011-11-16 14:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jinmoku at hotmail dot com Assigned:
Status: Not a bug Package: PHAR related
PHP Version: 5.3.3 OS: XP, OSX
Private report: No CVE-ID: None
 [2010-07-22 16:08 UTC] jinmoku at hotmail dot com
Description:
------------
spl_autoload_register don't load namespaces file in phar

Test script:
---------------
---- BEGIN TEST CODE ----
$phar = new Phar('MyPhar.phar');

$index = <<<DOC
<?php
	spl_autoload_register();
DOC;

$contents = <<<DOC
<?php
	namespace Framework;
	
	class Test
	{
		public function __construct()
		{
			echo 'hi';
		}
	}
DOC;
$phar->addFromString('index.php', $index);
$phar->addFromString('Framework/Test.php', $contents);

require_once('MyPhar.phar');
$test = new Framework\Test();
---- END TEST CODE ----

but this follow code work :

require_once('MyPhar.phar');
require_once('Framework\Test.php');
$test = new Framework\Test();



Expected result:
----------------
hi

Actual result:
--------------
Fatal error: spl_autoload() [function.spl-autoload]: Class Framework\Test could not be loaded

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-22 16:13 UTC] jinmoku at hotmail dot com
-Operating System: +Operating System: XP -PHP Version: 5.3.3RC3 +PHP Version: 5.3.3
 [2010-07-22 16:13 UTC] jinmoku at hotmail dot com
just like http://bugs.php.net/bug.php?id=51991 ;)
 [2010-07-22 20:09 UTC] jinmoku at hotmail dot com
-Operating System: XP +Operating System: XP, OSX
 [2010-07-22 20:09 UTC] jinmoku at hotmail dot com
On OSX 10.6.4

output :

��???�???
Fatal error: Class 'Framework\Test' not found in /Library/WebServer/Documents/test/index.php on line 26



require_once('Framework\Test.php');
don't run :

��????
Warning: require_once(Framework\Test.php): failed to open stream: No such file or directory in /Library/WebServer/Documents/test/index.php on line 26

Fatal error: require_once(): Failed opening required 'Framework\Test.php' (include_path='.:/usr/lib/php') in /Library/WebServer/Documents/test/index.php on line 26

and phar is not in PATH include_path Windows XP
 [2010-07-23 00:16 UTC] felipe@php.net
-Status: Open +Status: To be documented
 [2010-07-23 00:16 UTC] felipe@php.net
Hi, the spl_autoload() will try to find the 'framework/test.php', i.e. the lowercased name, so on *nix will fail because it's case-sensitive, and you are using $phar->addFromString('Framework/Test.php'...).

You must to use $phar->addFromString('framework/test.php', ...);
(the lowercased name to the spl_auload to find it)
 [2010-07-23 01:02 UTC] jinmoku at hotmail dot com
I try lowercase, but that doesn't work too, I make some tests with spl_autoload and it's work in lower and uppercase filename.
Why in osx (i don't try with other *nix) the phar is not in the include_path ?

it's work fine (always with the strange "��????") with this follow code :

require_once('MyPhar.phar');
set_include_path('phar://' . realpath('MyPhar.phar') . PATH_SEPARATOR . get_include_path());
require_once 'Framework/Test.php';
$test = new Framework\Test();

see ya ;)
 [2010-07-23 01:22 UTC] felipe@php.net
I can't reproduce the weird chars...

About this is work...:
require_once('MyPhar.phar');
set_include_path('phar://' . realpath('MyPhar.phar') . PATH_SEPARATOR . get_include_path());
require_once 'Framework/Test.php';

It's because that in this case the require_once doesn't look into the file system at all, but into the phar structure, so it doesnt search for the lowercased one, as in the other sample code.
 [2010-07-23 01:36 UTC] jinmoku at hotmail dot com
Do u have a sample code who doesn't work with the lowercase, I want to test in my osx ?

about :
> I can't reproduce the weird chars...

I've this in my phar 

Extract_Phar::go();
__HALT_COMPILER(); ?>e
 [2010-07-23 01:44 UTC] jinmoku at hotmail dot com
oups, caracteres don't passed, you can find the phar here : http://backfront.org/MyPhar.phar

;)
 [2010-07-23 01:59 UTC] felipe@php.net
What I am saying is:

- Using require_once you might use (lowercase not required):
$phar->addFromString('Framework/Test.php', $contents);
require_once 'Framework/Test.php'; // the search is non-lowercased

- Using spl_autoload() you must use (lowercase required):
$phar->addFromString('framework/test.php', $contents);
$test = new Framework\Test(); // spl_autoload() searchs for the lowercased namespace/classname.php
 [2010-07-23 11:11 UTC] jinmoku at hotmail dot com
Ok, I retry on XP and it's work, even if it isn't simple, a filename in project is not always in lowercase...

Unfortunately it's doesn't work on osx, we see : set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());

but after the require_once the phar path's gone, i'll check on other system and I come back

;)
 [2011-02-09 10:37 UTC] jinmoku at hotmail dot com
Only way to work :

$phar->addFromString(strtolower('index.php'), $index);
$phar->addFromString(strtolower('Framework/Test.php'), $contents);

or maybe do it in internal
 [2011-02-10 21:49 UTC] jinmoku at hotmail dot com
Add detect_unicode to off for OSX :

ini_set('detect_unicode', false);


I think all the files should be automatically put in lowercase.
 [2011-02-10 21:50 UTC] jinmoku at hotmail dot com
-Type: Bug +Type: Feature/Change Request -Package: SPL related +Package: PHAR related
 [2011-02-10 21:50 UTC] jinmoku at hotmail dot com
it's more a PHAR problem
 [2011-10-28 16:58 UTC] ralph at ralphschindler dot com
This is not an issue, spl_autoload() is working as described, and furthermore, 
this is not a PHAR issue.

Can someone close?

-ralph
 [2011-11-16 14:29 UTC] felipe@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


 [2011-11-16 14:29 UTC] felipe@php.net
-Status: Open +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 07:01:27 2024 UTC