虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    metformin 500 mg ventolin price zithromax 500mg lexapro australia price

  2. vfbicrure
    vfbicrure
    回复

    coursework history http://courseworkhelpxeg.com/ - coursework writing services online coursework coursework help university coursework website

  3. Stevnisa
    Stevnisa
    回复

    Amoxicillin Dosage Dental http://buycialisuss.com - order cialis online Cialis Extra Super viagra vs cialis Prix Cialis France

  4. boigoks
    boigoks
    回复

    best online canadian pharmacy http://onlinepharmacy.today - northwest pharmacy online canadian pet pharmacy

  5. Lesswesty
    Lesswesty
    回复

    Compare Avelox To Keflex http://viacialisns.com/# - cialis without prescription Buy Zithromax Single Dose Packets Cialis Buy Generic Plavix 75 Mg

  6. SamDes
    SamDes
    回复

    allopurinol rx retin a 0.025 cream buy online cafergot price doxycycline for sale metformin 500 mg for sale lisinopril tabs 20mg prednisone pills for sale stromectol in canada

  7. AnnaDes
    AnnaDes
    回复

    sildenafil 20 mg coupon levitra generic canada cheap generic propecia online albuterol 2.5 mg coupon colchicine 0.6 mg azithromycin 500mg buy clomid

  8. SamDes
    SamDes
    回复

    finasteride prostate motilium domperidone

  9. SamDes
    SamDes
    回复

    where can i buy cafergot tablets buy doxycycline india lexapro 5mg metformin 104

  10. EyeDes
    EyeDes
    回复

    generic zithromax 250mg colchicine generic canada buy levitra online cheap synthroid generic buy lisinopril buy propecia 5mg azithromycin 500mg sildenafil 20 mg tablet doxycycline 100mg buy albuterol tablets australia retin a 0.1 cream allopurinol 300 lisinopril online prescription ventolin tablets 4mg prednisolone 25mg price cafergot tab 100 mg prednisone 120 mg daily fluoxetine otc how much is generic lexapro buy motilium australia

  11. AnnaDes
    AnnaDes
    回复

    allopurinol tablets 100mg 300mg levitra 20mg stromectol canada motilium otc uk

  12. NickDes
    NickDes
    回复

    azithromycin 250 mg pill metformin generic

  13. EvaDes
    EvaDes
    回复

    prednisolone 25mg

  14. fegoDrurb
    fegoDrurb
    回复

    essays help http://essayonlinethx.com/ - i need someone to write my essay help me write my college essay custom essay service top 10 essay writers

  15. LarPrema
    LarPrema
    回复

    online pharmacy http://canadianmail-orderpharmacy.com - canada drugs coupon code canada pharmacy pharmacy cheap no prescription

  16. NickDes
    NickDes
    回复

    azithromycin 500mg without prescription buy cafergot pills

  17. SamDes
    SamDes
    回复

    albuterol cost in mexico lisinopril 40 mg tablet retin a 0.1 cream

  18. Lesswesty
    Lesswesty
    回复

    Canadian Pharmacy Online Express http://abcialisnews.com - Buy Cialis Get Macrobid Antibiotic cialis 20mg price at walmart Cheapest Generic Viagra Uk

  19. enrist
    enrist
    回复

    viagra without a doctor prescription buying viagra online viagra without a doctor 100 mg

  20. econcorenny

    buy cbd cbd drops cbd gummies buy cbd oil online

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