NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question about explicit returns

Michael B Allen ioplex at gmail.com
Fri Jan 11 13:56:35 EST 2008


On 1/11/08, Tod Dailey <christiandailey at gmail.com> wrote:
> When I'm writing a function that returns a Boolean that indicates that the
> given process failed or <snip> Verse inline returns, such as "if
> ($condition !== true) return false;" that builds a list of failure by
> exception.

Hi Tod,

I don't think it matters that much. I would rather spend time thinking
about the overall design. Just pick one technique that makes you happy
and stick to it.

This is how I would write it:

public function checkForSomething($record_id) {
    $yourObj = new SomeObject;

    if ($yourObj->loadObjectByRecordId($record_id)) {
        if (is_array($restrictedItems = $yourObj->getUnrestrictedItems())) {
            if ($yourObj->updateUnrestrictedItems(self::ObjectItemStatus)) {
                $this->setRecordStatusId($yourObj->getRecordStatusId());
                $this->setRestrictedItemList($restrictedItems);
                return true;
            }
        }
    }

    return false;
}

-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/



More information about the talk mailing list