虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    buy cbd oil online buy cbd buy cbd oil cbd gummies

  2. Lesswesty
    Lesswesty
    回复

    Cialis Generika Tadacip http://cheapcialisir.com - Cheap Cialis Cephalexin Side Effects On Dogs cheap cialis Cialis Muskelaufbau

  3. econcorenny

    https://cbdoilww.com/ cbd cbd cbd tinctures cbd vape

  4. SeapokeSmele

    cbd cbd hemp cbd
    cbd

  5. RafSeinaclecoca

    cbd gummies cbd oil online cbd oil
    cbd oil

  6. econcorenny

    buy cbd oil online cbd cbd oil cbd

  7. AnnaDes
    AnnaDes
    回复

    how to get cipro without a prescription doxycycline 100mg tablet price retin a 0.05 antabuse medication

  8. RafSeinaclecoca

    buy hemp oil https://cbdoilww.com/ - cbd tinctures cbd online cbd oil online

  9. SeapokeSmele

    cbd online https://cbdoilww.com/ buy cbd buy hemp cbd oil online

  10. SeapokeSmele

    buy cbd cbd drops cbd oil online
    cbd oil online

  11. RafSeinaclecoca

    cbd cream hemp cbd cbd online
    cbd vape

  12. AnnaDes
    AnnaDes
    回复

    indocin medication buy kamagra buy accutane valtrex 500 mg can i buy advair over the counter albendazole brand name canada tadalafil soft tablets 10 mg buy anti buse

  13. econcorenny

    buy cbd oil buy cbd oil online cbd gummies cbd oil

  14. NickDes
    NickDes
    回复

    advair diskus coupon buy tretinoin no prescription suhagra 50 mg price in india synthroid 0.100 mg diflucan prescription online buy roaccutane generic indocin albendazole brand name

  15. SeapokeSmele

    buy cbd oil online cbd oil online cbd online
    buy cbd oil online

  16. RafSeinaclecoca

    buy hemp buy hemp oil cbd tinctures
    hemp cbd

  17. NickDes
    NickDes
    回复

    antabuse medication buy albuterol uk acyclovir 400 mg advair diskus discount diflucan 150 cipro 500mg buy

  18. econcorenny

    cbd oil online buy hemp buy hemp cbd tinctures

  19. Stevnisa
    Stevnisa
    回复

    Propecia A Semana Santa http://abcialisnews.com - cialis canada Cialis Einmal Taglich cialis price Viagra Flughafen

  20. SeapokeSmele

    buy hemp cbd online cbd online
    cbd tinctures

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