SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Needed, Classes and such

    Ok, What i was really wondering is say i made a mysql class. To initiate that class i write a line such as $DB = new mysql(); Thats all fine and dandy however i was wondering if there was a way of checking if that had been initated.

    What im trying to get at is i want to have a whole bunch of classes and i need to know if they had been started and if not run that line for the ones that hadn't.

    If anyone could help me if this post makes any sense then i would be most grateful.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can check if a particular variable has been assigned a value yet with isset; in your example above you could do
    PHP Code:
    if(!isset($DB))
        
    $DB = new mysql(); 
    I don't know of a way to tell if there is an instance of a class already instantiated, though, without creating a new instance of one that has a static variable.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like your classes should be using a Singleton pattern. Follow the link provided by clamcrusher to find out more.

  5. #5
    SitePoint Addict Procode's Avatar
    Join Date
    Dec 2006
    Location
    New York
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just define all the classes in the top and know they are defined... thats what i do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •