NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question about explicit returns

Daniel Convissor danielc at analysisandsolutions.com
Fri Jan 11 15:55:49 EST 2008


I like returning as soon as possible.  This clarifies exactly what's 
happening.  Otherwise you need to read through the whole function.  Plus 
it dramatically cuts down on the amount of nesting.

I also try to put the short code bits at the top so you can read it right 
away and then move on to the big block.  For example, you have this 
block:

>         if (is_array($restrictedItems)) {
>             $result = $yourObj->updateUnrestrictedItems(...);
> 
>             if ($result === true) {
>                 $this->setRecordStatusId($yourObj->getRecordStatusId());
>                 $this->setRestrictedItemList($restrictedItems);
>                 $result = true;
>             }
>         } else {
>             $result = false;
>         }

which I'd change the initial test to negate the is_array() test:

         if (!is_array($restrictedItems)) {
             $result = false;
         } else {
             $result = $yourObj->updateUnrestrictedItems(...);
 
             if ($result === true) {
                 $this->setRecordStatusId($yourObj->getRecordStatusId());
                 $this->setRestrictedItemList($restrictedItems);
                 $result = true;
             }
         }

Enjoy,

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list