Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[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