虫言虫语 虫言虫语

PHP整洁之道节选

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

函数

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

    Cheap Us Made Viagra Et Priligy Viagra viagra Pharmacie En Ligne Cytotec Que Espatente De Propecia

  2. Ellvady
    Ellvady
    回复

    Comment Durer Plus Longtemps cialis 20mg for sale Best Price Viagra 100mg

  3. Ellvady
    Ellvady
    回复

    Online Viagra Consultation cheap cialis online Zithromax 1000 Mg Side Effects Viagra Soft Tabs Review

  4. RandElend
    RandElend
    回复

    Online Apotheke Silagra Direct On Line Pyridium Cheapeast Amex Accepted Shopretin A Cream Buy Zithromax Online Cheap cialis canada Levitra 10mg Orodispersible Bayer

  5. Ellvady
    Ellvady
    回复

    Cephalexin Generation Cephalosporin order cialis online Keflex Bladder Infection Propecia Buy Prescription Avodart Propecia

  6. Instagram
    Instagram
    回复

    instagram private profile viewer is the things that can gives you to full access of private profile emulation that is use for the enjoyment purpose this instagram viewer have random images to yours concerning searches that is according to your desire private profile pictures and videos for free. Which means you can use these features absolutely without and penny.

  7. RandElend
    RandElend
    回复

    Viagra Pills Redtube Kamagra Vente En France canadian pharmacy cialis Buy Propranolol Inderal Uk

  8. Ellvady
    Ellvady
    回复

    Viagra Venta Sin Receta cialis 20mg for sale Preisvergleich Cialis 20 Mg Baclofene Atoute Viagra Utilite

  9. Ellvady
    Ellvady
    回复

    Cialis Effetti Collaterali Propecia Hair Cost propecia cost Darunavir Levitra 10 Precio Osterreich Bestellen Levitra

  10. RandElend
    RandElend
    回复

    Articulo 12 Generique Cialis Vendu France canadian pharmacy cialis 20mg Clomid By Avents

  11. Ellvady
    Ellvady
    回复

    Commentaire Achat Cialis France Acheter Cytotec En Connexion Cialis Bestellung cialis 5mg best price Buy Xenical Online No Prescription Cialis Prix Sans Ordonnance Cialis Effet

  12. RandElend
    RandElend
    回复

    Amoxicillin And Vitamin And Headache Effetti Levitra cialis without a doctor's prescription Que Significa Propecia

  13. buy prescription drugs without doctor

    online pharmacies canada
    http://canadianpharmaciesoffer.com/
    canadian online pharmacy

  14. best online pharmacies in canada

    reputable mexican pharmacies online
    http://canadianhealthypharmacyrx.com/
    canadian pharmacies shipping to usa

  15. BennySon
    BennySon
    回复

    doxycycline 100mg acne

  16. Michaelnom
    Michaelnom
    回复

    levitra 10mg

  17. AaronDib
    AaronDib
    回复

    http://albuterolsulfateinhaler.com/ - albuterol sulfate inhaler

  18. KennethSar
    KennethSar
    回复

    allopurinol no prescription

  19. AaronDib
    AaronDib
    回复

    clonidine hydrochloride advair propranolol 80mg levaquin cost prices for cialis cheap generic cialis vardenafil 20 mg propecia for less

  20. CharlesDes
    CharlesDes
    回复

    cheap generic valtrex without prescription

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