SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: class question

  1. #26
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    it's because in maths, "hello" = 0.

    I see your point though. In may I was a C# fanatic, and looked down on PHP because of stuff like that.
    But, in the end, it's a feature of PHP, not a flaw. Maybe in PHP7, PHP will begin to require them. There's no demand for it though - it makes life easier.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  2. #27
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH JOY...i was just about to ask on my hosting company's forums (when are u upgrading to php5....i ask every 5/6 months)...turns out they did it 2 weeks ago! (it's just that php4 is the default).

    i'm so happy

  3. #28
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But, in the end, it's a feature of PHP, not a flaw.
    no....it's a flaw

  4. #29
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fluxman View Post
    ... also javascript let's u do myvar = 'hello' + 5....but let's not get onto javascript...
    But JavaScript is great Then again so is C#.

    All three (including PHP) are completely different tools for completely different circumstances.

  5. #30
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ye...kinda went off topic there.

    Currently i'm implementing arkinstalls class methods (which is what i actually did last time i needed to use classes last year, but forgot). I don't think it will cause any major problems cuz my website's pretty simple...but if anyone has any other ideas let me know.

    Many Thanks!

  6. #31
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Separating the DB code and SQL to a separate class may make this class far more extensible and reusable.
    Also I don't think it is too wise pulling every user into the object when they are already stored in the database. Only pull when you need.

    PHP Code:
    // ( object $db, $user, $pass, $host, $options)
    $store = new Users_Store_Database_MySql(null'user''pass');
    $store->setTable('users');
    $store->setColumn('realtablename''alias');

    $users = new Users($store);
    $find $users->find('alias''joe'); 
    PHP Code:
    <?php

    class Users {

        private 
    $store;

        public function 
    __construct ($store) {

            if (!
    is_object($store) || !($store instanceof Users_Store)) {
                throw new 
    User_Exception();
            }

            
    $this->store $store;

        }

    #------------------------------------------------------------------------------

        // Using a strided list
        // array('ColumnName', 'value')
        
    public function find () {

            if (
    func_num_args() == 0) {
                
    trigger_error('Cannot find anything without any arguments.');
                return 
    null;
            }

            
    // Setup expressions for a where clause, 'tablename' => 'value'

            
    $args func_get_args();
            
    $num  func_num_args();

            for (
    $i 0$i $num$i += 2) {
                
    $expr[$args[$i]] = $args[$i 1];
            }

            
    $r $this->store->fetchUsers($expr);
            return new 
    User($r);

        }

        
    // Many more functions...

    }
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •