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 6786069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:12:06+00:00 2026-05-26T17:12:06+00:00

i’m a php novice, and i’m wondering the best way to go about using

  • 0

i’m a php novice, and i’m wondering the best way to go about using previously defined class methods from a front facing ajax file. i trolled through 50 or more of the top questions looking for something similar to this, so my apologies if this has been asked before.

my project is set up using a front controller which calls initialize.php, which then includes all the class files i’ve made for this project thus far, whether those class methods/properties will be needed now or not (if this is super bad then someone please tell me an alternative :[[). so basically, for every request made on this site initialize is called, all of those classes are defined and two are instantiated immediately, those two being the classes i use for the database and sessioning/login stuff.

i’ve been doing this in my ajax files:

<?php
// login.ajax.php
require_once 'initialize.php';

$email = $_POST['email'];
$password = $_POST['password'];
$remember = $_POST['remember'];

global $session; // this is instantiated right away every time
$login = $session->login($email, $password);

echo json_encode($login);
?>

recent complications are now making me rethink this approach. constantly loading initialize seems really wasteful, but including/requiring just the necessary class files would be a pain in the ass at best. in this example i’d need to include session, which would also need two other classes to perform this login.

  • 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-26T17:12:07+00:00Added an answer on May 26, 2026 at 5:12 pm

    It seems you may wish to use PHP autoloading mechanism.

    To see some details, please go to the PHP autoloading documentation. You can read there that:

    Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).

    In PHP 5, this is no longer necessary. You may define an __autoload function which is automatically called in case you are trying to use a class/interface which hasn’t been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.

    Within your initialization file (or separate one, depending on your design decisions) just define __autoload() function that will be used to include required files:

    function __autoload($class_name) {
        include_once $class_name . '.php';
    }
    

    This should solve the issue / need of multiple requirement / inclusion declarations – from now on, when you instantiate some class and it is not available, newly defined function (__autoload()) will be called to include necessary files.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a

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.