虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

函数参数最好少于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
发表新评论
已有 37630 条评论
  1. erfiUnada
    erfiUnada
    回复

    viagra and alcohol http://viagrajr.com/ - online viagra generic viagra online for sale how to take viagra viagra generic name

  2. vfgrPydaY
    vfgrPydaY
    回复

    viagra generic http://viagracefo.com/ - viagra cost viagra viagra and alcohol how does viagra work

  3. Brianrenly
    Brianrenly
    回复

    Learn More go to website continue reading this..

  4. grdfscant
    grdfscant
    回复

    viagra cost http://viagraid.com/ - online viagra viagra side effects how to take viagra generic viagra walmart

  5. erfiUnada
    erfiUnada
    回复

    viagra http://viagrajr.com/ - cheap viagra viagra side effects how to get viagra viagra alternative

  6. JaneDes
    JaneDes
    回复

    buy cheap cipro online

  7. erfiUnada
    erfiUnada
    回复

    generic viagra online http://viagrajr.com/ - viagra generic viagra walmart viagra viagra

  8. vfgabaxy
    vfgabaxy
    回复

    how long does viagra last http://cheapvirgaraonline.com/ - viagra sale cialis vs viagra viagra canadian pharmacy ezzz women viagra

  9. vttqabaxy
    vttqabaxy
    回复

    buy generic 100mg viagra online http://buyviagricxr.com/ - online viagra viagra viagra online viagra

  10. vttqabaxy
    vttqabaxy
    回复

    herbal viagra http://buyviagricxr.com/ - viagra generic viagra generic viagra online for sale how to get viagra

  11. erfiUnada
    erfiUnada
    回复

    what is viagra http://viagrajr.com/ - generic viagra generic viagra walmart viagra price viagra alternative

  12. vfgabaxy
    vfgabaxy
    回复

    generic viagra http://cheapvirgaraonline.com/ - viagra and alcohol generic viagra cheap viagra buy viagra online

  13. vpkcrure
    vpkcrure
    回复

    herbal viagra http://cheapgogenvia.com/ - viagra online viagra generic viagra and alcohol generic viagra online for sale

  14. wdriLiene
    wdriLiene
    回复

    cialis buy http://cialishe.com/ - generic cialis cialis online cialis online cialis 20mg

  15. vttqabaxy
    vttqabaxy
    回复

    generic viagra online http://buyviagricxr.com/ - over the counter viagra what does viagra do viagra sale viagra online

  16. ACrorgo
    ACrorgo
    回复

    viagra online viagra online canada pharmacy buy viagra cheap viagra viagra prices cheap viagra

  17. erfiUnada
    erfiUnada
    回复

    buy viagra http://viagrajr.com/ - viagra over the counter buy generic 100mg viagra online viagra cost cialis vs viagra

  18. vpkcrure
    vpkcrure
    回复

    buy viagra http://cheapgogenvia.com/ - viagra viagra online how to get viagra online viagra

  19. vttqabaxy
    vttqabaxy
    回复

    viagra over the counter http://buyviagricxr.com/ - generic viagra online for sale womens viagra generic viagra cheap viagra

  20. erfiUnada
    erfiUnada
    回复

    viagra 100mg http://viagrajr.com/ - viagra side effects cheap viagra viagra generic name п»їgeneric viagra

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