虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    online cialis order viagrahttps://frviagrafrance.com/ - acheter viagra generique
    acheter viagra generiqueviagra 2bonline

  2. BeardenSwanobete

    best generic cialis suppliershttps://ciasale20.com/ - buy generic cialis
    how to buy cialis in torontocialis und glaukom

  3. OstroskyPeytynnobete

    visit our site buy viagra ukhttps://frviagrafrance.com/ - we use it viagra sale
    generic viagra topviagra compresse 50 mg prezzo

  4. BeardenSwanobete

    order cialis with prescriptionhttps://ciasale20.com/ - wow buy cialis doctor online
    buy cialiscialis sconto enorme

  5. OstroskyPeytynnobete

    we choice viagra canada drugshttps://frviagrafrance.com/ - acheter viagra net forum
    generic softtabs viagra phpbuy viagra in dallas

  6. BeardenSwanobete

    buy cialis buyhttps://ciasale20.com/ - online cialis
    buy generic cialisbuy cialis florida

  7. OstroskyPeytynnobete

    usefull link viagra doseshttps://frviagrafrance.com/ - comprar viagra requiere receta
    the best place viagra usinguse viagra dosage

  8. CallicuttVidhyaobete

    buy viagra one tablethttps://deliveryviagranow.com/ - buy viagra online legally
    viagra without doctor prescriptionviagra pfizer 150 mg

  9. BeardenSwanobete

    cialis kanada apothekehttps://ciasale20.com/ - buy generic cialis
    order generic cialis shopcialis und glaukom

  10. BeardenSwanobete

    cialis posologia 20 mghttps://ciasale20.com/ - best site to order cialis
    comparegenericcialispricesthe cheapest cialis online

  11. CallicuttVidhyaobete

    try it viagra propranodolhttps://deliveryviagranow.com/ - viagra generic
    viagraviagra preis thailand

  12. OstroskyPeytynnobete

    can viagra hurt youhttps://frviagrafrance.com/ - viagra sur internet
    how to get viagra uk nhscit costa viagra

  13. OstroskyPeytynnobete

    viagra 50mg price in chennaihttps://frviagrafrance.com/ - acheter viagra sans ordonnance
    viagra rezept hollandfast shipping viagra canada

  14. OstroskyPeytynnobete

    billige viagrapillenhttps://frviagrafrance.com/ - viagra in greece
    viagra pillen teuerutilisation et effet du viagra

  15. BeardenSwanobete

    comprar cialis en ukhttps://ciasale20.com/ - we use it soft gel cialis
    generic cialis onlinecialis uk supplier

  16. BeardenSwanobete

    buy cialis at walmarthttps://ciasale20.com/ - cialis day generic next
    buy cialiswwwcialispharmacist

  17. OstroskyPeytynnobete

    viagra jakartahttps://frviagrafrance.com/ - can viagra hurt you
    viagra e controindicazioncialis mas viagra

  18. BeardenSwanobete

    bulk cialishttps://ciasale20.com/ - small pink cialis pills
    cialis venta en argentinathe cheapest cialis online

  19. OstroskyPeytynnobete

    50 mg viagra price in indiahttps://frviagrafrance.com/ - cheap viagra on line forum
    has best prices viagraviagra dosage price

  20. CallicuttVidhyaobete

    off shore viagrahttps://deliveryviagranow.com/ - jokes birth viagra
    viagra kaufen berlin200mg viagra india

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