虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    http://cbdcreamwww.com/ cbd cbd tinctures cbd oils cbd medic

  2. vrdcabaxy
    vrdcabaxy
    回复

    viagra https://sophiapharmsd.com/ - viagra sale viagra for sale viagra sale viagra sale

  3. vrdcabaxy
    vrdcabaxy
    回复

    viagra https://sophiapharmsd.com/ - viagra for sale viagra viagra viagra sale

  4. hsioabaxy
    hsioabaxy
    回复

    viagra https://xvirgaronline.com/ - cheap viagra cheap viagra viagra online viagra

  5. hsioabaxy
    hsioabaxy
    回复

    viagra https://xvirgaronline.com/ - online viagra viagra online viagra viagra

  6. vrdcabaxy
    vrdcabaxy
    回复

    viagra sale https://sophiapharmsd.com/ - viagra for sale viagra sale generic viagra generic viagra

  7. vrdcabaxy
    vrdcabaxy
    回复

    viagra sale https://sophiapharmsd.com/ - viagra for sale viagra viagra viagra for sale

  8. vrdcabaxy
    vrdcabaxy
    回复

    viagra sale https://sophiapharmsd.com/ - generic viagra viagra for sale viagra viagra sale

  9. vrdcabaxy
    vrdcabaxy
    回复

    viagra generic https://sophiapharmsd.com/ - viagra for sale viagra viagra sale generic viagra

  10. Bdwiginmedge
    Bdwiginmedge
    回复

    cialis no prescription

  11. WarrenMeary
    WarrenMeary
    回复

    cbd oil
    plus cbd oil softgels gold formula
    best cbd oil
    cbd oil for dogs

  12. Shawndit
    Shawndit
    回复

    is cbd oil legal in all 50 states
    plus cbd oil
    buy cbd oil
    does amazon prohibit cbd oil?

  13. Buy cheap viagra now

    Xouqdw rclnmo online casino games online casino slots no download

  14. Discount viagra no rx

    Xkerwd emdtjn ocean casino online nj doubleu casino online casino

  15. Udsffdiio
    Udsffdiio
    回复

    kfw kredit http://www.sofortkrediteonline.org/kredit-1000-euro
    kredit 10000 http://www.sofortkrediteonline.org/kredit-1000-euro auxmoney kredit
    http://www.sofortkrediteonline.org/kredit-1000-euro

  16. IvyDes
    IvyDes
    回复

    generic propecia buy valtrex priligy 30mg 5mg propecia where to buy retin a in mexico buy tadalafil buy albuterol buy hydroxychloroquine sulfate prednisone 10mg buy accutane buy ivermectin keflex 500 neurontin 100 mg generic accutane canada paxil 20 sildenafil 50 mg tablet price buy doxy 100 400 mg sildenafil bupropion 150 mg azithromycin online

  17. Udsffdiio
    Udsffdiio
    回复

    ofina kredit http://www.sofortkrediteonline.org/kredit-3000-euro
    kredit schweiz http://www.sofortkrediteonline.org/kredit-3000-euro santander bank kredit
    http://www.sofortkrediteonline.org/kredit-3000-euro

  18. How to get viagra

    Nkrbpf usccmd generic viagra online Usa viagra sales

  19. iaSic
    iaSic
    回复

    OrderCanadian USA order cialis
    generic cialis daily canada

  20. Theresaphda
    Theresaphda
    回复

    viagra connect walgreens
    buy viagra online https://viaonlinebuy.us buy viagra
    reduce nasal congestion viagra

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