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
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-19-2009, 10:11 PM   #1 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default The correct way to use multiple classes?

Is this even close to the "correct" way to do this?

main-class.php
PHP Code:
class main_class {
    private 
$someVar "Hello";
    public function 
talk($text) {
        echo 
$text;
    }

    public function 
dispBoard($boardID) {
        
$sql "SELECT * FROM " $config['mysql']['db-name'] . ".threads WHERE board-id =" $boardID "ORDER BY date";
        
$result mysql_query($sql);

        
// Then display the board.....
    
}

mysql-class.php
PHP Code:
class mysql_class extends main_class {
    protected function 
connect($host$username$password) {
        return 
mysql_connect($host$username$password);
    }


string-class.php
PHP Code:
class string_class extends main_class {
    public function 
trim($str) {
        return 
trim($str);
    }



What I'm trying to do is be able to call something like this
PHP Code:
$system->mysql_connect($config['mysql']['host'], $config['mysql']['username'], $config['mysql']['password']);
$system->dispBoard(12); // The board ID 
It would require more code than that, I didn't feel like writing it all for this post, but is that about the right way to do this? I want the separate "jobs" to be in separate files.

Should I just combine it all into one big file?
__________________
My Site
adamdecaf is offline  
Reply With Quote
 



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
Abstract Classes sketchMedia Advanced PHP Programming 18 02-28-2013 05:38 AM
abstract classes and constructors captainmerton Absolute Beginners 9 06-08-2009 06:36 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Passing multiple arguments to a function via one variable. delayedinsanity Advanced PHP Programming 10 05-07-2008 05:04 AM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM


All times are GMT. The time now is 11:32 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