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

Have had to write my first proper multithreaded coded recently, and realised just how
We have had SharePoint where I work for a little while now, but we've
I have had to do this several times, usually when trying to find in
I have had a bug recently that only manifested itself when the library was
We have had issues with Mootools not being very backward compatible specifically in the
I have had a few problems with log files growing too big on my
We have/had a phantom delay in our app. This was traced to the initialisation
I have had many requests come in to a project that I work on,
What are some strategies that people have had success with for maintaining a change
I'm sure that all of us have had to deal with telecommuters at some

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.