虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    why does viagra stop working
    viagra generic https://viagra-generics.us viagra generic
    how long does a viagra erection last

  2. vfgabaxy
    vfgabaxy
    回复

    buy viagra http://cheapvirgaraonline.com/ - viagra cost viagra over the counter viagra women viagra

  3. vtgdretelf
    vtgdretelf
    回复

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

  4. erfiUnada
    erfiUnada
    回复

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

  5. MiaDes
    MiaDes
    回复

    antabuse price south africa paxil 12.5 how to buy atenolol online proscar canada online generic propecia 5mg

  6. vthDrurb
    vthDrurb
    回复

    п»їgeneric viagra http://buyviagenonline.com/ - buy viagra viagra generic women viagra viagra for sale

  7. vtgdretelf
    vtgdretelf
    回复

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

  8. grdfscant
    grdfscant
    回复

    generic viagra walmart http://viagraid.com/ - п»їgeneric viagra online viagra viagra side effects viagra

  9. erfiUnada
    erfiUnada
    回复

    viagra online http://viagrajr.com/ - otc viagra cheap viagra buy generic 100mg viagra online viagra and alcohol

  10. MiaDes
    MiaDes
    回复

    indocin medicine 25 mg sildenafil sale in india hydrochlorothiazide 50 mg price dapoxetine premature ejaculation avana australia

  11. PaulDes
    PaulDes
    回复

    finasteride 5mg prazosin 2mg capsules buy online 10mg prednisolone buy phenergan 10mg online buspar 10mg cost

  12. erfiUnada
    erfiUnada
    回复

    viagra for sale http://viagrajr.com/ - viagra online generic viagra walmart viagra alternative viagra

  13. vpkcrure
    vpkcrure
    回复

    viagra http://cheapgogenvia.com/ - online viagra cialis vs viagra buy viagra viagra for women

  14. SueDes
    SueDes
    回复

    clonidine hcl 1 mg sumycin cost vermox pills buy phenergan nz avodart 500 mg diclofenac gel 100 mg cytotec pharmacy uk accutane costs uk cheap cialis canada pharmacy best price baclofen brand name australia

  15. vpkcrure
    vpkcrure
    回复

    viagra for women http://cheapgogenvia.com/ - what does viagra do viagra 100mg herbal viagra viagra

  16. vthDrurb
    vthDrurb
    回复

    viagra for sale http://buyviagenonline.com/ - buy viagra buy viagra viagra generic generic viagra walmart

  17. vtgdretelf
    vtgdretelf
    回复

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

  18. grdfscant
    grdfscant
    回复

    viagra online http://viagraid.com/ - generic viagra walmart how to get viagra herbal viagra viagra

  19. vttqabaxy
    vttqabaxy
    回复

    how does viagra work http://buyviagricxr.com/ - viagra 100mg generic viagra online for sale generic viagra online generic viagra

  20. vfgrPydaY
    vfgrPydaY
    回复

    viagra 100mg http://viagracefo.com/ - generic viagra walmart viagra generic name generic viagra viagra pill

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