php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46974 Closure and Namespaces bug! FATAL ERROR
Submitted: 2008-12-30 16:40 UTC Modified: 2016-01-24 04:22 UTC
From: info at netmosfera dot it Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.3.0alpha3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: info at netmosfera dot it
New email:
PHP Version: OS:

 

 [2008-12-30 16:40 UTC] info at netmosfera dot it
Description:
------------
hi,
i noticed there is a bug that causes a FATAL ERROR
please read the code
thank you for your time

Reproduce code:
---------------
file index.php:

<?php
namespace Clsure;
spl_autoload_register(function($c){
	echo $c = str_replace("\\", "-", $c) . ".php";
	require($c);
});
// TRY TO UNCOMMENT THIS LINE:
// $b=function(){};
$a = new Testing();
?>

file Clsure-Testing.php:
<?php namespace Clsure; class Testing{function __construct(){echo "constructor";}} ?>

Actual result:
--------------
Fatal error: Class 'Clsure\Testing' not found in on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-30 16:50 UTC] info at netmosfera dot it
uhm... autoload is not called!

another suggest:
Closure is a special class\type

so it must be global
in a namespace i have to use

public function method(\Closure $x){}

instead of

public function method(Closure $x){}

is it correct? Closure is a special type and final too
 [2008-12-30 17:19 UTC] info at netmosfera dot it
ok, with __autoload in global namespace works

if you remove the closure but works too

where's the problem?
 [2009-01-02 01:11 UTC] info at netmosfera dot it
hi, thanks for accepting this bug

i have one request, is possible to make autoloads for namespaces?
is this back compatible?

namespace a
{
      function __autoload(){echo "a";}
      new Pippo();
}


namespace b
{
      function __autoload(){echo "b";}
      new Pippo();
}

thank you
 [2009-01-09 18:55 UTC] stas@php.net
I think you can easily implement it in user-space by using either one autoloader checking class name or using multiple autoloaders and http://www.php.net/manual/en/function.spl-autoload-register.php

I'm not sure it is practical to do it in the engine as it would require a lot of search around for autoloaders by the engine. I think it's better done in user-space.
 [2011-04-08 20:48 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2016-01-16 13:34 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2016-01-16 13:34 UTC] danack@php.net
The initial code reported as a bug works, and the request for namespaced autoloaders is possible in userland code with no new core functionality needed.

If there is still an issue, please cam you clarify what it is?
 [2016-01-24 04:22 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 "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 13:01:29 2024 UTC