虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    viagra https://zvigariageneric.com/ - generic viagra viagra cheap viagra viagra generic

  2. dbniLiene
    dbniLiene
    回复

    generic cialis https://valcialisns.com/ - cialis cialis online cialis generic cialis

  3. loppDrurb
    loppDrurb
    回复

    generic viagra https://buyonlinewwwmen.com/ - п»їviagra viagra viagra generic viagra

  4. bdghscant
    bdghscant
    回复

    cheap cialis http://www.ciallisonline.com/ - cialis online cialis generic generic cialis cheap cialis

  5. bfbnFaulP
    bfbnFaulP
    回复

    cheap viagra https://sexviagen.com/ - generic viagra viagra online viagra viagra online

  6. bdghscant
    bdghscant
    回复

    cialis generic http://www.ciallisonline.com/ - п»їcialis п»їcialis п»їcialis п»їcialis

  7. grlsetelf
    grlsetelf
    回复

    viagra without a doctor prescription https://medyvirgaraonline.com/ - cheap viagra online viagra viagra online viagra generic

  8. loppDrurb
    loppDrurb
    回复

    generic viagra https://buyonlinewwwmen.com/ - viagra viagra viagra online viagra online

  9. loppDrurb
    loppDrurb
    回复

    generic viagra https://buyonlinewwwmen.com/ - viagra viagra viagra cheap viagra

  10. Amitsflormror

    http://cbd-hemp.us.com/ best cbd oil buy cbd oil cbd near me hemp cbd oil cbd oil store

  11. gwbqabaxy
    gwbqabaxy
    回复

    viagra online https://zvigariageneric.com/ - viagra viagra cheap viagra viagra

  12. loppDrurb
    loppDrurb
    回复

    generic viagra https://buyonlinewwwmen.com/ - generic viagra viagra online п»їviagra viagra

  13. gwbqabaxy
    gwbqabaxy
    回复

    viagra online https://zvigariageneric.com/ - cheap viagra online viagra buy viagra viagra generic

  14. bfbnFaulP
    bfbnFaulP
    回复

    viagra https://sexviagen.com/ - viagra viagra without doctor prescription viagra online viagra

  15. bdghscant
    bdghscant
    回复

    online cialis http://www.ciallisonline.com/ - online cialis generic cialis buy cialis buy cialis

  16. lqbtbCrarl
    lqbtbCrarl
    回复

    cialis online http://genericcialls.com/ - online cialis cialis daily generic cialis generic cialis

  17. vsbhabaxy
    vsbhabaxy
    回复

    viagra online https://genericjojos.com/ - generic viagra generic viagra viagra buy viagra

  18. grlsetelf
    grlsetelf
    回复

    generic viagra https://medyvirgaraonline.com/ - viagra online viagra online viagra online cheap viagra

  19. lqbtbCrarl
    lqbtbCrarl
    回复

    cialis generic http://genericcialls.com/ - buy cialis cialis generic cialis generic cialis

  20. gwbqabaxy
    gwbqabaxy
    回复

    viagra online https://zvigariageneric.com/ - viagra online viagra online buy viagra viagra

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