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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:33:19+00:00 2026-05-24T23:33:19+00:00

I imagine this is fairly simple and one I should be able to get

  • 0

I imagine this is fairly simple and one I should be able to get but I am having trouble with it. I can’t seem to find an answer for this anywhere.

Consider the scenario: I have two files (we’ll call them index.php and global.php). I am properly referencing the require_once() file.

Index.php:

<?php
require_once('./global.php');

$database = new database();
echo $database->dbname;
?>

Global.php:

<?php
class database {
public $dbname = 'jdoe';
}
?>

This does not output ‘jdoe’ on the index.php page. However…if I place the following into global.php, it works:

<?php
class database {
public $dbname = 'jdoe';
}

$database = new database();
echo $database->dbname;
?>
  • 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-24T23:33:19+00:00Added an answer on May 24, 2026 at 11:33 pm
    $database = new database();
    

    You forgot the parenthesis. Also, take a look at the php documentation for Classes and Objects if you need more information about using classes in php.

    Update:

    Reading up on PHP Class Properties I came across this little tid-bit:

    [Class member variables] must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

    I’m not 100% certain on this, but it seems like PHP is seeing your string assignment as “run-time information”. Try assigning your variable in the constructor (its probably better practice anyway).

    class database {
        public $dbname;
        function __construct() {
            $this->dbname= 'jdoe';
        }
        // Rest of class
    }
    

    Hope that helps! And if anyone could verify my assumption that would be great.

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

Sidebar

Related Questions

Ok guys I imagine this is easy but I can't seem to find how
I imagine this has a rather simple answer <% for user in @users %>
I imagine that this is a simple question, but I'm getting some strange results
Imagine this simple form <form action=<?php echo $_SERVER['REQUEST_URI']; ?> method=post> <fieldset> <legend>Contact Me</legend> <label
Imagine this case, but with a lot more component buckets and a lot more
Imagine a fairly simple HTML document <!DOCTYPE HTML > <html> <body> <table> <tr> <td>
I have a fairly straightforward question in Rails 3 to which I can't seem
I am fairly experienced with regular expressions, but I am having some difficulty with
Imagine this subroutine: sub test(&&) { my $cr1 = shift; my $cr2 = shift;
Imagine this scenario: You have a desktop and a laptop. The desktop has 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.