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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:06:06+00:00 2026-06-07T02:06:06+00:00

I am trying to set up a class with commonly used tasks, such as

  • 0

I am trying to set up a class with commonly used tasks, such as preparing strings for input into a database and creating a PDO object. I would like to include this file in other class files and extend those classes to use the common class’ code.

However, when I place the common class in its own file and include it in the class it will be used in, I receive an error that states the second class cannot be found. For example, if the class name is foo and it is extending bar (the common class, located elsewhere), the error says that foo cannot be found. But if I place the code for class bar in the same file as foo, it works.

Here are the classes in question –
Common Class

abstract class coreFunctions {
    protected $contentDB;

    public function __construct() {
        $this->contentDB = new PDO('mysql:host=localhost;dbname=db', 'username', 'password');
    }

    public function cleanStr($string) {
        $cleansed = trim($string);
        $cleansed = stripslashes($cleansed);
        $cleansed = strip_tags($cleansed);
        return $cleansed;
    }
}

Code from individual class

include $_SERVER['DOCUMENT_ROOT'] . '/includes/class.core-functions.php';
$mode = $_POST['mode'];

if (isset($mode)) {
    $gallery = new gallery;
    switch ($mode) {
        case 'addAlbum':
            $gallery->addAlbum($_POST['hash'], $_POST['title'],
                               $_POST['description']);
    }
}

class gallery extends coreFunctions {

    private function directoryPath($string) {
        $path = trim($string);
        $path = strtolower($path);
        $path = preg_replace('/[^ \pL \pN]/', '', $path);
        $path = preg_replace('[\s+]', '', $path);
        $path = substr($path, 0, 18);

        return $path;
    }
    public function addAlbum($hash, $title, $description) {
        $title = $this->cleanStr($title);
        $description = $this->cleanStr($description);
        $path = $this->directoryPath($title);

        if ($title && $description && $hash) {
            $addAlbum = $this->contentDB->prepare("INSERT INTO gallery_albums
                                        (albumHash, albumTitle, albumDescription,
                                        albumPath)
                                        VALUES
                                        (:hash, :title, :description, :path)");
            $addAlbum->execute(array('hash' => $hash, 'title' => $title, 'description' => $description,
                                     'path' => $path));
        }
    }
}

The error when I try it this way is
Fatal error: Class 'gallery' not found in /home/opheliad/public_html/admin/photo-gallery/includes/class.admin_photo-gallery.php on line 10

  • 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-06-07T02:06:07+00:00Added an answer on June 7, 2026 at 2:06 am

    Still learning the ins and outs of OOP. After a few minutes of research I came across spl_autoload_register in the PHP documentation.

    I placed the coreFunctions class in /includes/classes/coreFunctions.class.php and the gallery class in /includes/classes/gallery.class.php

    My code then became:

    function cvfdAutoloader($class) {
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/classes/' . $class . '.class.php';
    }
    
    spl_autoload_register('cvfdAutoloader');
    $mode = $_POST['mode'];
    
    if (isset($mode)) {
        $gallery = new gallery;
        switch ($mode) {
            case 'addAlbum':
                $gallery->addAlbum($_POST['hash'], $_POST['title'],
                                   $_POST['description']);
        }
    }
    

    And it works! Would someone care to shed some light on what exactly is happening here that is different from just including coreFunctions?

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

Sidebar

Related Questions

I am trying to set my AsyncTask returning a custom class type such as
I am trying to set a custom class to an Iterator through the setInfoClass
In ASP.NET MVC3 I'm trying to set the css class that the validation error
I'm trying to set up integration tests using the AbstractTransactionalJUnit4SpringContextTests base class. My goal
I am trying to set a focus on a dropdown within GridView(gridViewDropDown class) when
I'm trying to set a static pointer variable in a class but I'm getting
Trying to initialize and set things up for a class as follows: class Accel
I'm trying to set up a class so that it's possible to initialize it
Trying to set this label to red I've got the following class: .redErrorText {
I am trying to set up a method inside a class that implements the

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.