虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

函数参数最好少于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. Buy viagra from canada

    Eygirf ahjvxd casino slots gambling real online casino

  2. Buy now viagra

    Tbcjdp turixo online loan payday loans for bad credit

  3. viagra
    viagra
    回复

    git diseases list overview of asthma
    https://onlinedrugstore.us.org cialis
    baldness solutions inpatient alcohol treatment
    cialis generic

  4. Metug
    Metug
    回复

    Exhausted? No desire? cialis generique livraison 48hmuscle cramps from cialis
    buy cialis boots

  5. Udsffdiio
    Udsffdiio
    回复

    kredit 10000 http://www.sofortkrediteonline.org/kredit-4000-euro
    sparkassen kredit http://www.sofortkrediteonline.org/kredit-4000-euro kredit karte
    http://www.sofortkrediteonline.org/kredit-4000-euro

  6. Udsffdiio
    Udsffdiio
    回复

    gunstiger kredit http://www.sofortkrediteonline.org/
    schufafreier kredit http://www.sofortkrediteonline.org/ swk bank kredit
    http://www.sofortkrediteonline.org/

  7. Buy online viagra

    Egeave tlazwo bad credit personal loans payday loans for bad credit

  8. Cost viagra
    Cost viagra
    回复

    Twiwpk alxzpn buy cialis pills online canadian pharmacy

  9. Aplaire
    Aplaire
    回复

    canadian viagra online pharmacy viagra pill viagra vs cialis canadian viagra generic viagra online pharmacy https://buyatedtablets.com/# - viagra dosage order viagra

  10. Viagra overnight

    Ujajsb elxxja payday loan lenders online casino for real cash

  11. Edwardmug
    Edwardmug
    回复

    asda viagra price uk
    taking blood pressure medication viagra
    generic viagra online

  12. Buy viagra australia

    Nkfbgb iefxzx payday loans no credit check vegas casino online

  13. Buy viagra cheap

    Aexpqg ijghbp payday loan online online payday loans

  14. Albertvsal
    Albertvsal
    回复

    the best way to take viagra
    viagra online
    viagra for teenager

  15. Adelineajuw
    Adelineajuw
    回复

    i took 200mg viagra
    how does viagra advertise
    viagra pulmonary hypertension

  16. Faviolandyw

    where to get viagra online
    buy viagra online viaonlinebuy.us buy viagra online
    viagra und cialis

  17. Nancienhwr
    Nancienhwr
    回复

    is viagra an over the counter drug
    when does viagra cream come to united states
    how long until viagra starts working

  18. RichardSlowl

    generic viagra
    viagra chipset
    buy viagra
    como elaborar una viagra casera

  19. iaSic
    iaSic
    回复

    GetCanadian USA buy generic cialis
    opinion cialis diario

  20. Drug viagra

    Gnkuze jvvnky payday loans no credit check payday loan lenders

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