Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1049915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:41:27+00:00 2026-05-16T16:41:27+00:00

I have had a slight problem with autoloading in my namespace. As shown on

  • 0

I have had a slight problem with autoloading in my namespace. As shown on the PHP manual here: http://us.php.net/manual/en/language.namespaces.rules.php you should be able to autoload namespace functions with a full qualified name e.g. \glue\common\is_email().

Thing is I have a function spl_autoload_register(array($import, “load”)); within the initial namespace but whenever I try and call \glue\common\is_email() from the initial namespace it will not pass that autoload function but when using new is_email() (in the context of a class) it will. I don’t get it the manual says I can autoload from fully qualified names but I can’t :.

Here’s my code:

namespace glue;

require_once 'import.php';

use glue\import as import;
use glue\core\router as router;

$import = new import();

spl_autoload_register(array($import, "load"));

/** Works and echos glue\router **/
$router = new router();

/** Don't do nothing **/
$cheese = \glue\common\is_email($email);

I also tried this code as well:

namespace glue;

require_once 'import.php';

use glue\import as import;
use glue\core\router as router;
use glue\common;

$import = new import();

spl_autoload_register(array($import, "load"));

/** Works and echos glue\router **/
$router = new router();

/** Don't do nothing **/
$cheese = common\is_email($email);

and finally this code:

namespace glue;

require_once 'import.php';

use glue\import as import;
use glue\core\router as router;
use glue\common\is_email as F;

$import = new import();

spl_autoload_register(array($import, "load"));

/** Works and echos glue\router **/
$router = new router();

/** Don't do nothing **/
$cheese = F($email);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:41:27+00:00Added an answer on May 16, 2026 at 4:41 pm

    Here’s the only right answer.

    Every namespace needs its own spl_autoload_register() function.

    also, spl_autoload_register() syntax changed in 5.3:

    spl_autoload_register(__NAMESPACE__ . "\\className::functionName"));
    

    The following should work:

    namespace glue;
    
    require_once 'import.php';
    
    use glue\import as import;
    use glue\core\router as router;
    
    $import = new import();
    
    spl_autoload_register(__NAMESPACE__ . "\\$import::load"));
    
    /** Works and echos glue\router **/
    $router = new router();
    
    /** Don't do nothing **/
    $cheese = \glue\common\is_email($email);
    

    Here is some live code that Just works!

    in ../WebPageConsolidator.inc.php:

    class WebPageConsolidator
    {
        public function __construct() { echo "PHP 5.2 constructor.\n"; }
    }
    

    in test.php:

    <?php
    
    namespace WebPage;
    
    class MyAutoloader
    {
        public static function load($className)
        {
            require '../' . __NAMESPACE__ . $className . '.inc.php';
        }
    }
    
    spl_autoload_register(__NAMESPACE__ . "\\MyAutoloader::load");
    
    class Consolidator extends \WebpageConsolidator
    {
        public function __construct()
        {
            echo "PHP 5.3 constructor.\n";
    
            parent::__construct();
        }
    }
    
    // Output: 
    // PHP 5.3 constructor.
    // PHP 5.2 constructor.
    

    So I know it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had the following problem for a while and I am really not
I have had this problem w/ two seperate WYSWYG editors in my rails application
Have a slight problem. Trying to post XML to a server. To do this,
We have had our glassfish instance go down every two weeks for a while
I have had this issue countless times with my Flex applications. When I export
I have had another question similar to this and have tried to see if
I have had Delphi 2007 for a while. I tried the Delphi 2009 trial.
I have had a few problems getting this right, so I wanted to ask
I have had a talk with a friend of mine about the relative vulnerability
I have had been on a roller coaster trying to get ImageMagick to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.