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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[PHP] please criticize my PHP code

  • 12-06-2013 10: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, Registered Users 2 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