虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

函数参数最好少于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. vpkcrure
    vpkcrure
    回复

    viagra generic http://cheapgogenvia.com/ - viagra pill viagra generic generic viagra viagra vs cialis

  2. JimDes
    JimDes
    回复

    best price for prazosin 1 mg purchase vardenafil cheap zoloft

  3. vpkcrure
    vpkcrure
    回复

    viagra vs cialis http://cheapgogenvia.com/ - online viagra viagra generic name over the counter viagra viagra online

  4. vthDrurb
    vthDrurb
    回复

    over the counter viagra http://buyviagenonline.com/ - women viagra viagra pill viagra online viagra

  5. wdriLiene
    wdriLiene
    回复

    cialis online http://cialishe.com/ - buy cialis generic cialis cialis generic п»їcialis

  6. vfgrPydaY
    vfgrPydaY
    回复

    cheap viagra http://viagracefo.com/ - generic viagra online for sale female viagra buy viagra generic viagra online for sale

  7. brliFaulP
    brliFaulP
    回复

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

  8. vfgrPydaY
    vfgrPydaY
    回复

    viagra http://viagracefo.com/ - viagra price viagra over the counter viagra online how long does viagra last

  9. vpkcrure
    vpkcrure
    回复

    viagra http://cheapgogenvia.com/ - viagra pills generic viagra online for sale viagra online women viagra

  10. vttqabaxy
    vttqabaxy
    回复

    viagra for men http://buyviagricxr.com/ - viagra for sale viagra for sale generic viagra viagra online

  11. wdriLiene
    wdriLiene
    回复

    online cialis http://cialishe.com/ - buy cialis cialis online cialis online buy cialis

  12. SueDes
    SueDes
    回复

    lisinopril 10mg prices compare can you buy ventolin over the counter in singapore where to get proscar without prescription lipitor 5 mg singulair medication in canada furosemide tablets amoxicillin 500 mexico buy viagra free shipping 20000 mg gabapentin buy generic cymbalta canada

  13. brliFaulP
    brliFaulP
    回复

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

  14. vthDrurb
    vthDrurb
    回复

    viagra price http://buyviagenonline.com/ - generic viagra viagra and alcohol herbal viagra viagra 100mg

  15. vtgdretelf
    vtgdretelf
    回复

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

  16. grdfscant
    grdfscant
    回复

    side effects of viagra http://viagraid.com/ - generic viagra viagra over the counter generic viagra viagra

  17. erfiUnada
    erfiUnada
    回复

    cheap viagra http://viagrajr.com/ - viagra online online viagra cialis vs viagra viagra pill

  18. vtgdretelf
    vtgdretelf
    回复

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

  19. vtgdretelf
    vtgdretelf
    回复

    cialis buy http://cialonlinesja.com/ - cialis online cialis cialis cialis 20mg

  20. vttqabaxy
    vttqabaxy
    回复

    viagra online http://buyviagricxr.com/ - viagra generic how long does viagra last female viagra womens viagra

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