虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    buy hemp cbd cream cbd drops
    cbd drops

  2. EvaDes
    EvaDes
    回复

    suhagra tablet 50 mg

  3. econcorenny
    econcorenny
    回复

    cbd oil online https://cbdoilww.com/ - cbd cream buy cbd oil buy cbd cbd vape

  4. econcorenny
    econcorenny
    回复

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

  5. econcorenny
    econcorenny
    回复

    cbd oil online https://cbdoilww.com/ - cbd drops cbd oil online cbd

  6. econcorenny
    econcorenny
    回复

    hemp cbd cbd cbd oil cbd vape

  7. RafSeinaclecoca

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

  8. RafSeinaclecoca

    cbd oil hemp cbd cbd oil online

  9. SeapokeSmele
    SeapokeSmele
    回复

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

  10. econcorenny
    econcorenny
    回复

    buy hemp cbd cream buy cbd oil online buy hemp oil

  11. SeapokeSmele
    SeapokeSmele
    回复

    cbd vape buy hemp oil cbd
    hemp cbd

  12. RafSeinaclecoca

    cbd online buy hemp oil cbd cream
    cbd gummies

  13. MiaDes
    MiaDes
    回复

    buy cipro 500mg generic for strattera buy diflucan metformin 500 buy kamagra

  14. econcorenny
    econcorenny
    回复

    cbd drops cbd drops cbd gummies cbd tinctures

  15. RonaldosThoni

    cialis for sale toronto
    http://cialisle.com/# - generic cialis 5mg online
    why does cialis work better than viagra
    prices for cialis
    will cialis show up on a blood test

  16. SeapokeSmele
    SeapokeSmele
    回复

    buy cbd oil online cbd vape cbd
    buy hemp oil

  17. RafSeinaclecoca

    cbd oil online hemp cbd hemp cbd
    cbd

  18. econcorenny
    econcorenny
    回复

    cbd online buy hemp buy hemp oil cbd online

  19. SeapokeSmele
    SeapokeSmele
    回复

    buy cbd cbd drops cbd online
    buy cbd

  20. RafSeinaclecoca

    buy hemp buy cbd cbd vape
    buy cbd

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