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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:12:38+00:00 2026-05-16T14:12:38+00:00

So i have this class that includes some custom functions named class.php I have

  • 0

So i have this class that includes some custom functions named class.php
I have another file called config.php that includes

require('engine.class.php');
$engine = new engine;

config.php also requires functions.php to run like:

require('functions.php');

i have a function in functions.php that uses $engine eg:

function login($username, $password){
    return $engine->mysql_query('SELECT `user_id` WH...', 'array);//this is custom function in class.php
}

but when i run the page that reuires config.php i get some error like:

Fatal error: Call to a member function mysql_query() on a non-object in ../somedir/functions.php on line 3
  • 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-16T14:12:38+00:00Added an answer on May 16, 2026 at 2:12 pm

    Global variables are indisputably evil. Any one who tells you to use them does not have scope experience in dealing w/ code that uses them. Unfortunately, there are far more PHP coders using globals than any other language, in my experience, largely due to ignorance.

    Virtually every class should be self-consistent, meaning that it shouldn’t matter how many times you substantiate it into an object via new. The only exception is the Singleton pattern, but real-world instances where singletons are desirable are so rare that virtually every use of those is also an uncalled design flaw that just tightly couples code, which is also a very bad thing.


    PHP caches DB connections, so you can have an unlimited mysql_connect()s in the same program and it will only connect once per page load (unless you manually close it). So remove the $engine from your config.php immediately and rewrite all your code to this:

    function login($username, $password)
    {
        $engine = new Engine;
        //this is custom function in class.php
        return $engine->mysql_query('SELECT `user_id` WH...', 'array);
    }
    

    I’ll happily elucidate more, if you need it.

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

Sidebar

Related Questions

I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have this small class called City that simply holds some information about a
I have this class that have a function to load other classes and create
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class that has many class members, and a lot of different
I have this c# class that calculates n choose k and then generates all
I have class that looks like this: class A { public: class variables_map vm
I have a class that contains this class method: def self.get_event_record(row, participant) event =
I have a Handler class that looks like this: class Handler{ public $group; public
Assume I have a class that looks like this: class Sample { public string

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.