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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:53:11+00:00 2026-05-28T06:53:11+00:00

i have a class: class Connect { public function auth() { … do something

  • 0

i have a class:

class Connect
{
    public function auth()
    {
        ... do something
    }
}

and i have a function: getfile.php

<?php
require_once($GLOBALS['path']."connect.php");
?>

the i have the: connect.php

<?php
function connect( $host, $database )
{
   database connection here
}
?>

how can i use this functions inside my class like this:

class Connect
{
    require_once("getfile.php");
    public function auth()
    {
        connect( $host, $database )
        ... do query
    }
}

is this possible?

thanks

  • 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-28T06:53:12+00:00Added an answer on May 28, 2026 at 6:53 am

    Functions declared in the global scope is available globally. So you don’t have to include it where you need it, just include the file with the function in the beginning of your script.

    Secondly,

    class Connect
    {
        require_once("getfile.php");
        public function auth()
        {
            connect( $host, $database )
            ... do query
        }
    }
    

    this is just jibberish; you can’t execute something inside the class outside of methods. If you really just want something included ONLY when that specific file is needed in that specific method, do something like this:

    class Connect
    {
        public function auth()
        {
            require_once("getfile.php");
            connect( $host, $database )
            ... do query
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class to connect to my database, strip stuff and return things
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have a database class that I made that uses PDO to connect to
Below is part of a PHP database class someone else wrote, I have removed
I have a DBAdmin class that connects to the database, and then some other
I have class A: public class ClassA<T> Class B derives from A: public class
I have class with a member function that takes a default argument. struct Class
I have a MySQL singleton class written in PHP. Its code is listed below:
I have 4 classes, one Database helper and 3 defined like this: abstract class
I am a learner, I have a class db to help me connect and

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.