Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[PHP] please criticize my PHP code

Options
  • 12-06-2013 11:13pm
    #1
    Closed Accounts Posts: 2,000 ✭✭✭


    I want to get rid of bad habits and therefore I'm asking people to criticize my PHP code. Feel free to point out what I'm doing right or wrong:
    http://goo.gl/qMNd6

    Many thanks!


Comments

  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    At a glance, looks well formatted. Maybe a few too many utility functions, but without knowing the exact purpose of the class, take that with a pinch of salt.

    You should look at namespacing for your own custom classes http://php.net/manual/en/language.namespaces.php if you're running this under PHP 5.3.

    Also, and it's probably just me, but some of the functions may return values that have not been set, or initialized as empty arrays, and some will return null, for example:
     public function fetchExpiring() {
            // browse all domains
            foreach ($this->_domains as $row) {
                // add domains between 1 and 30 days to result
                if ($row['dom_days_left']>1 && $row['dom_days_left']<=30)
                    $data[]=$row;
            }
            return $data;
        }
        //
    
    

    what if $this->_domains is 0 length? $data is never initialised and set, therefore the return type is null (or undefined). Consider using !empty() to determine if the $_domains array contains values.

    Hope this helps,
    Stephen


  • Closed Accounts Posts: 2,000 ✭✭✭fl4pj4ck


    point taken about uninitialized variables, thanks for your input
    out of curiosity: would it be acceptable to return -1 if not set? how would you deal with this?


Advertisement