虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    lisinopril 102 synthroid prices where to buy stromectol online cheap propecia online canada where to buy propecia online buy levitra cost of lisinopril 40 mg allopurinol 300 mg price

  2. Lesswesty
    Lesswesty
    回复

    Keflex Personality Change Cephalaxin http://abuycialisb.com - Cialis Priligy Barata Cialis Generic Cialis 20mg France

  3. AnnaDes
    AnnaDes
    回复

    sildenafil sale uk buy prednisolone no prescription clomid online without prescription

  4. AnnaDes
    AnnaDes
    回复

    can you buy motilium over the counter lisinopril 20mg azithromycin 250 mg over the counter prednisolne online prednisone 1 mg cheap levitra

  5. MiaDes
    MiaDes
    回复

    prednisone 4mg buy levitra canadian pharmacy albuterol inhaler prescription where can i buy propecia online zithromax capsules 250mg

  6. Lesswesty
    Lesswesty
    回复

    Acheter Cialis 20mg http://abcialisnews.com - Cialis Cialis Kaufen Serios Buy Cialis Levitra Eating

  7. NickDes
    NickDes
    回复

    zithromax over the counter australia how much does cipralex cost propecia online tetracycline 500mg retin a 025 prednisone online

  8. JimDes
    JimDes
    回复

    buy cafergot pills metformin 500 for sale zithromax capsules 500mg lisinopril brand name tetracycline capsules 250mg lisinopril cheap price

  9. Stevnisa
    Stevnisa
    回复

    Viagra Blitzversand http://buycialisuss.com - Cialis Buy Discount Secure Provera Real No Prior Script canadian cialis Cialis 5 Mg Best Price

  10. EvaDes
    EvaDes
    回复

    azithromycin rx coupon

  11. kppg915939
    kppg915939
    回复

    zytenz scam http://doanhnhan.net.vn/?option=com_k2&view=itemlist&task=user&id=1116436 lilly coupons for insulin http://shop-luxebox.com/?option=com_k2&view=itemlist&task=user&id=381384 viagra what to expect http://todotrial.com/?option=com_k2&view=itemlist&task=user&id=7920 sildenafil patient assistance program http://www.milanoportaverta.it/?option=com_k2&view=itemlist&task=user&id=664470 walgreens viagra substitute http://www.insightcounselingoffice.com/insight3/index.php/?option=com_k2&view=itemlist&task=user&id=43726

  12. Lesswesty
    Lesswesty
    回复

    Precio Cialis Con Receta http://abuycialisb.com - cialis from canada All Pharmacy Pills cialis 5 mg best price usa Levitra Patente

  13. KiaDes
    KiaDes
    回复

    buy levitra online no prescription

  14. EvaDes
    EvaDes
    回复

    albuterol canada price

  15. AnnaDes
    AnnaDes
    回复

    buy allopurinol retin a 05 lisinopril online purchase can you buy ventolin over the counter in singapore tetracycline 100 mg colchicine 0.6 mg metformin order online canada

  16. EvaDes
    EvaDes
    回复

    how can i get clomid online

  17. SamDes
    SamDes
    回复

    lisinopril 40 mg generic ventolin generic zithromax 500 mg tablet 10 mg prednisone tablets prednisolone 5mg compare propecia prices albuterol cheapest price

  18. Stevnisa
    Stevnisa
    回复

    Viagra Canada Price http://buycialisuss.com - buy generic cialis Acheter Novaldex Buy Cialis Does Amoxicillin Cause Increased Thirst

  19. KimDes
    KimDes
    回复

    stromectol for sale

  20. EvaDes
    EvaDes
    回复

    buy allopurinol 300 mg uk

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