虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

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

  2. vpkcrure
    vpkcrure
    回复

    cheap viagra http://cheapgogenvia.com/ - how to take viagra viagra vs cialis viagra viagra online

  3. wdriLiene
    wdriLiene
    回复

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

  4. vpkcrure
    vpkcrure
    回复

    generic viagra http://cheapgogenvia.com/ - viagra dosage viagra vs cialis otc viagra women viagra

  5. vthDrurb
    vthDrurb
    回复

    what does viagra do http://buyviagenonline.com/ - viagra viagra pills viagra pill viagra connect

  6. KimDes
    KimDes
    回复

    propecia buy

  7. CarlDes
    CarlDes
    回复

    buy acyclovir cream uk xenical pills canada can you buy elimite cream over the counter cymbalta 25mg how much is amoxil

  8. vfgabaxy
    vfgabaxy
    回复

    viagra alternative http://cheapvirgaraonline.com/ - viagra generic name how to get viagra side effects of viagra generic viagra

  9. vfgabaxy
    vfgabaxy
    回复

    viagra for women http://cheapvirgaraonline.com/ - viagra 100mg viagra cheap viagra cheap viagra

  10. brliFaulP
    brliFaulP
    回复

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

  11. erfiUnada
    erfiUnada
    回复

    viagra 100mg http://viagrajr.com/ - viagra and alcohol what does viagra do viagra dosage viagra connect

  12. vtgdretelf
    vtgdretelf
    回复

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

  13. brliFaulP
    brliFaulP
    回复

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

  14. brliFaulP
    brliFaulP
    回复

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

  15. SueDes
    SueDes
    回复

    plaquenil price us robaxin prescription medication generic form of seroquel purchase toradol without prescription buy cialis generic india buy kamagra online usa chloroquine tablets brand india 4800mg gabapentin sildenafil citrate over the counter diflucan uk price

  16. brliFaulP
    brliFaulP
    回复

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

  17. vtgdretelf
    vtgdretelf
    回复

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

  18. vttqabaxy
    vttqabaxy
    回复

    generic viagra walmart http://buyviagricxr.com/ - womens viagra viagra pill generic viagra online for sale viagra

  19. vthDrurb
    vthDrurb
    回复

    viagra online http://buyviagenonline.com/ - generic viagra cheap viagra viagra viagra pill

  20. vfgrPydaY
    vfgrPydaY
    回复

    viagra http://viagracefo.com/ - herbal viagra side effects of viagra online viagra viagra alternative

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