TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-27-2012, 06:01 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Static Method Issue

Hi i hav extended the mysqli class and want to add some further functionality to the static method i have created for creation of the database access object (see below). I want to add some further functionality however to read in the current website url and then point to a different database based on the url. When i try to add code into the static method looking for certain characters in the $_SERVER['HTTP_HOST'] global variable i get error messages:

Call to a member function query() on a non-object

I assume i cant call global verianbles in a static method perhaps? Any guidance on what th issue is and how i might solve?

PHP Code:
        public static function getInstance() {

            if (empty (
self::$instance)) {
                
self::$instance = new DataLayer(DB_HOSTDB_USERDB_PASSDB_DATABASE) or die("Cannot connect to MySQL server!");
            }

            return 
self::$instance;

        } 
captainmerton is offline  
Reply With Quote
Old 01-28-2012, 08:45 AM   #2 (permalink)
The Wanderer
 
Join Date: May 2010
Posts: 19
Thanks: 1
core1024 is on a distinguished road
Default

Of cource you can. This error is not related with accessing globals. Somwhere in your code you're calling method of non-object variable. The easiest way would be to extend/edit your constructor method. This way you'll be sure that '$this' is instance of your class and you can call $this->query() without errors.
core1024 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static and Unstatic stuff Sirupsen General 0 10-22-2009 07:45 PM
Using the factory pattern (mad rantings of a mind without coffee) sketchMedia Advanced PHP Programming 35 09-25-2009 11:05 AM
Using static method to create objects captainmerton Absolute Beginners 3 06-03-2009 01:30 PM
Assigning non-static properties from a static method? delayedinsanity Advanced PHP Programming 4 07-10-2008 02:49 PM


All times are GMT. The time now is 05:34 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design