Results 1 to 4 of 4

Thread: Placing classes in php

  1. #1
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default Placing classes in php

    Good day guyz, is it possible to put all class definitions in one file (class.php)?


    class sample1
    {


    }


    class sample2
    {


    }

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    include('directory/file.php');

    For bigger projects, it is normal to have a "main.php" page (or whatever you want to call it), then include that page in each of your normal pages. Within main.php, include every file you need like class definitions, functions, and other information you need to define each time, like for example a login routine.

    Note that if you need to include a page within another page, then the paths can change, so the easiest way to do that is this:
    include(dirname(__FILE__).'/directory/file.php');


    If you want help, please ask more specific questions-- does this answer everything?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    for modularity (which is part of what classes are all about), I like to keep each class in its own file. I can load classes as needed for each page, thus loading only what I need (or use __autoload, though I prefer not).

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
  •