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 04-26-2008, 02:35 AM   #1 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 12
Thanks: 0
trs21219 is on a distinguished road
Help Sibling Classes not getting along

ok here is my prediciment. i have just been recently working with php classes and oop.

i have a system class that i have contain all the other classes (they extend system)

Class System
  • database extends system
  • security extends system

how can i get the security and database classes to be able to access each other's functions without including each class file in each function that i want to use that class in

ex. i want to use
PHP Code:
$database -> query("query here"); 
from my security class without including database.class.php in each function i want to call something from the database in

if someone could shed some light on this i would really really appriciate it.

thanks
trs21219 is offline  
Reply With Quote
Old 04-26-2008, 11:00 AM   #2 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

you should have a property in your security class that would be an instance of database class:

PHP Code:
class Security
{
    private 
$db;

    public function 
__construct()
    {
        
$this->db = new Database();
    }

    public function 
blabla
    
{
        
$this->db->query()....
    }

Also it would be better to have a method like getDb() that will return the database object in stead of accessing to the variable directly.
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 04-26-2008, 04:38 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Freenity is right. Well, not right, but it's also my most favourite way of implementation. Obviously there are occasions where inheritance is the sensible approach.

In Freenity's example, there is no limitation to how many object levels you could have. Such as like:

php Code:
$this->pDb->pResult->pRow->name;

Oh the joys of OOP!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 04-27-2008, 03:57 AM   #4 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 12
Thanks: 0
trs21219 is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Freenity is right. Well, not right, but it's also my most favourite way of implementation. Obviously there are occasions where inheritance is the sensible approach.

In Freenity's example, there is no limitation to how many object levels you could have. Such as like:

php Code:
$this->pDb->pResult->pRow->name;

Oh the joys of OOP!
lol thanks everyone i think i got it.
trs21219 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


All times are GMT. The time now is 10:46 PM.

 
     

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