473,668 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

global object from object?

I'm trying to set a object as global for access through out the rest
of my script ... {a basic SQL accessing object} however if I try
calling the object from with in another object it acts as if it isn't
global and hasn't been accessed at all ... weather I decalre it from
inside the object or declare it outside the object
I would rather not have to resort to the standard of refrenceing sence
I plan on having modular support and having this one object be a
global rathen then everyone refrencing it would just be easyer for
people to understandanywa ys heres some of the code
and mind you this is pretty basic so far
---------index.php----------------
<?php
include_once("c onfig.php");
include_once("l ibs/mod.class.php") ;
include_once("l ibs/DataBase.class. php");
include_once("l ibs/main.class.php" );
$site= new main();
$site->init();
$site->loop();
$site->close();
?>
--------end------------------------
--------main.class.php-----------
<?php
global $db;
class main {

function init () {
global $db;
$db = new DBAccess($confi g['database']);
}
function loop () {}
function close () {
$db->DBKill();
}
}
?>
----end-------------------------

---error------------------------
Fatal error: Call to a member function on a non-object in
main.class.php on line 11
-------------end----------------
I would rather get this finished before continuing to work on the code
sence accessing the database will lead to 90% of the work after this

and I have googled for the answer already and come up rather dry
Jul 17 '05 #1
2 8273

"WhyteWolf" <wh*******@fo ur-twenty.com> wrote in message
news:tc******** *************** *********@4ax.c om...
I'm trying to set a object as global for access through out the rest
of my script ... {a basic SQL accessing object} however if I try
calling the object from with in another object it acts as if it isn't
global and hasn't been accessed at all ... weather I decalre it from
inside the object or declare it outside the object
I would rather not have to resort to the standard of refrenceing sence
I plan on having modular support and having this one object be a
global rathen then everyone refrencing it would just be easyer for
people to understandanywa ys heres some of the code
and mind you this is pretty basic so far
---------index.php----------------
<?php
include_once("c onfig.php");
include_once("l ibs/mod.class.php") ;
include_once("l ibs/DataBase.class. php");
include_once("l ibs/main.class.php" );
$site= new main();
$site->init();
$site->loop();
$site->close();
?>
--------end------------------------
--------main.class.php-----------
<?php
global $db;
class main {

function init () {
global $db;
$db = new DBAccess($confi g['database']);
}
function loop () {}
function close () {
$db->DBKill();
}
}
?>
----end-------------------------

---error------------------------
Fatal error: Call to a member function on a non-object in
main.class.php on line 11
-------------end----------------
I would rather get this finished before continuing to work on the code
sence accessing the database will lead to 90% of the work after this

and I have googled for the answer already and come up rather dry


Variables in PHP are considered local unless declared 'global' in a given
scope; your initial 'global $db' is not required and indeed makes no sense
at file scope.

Example from the variable scope help (at
http://uk.php.net/manual/en/language...es.scope.php):
<?php
$a = 1;
$b = 2;

function Sum()
{
global $a, $b;

$b = $a + $b;
}

Sum();
echo $b;
?>
Garp
Jul 17 '05 #2
On Wed, 30 Jun 2004 22:58:53 GMT, "Garp" <ga***@no7.blue yonder.co.uk>
wrote:

"WhyteWolf" <wh*******@fo ur-twenty.com> wrote in message
news:tc******* *************** **********@4ax. com...
I'm trying to set a object as global for access through out the rest
of my script ... {a basic SQL accessing object} however if I try
calling the object from with in another object it acts as if it isn't
global and hasn't been accessed at all ... weather I decalre it from
inside the object or declare it outside the object
I would rather not have to resort to the standard of refrenceing sence
I plan on having modular support and having this one object be a
global rathen then everyone refrencing it would just be easyer for
people to understandanywa ys heres some of the code
and mind you this is pretty basic so far
---------index.php----------------
<?php
include_once("c onfig.php");
include_once("l ibs/mod.class.php") ;
include_once("l ibs/DataBase.class. php");
include_once("l ibs/main.class.php" );
$site= new main();
$site->init();
$site->loop();
$site->close();
?>
--------end------------------------
--------main.class.php-----------
<?php
global $db;
class main {

function init () {
global $db;
$db = new DBAccess($confi g['database']);
}
function loop () {}
function close () {
$db->DBKill();
}
}
?>
----end-------------------------

---error------------------------
Fatal error: Call to a member function on a non-object in
main.class.php on line 11
-------------end----------------
I would rather get this finished before continuing to work on the code
sence accessing the database will lead to 90% of the work after this

and I have googled for the answer already and come up rather dry


Variables in PHP are considered local unless declared 'global' in a given
scope; your initial 'global $db' is not required and indeed makes no sense
at file scope.

Example from the variable scope help (at
http://uk.php.net/manual/en/language...es.scope.php):
<?php
$a = 1;
$b = 2;

function Sum()
{
global $a, $b;

$b = $a + $b;
}

Sum();
echo $b;
?>

I understand that unforchantly it doens't help with the problem ...
the first global $db was an atifact I forgot to remove from messing
around with this ... the fact remains that I can't call the global $db
from inside an object weather or not the global was created in the
object or not, basicly I can't access varables or objects that are
created outside the object
basicly from what I'm seeing in the testing that I'm doing is the the
refrence is local even with "global" when dealing with objects and
that I'm most likely going to have to use the refrencing anyway
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2535
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
9
2380
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not any of the response.write lines from inside the sub. ******************************************* <%@ Application Language="VB" %> <script runat="server">
15
2464
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like to acomplish the same functionality in asp.net.
8
4859
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web page. I will be grateful if some one can help me understand the difference.
16
3215
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for me. I was doing research on JavaScript inheritance recently (simplifying it in particular) and after reading 10.1.1, 10.1.3 and some other sections of ECMA262 I got a hint on accessing global object from different than global scope.
3
2764
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions doesn't actually give any insight.
2
2332
by: arun1985 | last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file. Server Error in '/' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
15
2043
by: Bob | last post by:
Is there anyway to access the global object from inside a function other than doing a "var _global = this;" before declaring the function? Thanks
112
5425
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.