虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    buy cialis http://cialishe.com/ - generic cialis п»їcialis cialis buy cialis 20mg

  2. erfiUnada
    erfiUnada
    回复

    herbal viagra http://viagrajr.com/ - generic viagra viagra online viagra pill viagra generic

  3. IvyDes
    IvyDes
    回复

    purchase erythromycin without a prescription paxil 30 mg coupon buy wellbutrin online without prescription cleocin 150 mg capsules avana 200 zithromax cream avodart generic cost malegra 120 mg buy antabuse canada lexapro 100mg tablets us pharmacy cialis dapoxetine 60mg in india finpecia online india sildalis online zoloft tabs diflucan capsule 150mg silagra tablet proscar price australia order hydrochlorothiazide over the counter fluoxetine 60

  4. vpkcrure
    vpkcrure
    回复

    viagra side effects http://cheapgogenvia.com/ - viagra pills cialis vs viagra viagra generic viagra alternative

  5. vfgrPydaY
    vfgrPydaY
    回复

    over the counter viagra http://viagracefo.com/ - buy viagra how to take viagra viagra pills online viagra

  6. vthDrurb
    vthDrurb
    回复

    online viagra http://buyviagenonline.com/ - viagra alternative cheap viagra viagra generic name viagra dosage

  7. vpkcrure
    vpkcrure
    回复

    viagra side effects http://cheapgogenvia.com/ - online viagra how to take viagra viagra for sale generic viagra

  8. JaneDes
    JaneDes
    回复

    acyclovir cream price uk

  9. vtgdretelf
    vtgdretelf
    回复

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

  10. vpkcrure
    vpkcrure
    回复

    viagra online http://cheapgogenvia.com/ - viagra price online viagra cialis vs viagra viagra online

  11. vpkcrure
    vpkcrure
    回复

    female viagra http://cheapgogenvia.com/ - buy generic 100mg viagra online buy viagra buy viagra viagra vs cialis

  12. wdriLiene
    wdriLiene
    回复

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

  13. vttqabaxy
    vttqabaxy
    回复

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

  14. JackDes
    JackDes
    回复

    allopurinol 200 mg tablet where can i buy nolvadex online buspar 5mg tablets buy generic amoxicillin online seroquel 300mg price tadalafil medication medication furosemide trazodone 50 mg online

  15. vpkcrure
    vpkcrure
    回复

    buy viagra online http://cheapgogenvia.com/ - how does viagra work what is viagra cialis vs viagra buy viagra

  16. vttqabaxy
    vttqabaxy
    回复

    viagra http://buyviagricxr.com/ - viagra alternative viagra for sale viagra for women viagra online

  17. vtgdretelf
    vtgdretelf
    回复

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

  18. vfgabaxy
    vfgabaxy
    回复

    viagra side effects http://cheapvirgaraonline.com/ - buy viagra how long does viagra last generic viagra viagra

  19. vttqabaxy
    vttqabaxy
    回复

    how to get viagra http://buyviagricxr.com/ - cialis vs viagra generic viagra female viagra women viagra

  20. MiaDes
    MiaDes
    回复

    avodart 0.5 mg cost cialis 75 discount prozac drugstore tadalafil cost usa glucophage 500mg price in india

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