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

  • Home
  • SEARCH
  • 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 3272046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:47:13+00:00 2026-05-17T18:47:13+00:00

PHP 5.3.3-pl1-gentoo (cli) (built: Aug 17 2010 18:37:41) Hi all, I use a simple

  • 0

PHP 5.3.3-pl1-gentoo (cli) (built: Aug
17 2010 18:37:41)

Hi all, I use a simple autoloader in my project’s main file (index.php):

require_once("./config.php");
require_once("./app.php");
require_once("./../shared/SqlTool.php");

function __autoload($className) {
    $fn = 'file-not-exists-for-{$className}';
    if (file_exists("./specific/php/{$className}.php")) { $fn = "./specific/php/{$className}.php"; } else
     { $fn = "./../shared/{$className}.php";}
    require_once($fn);
}

$sql = new SqlHD(); // class SqlHD, in ./specific/php/SqlHD.php extends SqlTool
$web = new HTMLForm($sql); // class HTMLForm in HTMLForm.php
$app = new App($sql, $web); // class App in App.php
$app->Main();

The problem: without that require_once("./../shared/SqlTool.php");, script can’t execute SqlHD.php, because it can’t find SqlTool.php by itself, and for some reason it doesn’t uses autoload routine defined in main file.

I tried this:

spl_autoload_register(__NAMESPACE__ .'\Test::load');

class Test {
    static public function load($className){
        $fn = 'file-not-exists-for-{$className}';
        if (file_exists("./specific/php/{$className}.php")) { $fn = "./specific/php/{$className}.php"; } else
         { $fn = "./../shared/{$className}.php}";}
        echo realpath($fn);//"$curRealDir Filename $fn\n";
        echo "\n";
        require_once($fn);
    }   
}

Well,

PHP Warning:
require_once(./../shared/SqlTool.php}):
failed to open stream: No such file or
directory in
/home/beep/work/php/hauthd/index.php
on line 20 PHP Fatal error:
require_once(): Failed opening
required ‘./../shared/SqlTool.php}’
(include_path=’.:/usr/share/php5:/usr/share/php’)
in
/home/beep/work/php/hauthd/index.php
on line 20

So it doesn’t reacts to any request from extended class.

Last second idea: put spl_autoload_register to each file. But cannot put it to “extends” directive itself!

P.S. May rewrite SqlTool.php using Factory pattern so it would automatically return an instance of project-specifc class, but it seems to be not a best way, or it is..?

  • 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-17T18:47:13+00:00Added an answer on May 17, 2026 at 6:47 pm

    If SqlHD extends SqlTool, then your __autoload() function should include this automatically.

    Note you have an extra ‘}’ in your filename which is probably messing this up. (Which you have also copy ‘n’ pasted into your 2nd code snippet.)

    { $fn = "./../shared/{$className}.php}";}
    

    As an aside, I think you only need to require() inside your __autoload() function, rather than require_once(), since your __autoload() function is only called if it has not already been loaded.

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

Sidebar

Related Questions

PHP is one of those languages I use periodically, but usually have to dust
PHP's C source can be found at http://svn.php.net/viewvc/php/php-src/trunk/ . If I want to find
PHP: function generate_uid() { $uid = mt_rand(); $sql = SELECT user_id FROM user_registration; if
PHP's __autoload() ( documentation ) is pretty interesting to me. Here's how it works:
PHP's range function work like this in php : $leap_years = range(1900, 2000, 4);
PHP supports this: $z = 5; $str = z is $z; // result: z
PHP regular expression script to remove anything that is not a alphabetical letter or
PHP, 5.3 non thread safe window, also proven on PHP 5.2.9 on linux. Sample
php > require_once('System.php'); php > System::users(); PHP Fatal error: Call to undefined method System::users()

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.