虫言虫语 虫言虫语

PHP整洁之道节选

in PHPread (139481) 文章转载请注明来源!

函数

函数参数最好少于2个

限制函数参数个数极其重要因为它是你函数测试容易点。有超过3个可选参数参数导致一个爆炸式组合增长,你会有成吨独立参数情形要测试。

无参数是理想情况。1个或2个都可以,最好避免3个。再多旧需要加固了。通常如果你的函数有超过两个参数,说明他多做了一些事。 在参数少的情况里,大多数时候一个高级别对象(数组)作为参数就足够应付。

Bad:

function createMenu($title, $body, $buttonText, $cancellable) {
  // ...
}

Good:

class menuConfig() {
  public $title;
  public $body;
  public $buttonText;
  public $cancellable = false;
}

$config = new MenuConfig();
$config->title = 'Foo';
$config->body = 'Bar';
$config->buttonText = 'Baz';
$config->cancellable = true;

function createMenu(MenuConfig $config) {
  // ...
}
jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

PHP
发表新评论
已有 37638 条评论
  1. vfgrPydaY
    vfgrPydaY
    回复

    viagra online http://viagracefo.com/ - buy generic 100mg viagra online generic viagra walmart cheap viagra viagra connect

  2. grdfscant
    grdfscant
    回复

    viagra over the counter http://viagraid.com/ - viagra online how long does viagra last herbal viagra generic viagra

  3. AlanDes
    AlanDes
    回复

    where to order viagra without a prescription can i buy glucophage online 2 propranolol buy seroquel india furosemide 20 mg tablet cost price of vermox in usa flagyl prescription finpecia online azithromycin 500g dapoxetine 30mg price anafranil tablet cephalexin500mg cap buspar 5mg cost can i buy lisinopril over the counter in canada antabuse 500mg avana singapore zofran price generic where can i buy nolvadex in south africa paxil 20mg cipro india

  4. vthDrurb
    vthDrurb
    回复

    viagra alternative http://buyviagenonline.com/ - online viagra otc viagra viagra viagra vs cialis

  5. brliFaulP
    brliFaulP
    回复

    cialis generic http://cialiisensf.com/ - cialis 20mg cialis buy generic cialis cialis

  6. vthDrurb
    vthDrurb
    回复

    buy viagra http://buyviagenonline.com/ - generic viagra online viagra generic name viagra online п»їgeneric viagra

  7. vpkcrure
    vpkcrure
    回复

    viagra http://cheapgogenvia.com/ - generic viagra walmart viagra and alcohol side effects of viagra how long does viagra last

  8. Brianrenly
    Brianrenly
    回复

    the full details check site

  9. vfgrPydaY
    vfgrPydaY
    回复

    cheap viagra http://viagracefo.com/ - viagra cost viagra generic viagra online generic viagra walmart

  10. vpkcrure
    vpkcrure
    回复

    female viagra [url=http://cheapgogenvia.com/]side effects of viagra[/url] п»їgeneric viagra viagra and alcohol buy viagra

  11. vttqabaxy
    vttqabaxy
    回复

    generic viagra walmart http://buyviagricxr.com/ - generic viagra otc viagra viagra viagra canadian pharmacy ezzz

  12. vttqabaxy
    vttqabaxy
    回复

    viagra over the counter http://buyviagricxr.com/ - viagra over the counter viagra generic viagra viagra generic

  13. erfiUnada
    erfiUnada
    回复

    viagra alternative http://viagrajr.com/ - viagra alternative buy viagra viagra 100mg generic viagra walmart

  14. wdriLiene
    wdriLiene
    回复

    cialis 20mg http://cialishe.com/ - cialis 20mg cialis 20mg п»їcialis п»їcialis

  15. vpkcrure
    vpkcrure
    回复

    how to take viagra http://cheapgogenvia.com/ - viagra online buy viagra online viagra generic viagra for women

  16. cialis buy
    cialis buy
    回复

    I visibly delay simply the ventilator to wisdom straight chief it. real money casino games vegas casino online

  17. grdfscant
    grdfscant
    回复

    viagra cost http://viagraid.com/ - online viagra viagra 100mg generic viagra cheap viagra

  18. brliFaulP
    brliFaulP
    回复

    cialis online http://cialiisensf.com/ - generic cialis cialis cialis online cialis generic

  19. Brianrenly
    Brianrenly
    回复

    more official site that guy

  20. erfiUnada
    erfiUnada
    回复

    viagra side effects http://viagrajr.com/ - how does viagra work generic viagra walmart cialis vs viagra viagra

博客已萌萌哒运行
© 2020 由 Typecho 强力驱动.Theme by Yodu
前篇 后篇
雷姆
拉姆