虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    viagra https://canadianpharmacyfda.com/ - generic viagra viagra viagra online viagra

  2. Bobbyjaf
    Bobbyjaf
    回复

    how to purchase cialis online tadalafil 5mg
    pharmacie viagra cialis cialis 20 mg
    cialis e melhor que o viagra https://babecolate.com/buy-cialis-online-without.html

  3. dbniLiene
    dbniLiene
    回复

    cialis https://valcialisns.com/ - cialis cialis generic cialis online cialis

  4. smagmevagype
    smagmevagype
    回复

    http://cbd-online.us.com/ cbd for dogs cbd pure cbd for sale cbd oil at walmart

  5. miqqabaxy
    miqqabaxy
    回复

    viagra https://cheapnowaaaa.com/ - viagra viagra viagra cheap viagra

  6. crapyragacoup
    crapyragacoup
    回复

    cbd oil for dogs cbd for sale buy cbd oil online

  7. dbniLiene
    dbniLiene
    回复

    п»їcialis https://valcialisns.com/ - cialis generic cialis cialis generic cialis online

  8. miqqabaxy
    miqqabaxy
    回复

    viagra https://cheapnowaaaa.com/ - viagra cheap viagra viagra viagra

  9. lqnuFaulP
    lqnuFaulP
    回复

    generic cialis https://cialisovnnc.com/ - cialis generic cialis cialis cialis online

  10. lqnuFaulP
    lqnuFaulP
    回复

    generic cialis https://cialisovnnc.com/ - cialis online cialis cialis online cialis online

  11. dbniLiene
    dbniLiene
    回复

    cialis https://valcialisns.com/ - generic cialis cialis cialis generic cialis generic

  12. Erytug
    Erytug
    回复

    Hi! cialis senza prescrizione medicapharmacy one cialis buy cialis by phone pharmacy one cialisgeneric cialis india pharmacy buy cialis boots

  13. swimarumTauff

    cbd cream buy cbd pure cbd oil cbd for sale http://cbd-oils.us.com/ - cbd products

  14. crapyragacoup

    cbd gummies walmart http://cbdoilstore.us.com/ cbd pills cbd vape pure cbd oil

  15. AnnaDes
    AnnaDes
    回复

    acyclovir pill canadian pharmacy augmentin

  16. jrnfetelf
    jrnfetelf
    回复

    viagra https://canadianpharmacyfda.com/ - viagra online viagra generic viagra viagra

  17. blbqabaxy
    blbqabaxy
    回复

    generic viagra https://emtpartsstore.com/ - viagra generic viagra buy viagra generic viagra

  18. bdghscant
    bdghscant
    回复

    cialis online http://www.ciallisonline.com/ - п»їcialis online cialis cialis generic cialis

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