global classes and their problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Austrian Coder
Forum Newbie
Posts: 2
Joined: Wed Jul 23, 2003 2:24 pm

global classes and their problems

Post by Austrian Coder »

Hi!

I have the file database.php, which contains the class Database. Ans i have an file (global.php), wich looks like this:

<?php
session_start(); // start a new session or take the old one
require_once 'database.php';

// open database
$g_database = new Database();
$g_database->Connect();

?>

Here the test.php:

<?php

#require 'global.php'

$g_database->Function(......);
?>

At this line, $g_database->Function(......);, i get this fatal error: Call to a member function on a non-object in /.../test.php on ...

What i am doing wrong?
Thanks, Austrian Coder
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Well the '#' starts the line of a comment so you are never including/requiring 'global.php' in test.php
Austrian Coder
Forum Newbie
Posts: 2
Joined: Wed Jul 23, 2003 2:24 pm

Post by Austrian Coder »

Thanks... now it works... never code late in the night
Normaly i am a c(++) coder, so the '#'-statement is used often by me
Post Reply