虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    cialis cialis cialis for daily use is there a generic cialis available in the us how long for cialis to take effect
    is cialis better than viagra best price generic cialis Cialis has cialis gone generic tadalafil Cialis cialis experience
    need a prescription for cialis cialis is a generic cialis available Cialis is eli lilly making generic cialis ? cialis

  2. grlsetelf
    grlsetelf
    回复

    viagra without doctor prescription https://medyvirgaraonline.com/ - viagra buy viagra viagra online viagra

  3. gwbqabaxy
    gwbqabaxy
    回复

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

  4. smagmevagype
    smagmevagype
    回复

    best cbd oil cbd oil for dogs cbd online

  5. mejzCrarl
    mejzCrarl
    回复

    п»їcialis http://pharmcilisa.com/ - generic cialis cialis generic cialis generic cialis pills

  6. dbniLiene
    dbniLiene
    回复

    cialis online https://valcialisns.com/ - cialis п»їcialis generic cialis cialis

  7. dbniLiene
    dbniLiene
    回复

    cialis generic https://valcialisns.com/ - п»їcialis cialis online п»їcialis cialis

  8. bfbnFaulP
    bfbnFaulP
    回复

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

  9. crapyragacoup

    http://cbdoilstore.us.com/ cbd for sale cbd oil for pain best cbd oil cbd tinctures

  10. gwbqabaxy
    gwbqabaxy
    回复

    generic viagra https://zvigariageneric.com/ - generic viagra buy viagra viagra without doctor prescription generic viagra

  11. bdntcrure
    bdntcrure
    回复

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

  12. canadian pharmacy online

    online pharmacies canada
    http://canadianpharmaciesnorth.com/
    prescription meds without the prescription

  13. swimarumTauff

    http://cbd-oils.us.com/ cbd oil online buy cbd oil pure cbd oil cbd near me

  14. mejzCrarl
    mejzCrarl
    回复

    cialis reviews http://pharmcilisa.com/ - cialis generic cialis online online cialis cialis online

  15. bdghscant
    bdghscant
    回复

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

  16. lqbtbCrarl
    lqbtbCrarl
    回复

    cheap cialis http://genericcialls.com/ - cialis online cialis price generic cialis generic cialis

  17. dbniLiene
    dbniLiene
    回复

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

  18. bdntcrure
    bdntcrure
    回复

    п»їviagra https://www.genericviragacheap.com/ - viagra generic viagra online viagra viagra without a doctor prescription

  19. gwbqabaxy
    gwbqabaxy
    回复

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

  20. bdntcrure
    bdntcrure
    回复

    viagra https://www.genericviragacheap.com/ - viagra without doctor prescription online viagra viagra without doctor prescription viagra

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