好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

php常量const和define的区别

一般来说,const用于声明类常量,define用于声明普通常量。

<?php
    //在类外面通常使用define定义常量,define是
    define('QINGZZCONSTANT','http://www.qingzz.cn');
    class QingzzClass {
        //在类中定义常量只能用const,定义常量不需要$
        const QzzConstant='http://www.qingzz.cn';
        
        function showConstant() {
            //在类中使用类常量使用self::常量名
            print self::QzzConstant."<br>";
        }
    }
    //在类外面使用类常量使用类名::常量名
    print QingzzClass::QzzConstant."<br>";
    //利用类方法输出常量
    $exam=new QingzzClass;
    $exam->showConstant();
    //普通常量的使用
    print QINGZZCONSTANT."<br>";
?>

在php5.3之后,const可以用于定义普通常量,类常量的使用增加了几种方法:

<?php
    //const定义普通常量
    const QINGZZCONSTANT='http://www.qingzz.cn';
    class QingzzClass {
        //类常量仍仅可使用const定义
        const QzzConstant='http://www.qingzz.cn';
        
        function showConstant() {
            print self::QzzConstant."<br>";
        }
    }
    //在类外面使用类常量的其他方法:
    $classname = "QingzzClass";
    print $classname::QzzConstant . "<br>"; // PHP 5.3.0之后

    $exam = new QingzzClass();
    print $exam::QingzzConstant."<br>"; // PHP 5.3.0之后
    //普通常量的使用
    print QINGZZCONSTANT."<br>";
?>

const和define的区别

  1. const不能在条件语句里面定义常量,define可以

  2. const的名称也只能是常量,define的名称可以由表达式获得

  3. const的值只能是静态常量,define的值可以是任意表达式

  4. const只是一个语言结构,define是一个函数,因此const的速度比define快


点赞1
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
rmmassage
 rmmassage 2019-05-20 11:24回复
#235
<a href="http://www.sguerradesign.com/kvinders-nike-roshe-run-slip-gr%C3%A5-sort-skol">kvinders nike roshe run slip gr氓 sort</a> <a href="http://www.zeneventsja.com/polo-ralph-lauren-black-and-red-hoodie-poloh">polo ralph lauren black and red hoodie</a> <a href="http://www.adharaweb.com/mens-nike-roshe-run-black-purple-shoesi">mens nike roshe run black purple</a> <a href="http://www.jrelselaw.com/ua-micro-g-torch-blue-shoesp">ua micro g torch blue</a> <a href="http://www.intellalegal.com/nike-air-max-svart-kvinners-trainers-obuvl">nike air max svart kvinners trainers</a> <a href="http://www.carmelscoffee.com/nike-lunaracer-3-gr%C3%B8n-skoj">nike lunaracer 3 gr酶n</a>
rmmassage http://www.rmmassage.com/
erzurumihl
 erzurumihl 2019-05-19 05:10回复
#234
<a href="http://www.atrapaniapp.com/nike-lebron-ambassador-9-cielo-azul-rojo-zapatosk">nike lebron ambassador 9 cielo azul rojo</a> <a href="http://www.maplebeyond.com/womens-asics-gel-kinsei-4-yellow-pink-shoesi">womens asics gel kinsei 4 yellow pink</a> <a href="http://www.collisionsix.com/nike-sb-stefan-janoski-max-dam%C3%A4nner-himmelblau-gold-schuhei">nike sb stefan janoski max dam盲nner himmelblau gold</a> <a href="http://www.todololitas.com/nike-air-force-1-mid-07-caqui-blanco-hyper-zapatosp">nike air force 1 mid 07 caqui blanco hyper</a> <a href="http://www.jcwjrlaw.com/billig-gr%C3%A5-nike-roshe-run-skoi">billig gr氓 nike roshe run</a> <a href="http://www.vstsblog.com/air-jordan-retro-9-royal-bl%C3%A5-gr%C3%B8nn-obuvq">air jordan retro 9 royal bl氓 gr酶nn</a>
[url=http://www.erzurumihl.com/]erzurumihl[/url]
kikoyboy
 kikoyboy 2019-05-18 21:27回复
#233
<a href="http://www.antalyaritim.com/air-jordan-11-low-sort-python-scarpea">air jordan 11 low sort python</a> <a href="http://www.wcscwoodlands.com/chicago-white-sox-new-era-mlb-kids-heather-vize-9fifty-snapback-cap-hati">chicago white sox new era mlb kids heather vize 9fifty snapback cap</a> <a href="http://www.nchfnj.com/air-jordan-1-brouge-restock-2015-trainersb">air jordan 1 brouge restock 2015</a> <a href="http://www.unchartedlust.com/air-max-zero-sort-gr%C3%A5-boots-kurpesd">air max zero sort gr氓 boots</a> <a href="http://www.bethelpipe.com/salomon-fellraiser-gelb-rose-schuhel">salomon fellraiser gelb rose</a> <a href="http://www.ftorrentz.com/nike-roshe-run-liberty-light-blau-skof">nike roshe run liberty light blau</a>
kikoyboy http://www.kikoyboy.com/
handydgh
 handydgh 2019-05-18 07:11回复
#232
<a href="http://www.reviewtogel.com/nike-schwarz-wei%C3%9F-air-huarache-ultra-trainers-schuheh">nike schwarz wei脽 air huarache ultra trainers</a> <a href="http://www.igrejamormon.com/nike-air-presto-premium-paramount-blue-shoesk">nike air presto premium paramount blue</a> <a href="http://www.skonya.com/nike-air-max-90-hyp-frm-kvinder-gr%C3%A5-lilla-skoj">nike air max 90 hyp frm kvinder gr氓 lilla</a> <a href="http://www.monsterplate.com/rot-wei%C3%9F-and-blau-nike-air-max-95-schuheh">rot wei脽 and blau nike air max 95</a> <a href="http://www.kentimpendik.com/nike-mercurialx-pro-street-indoor-grey-black-orange-shoesk">nike mercurialx pro street indoor grey black orange</a> <a href="http://www.attivopizza.com/mk-selma-top-zip-large-brown-satchels-mkh">mk selma top zip large brown satchels</a>
handydgh http://www.handydgh.com/
dianegrams
 dianegrams 2019-05-18 07:07回复
#231
<a href="http://www.seesoshow.com/nike-free-run-2.0-noir-chaussuresh">nike free run 2.0 noir</a> <a href="http://www.crypolio.com/nike-kobe-9-dam%C3%A4nner-rot-silber-schuheh">nike kobe 9 dam盲nner rot silber</a> <a href="http://www.vtrvideo.com/nike-air-zoom-pegasus-33-wolf-grey-shoesk">nike air zoom pegasus 33 wolf grey</a> <a href="http://www.asoseinhalb.com/sko-hvid-adidas-skoj">sko hvid adidas</a> <a href="http://www.handydgh.com/adidas-originals-superstar-light-rosa-schuheh">adidas originals superstar light rosa</a> <a href="http://www.blakefanz.com/nike-roshe-run-men-red-shoesk">nike roshe run men red</a>
dianegrams http://www.dianegrams.com/
bowtieorg
 bowtieorg 2019-05-18 05:17回复
#230
<a href="http://www.clashopedia.com/ralph-lauren-blue-striped-polo-poloh">ralph lauren blue striped polo</a> <a href="http://www.adamomacri.com/nike-elastico-superfly-ic-fluorescent-gr%C3%B8n-sort-skok">nike elastico superfly ic fluorescent gr酶n sort</a> <a href="http://www.waltonranchtx.com/adidas-porsche-design-bounce-schwarz-gelb-schuheh">adidas porsche design bounce schwarz gelb</a> <a href="http://www.dominickcars.com/womens-air-jordan-retro-13-grey-shoesk">womens air jordan retro 13 grey</a> <a href="http://www.libertactica.com/m%C3%A6nd-nike-shox-current-hvid-skol">m忙nd nike shox current hvid</a> <a href="http://www.flixzine.com/nike-free-5.0-14-nightshade-hvit-gr%C3%B8nn-volt-obuvk">nike free 5.0 14 nightshade hvit gr酶nn volt</a>
bowtieorg http://www.bowtieorg.com/
alrightdesign
 alrightdesign 2019-05-17 19:43回复
#229
<a href="http://www.sugarforspice.com/chicago-cubs-new-era-mlb-authentic-collection-9-11-patch-low-profile-59fifty-cap-hath">chicago cubs new era mlb authentic collection 9 11 patch low profile 59fifty cap</a> <a href="http://www.mybancorphsa.com/nike-air-max-zero-rose-blanc-chaussuresh">nike air max zero rose blanc</a> <a href="http://www.scopatore.com/nike-free-tr-femmes-violet-rose-chaussuresj">nike free tr femmes violet rose</a> <a href="http://www.galacticlogos.com/herren-nike-roshe-run-triangle-orangen-grau-schuhej">herren nike roshe run triangle orangen grau</a> <a href="http://www.ispardmore.com/adidas-crazylight-boost-gr%C3%B8n-himmelbl%C3%A5-skok">adidas crazylight boost gr酶n himmelbl氓</a> <a href="http://www.radioramabc.com/maschio-nike-roshe-run-floreale-rosso-bianca-scarpeh">maschio nike roshe run floreale rosso bianca</a>
alrightdesign http://www.alrightdesign.com/
lavaforchange
 lavaforchange 2019-05-17 19:24回复
#228
<a href="http://www.tkbelazig.com/nike-flyknit-lunar-3-kvinners-s%C3%B8lv-gr%C3%B8nn-obuvk">nike flyknit lunar 3 kvinners s酶lv gr酶nn</a> <a href="http://www.swiftgrocer.com/nike-kaishi-run-gym-red-shoesi">nike kaishi run gym red</a> <a href="http://www.warrnamboolag.com/herre-nike-roshe-run-slip-alle-r%C3%B8d-skoj">herre nike roshe run slip alle r酶d</a> <a href="http://www.paineesq.com/nike-lebron-13-kvinners-r%C3%B8d-oransje-obuvi">nike lebron 13 kvinners r酶d oransje</a> <a href="http://www.gemmatyndall.com/nike-flynit-air-max-kvinners-gr%C3%A5-gull-obuvk">nike flynit air max kvinners gr氓 gull</a> <a href="http://www.cestreaming.com/mennns-nike-flyknit-lunar-1-gr%C3%A5-oransje-obuvi">mennns nike flyknit lunar 1 gr氓 oransje</a>
lavaforchange http://www.lavaforchange.com/
zeraxia
 zeraxia 2019-05-17 18:04回复
#227
<a href="http://www.whatoiljobs.com/nike-sb-rose-dunk-low-chaussuresl">nike sb rose dunk low</a> <a href="http://www.mustberavi.com/nike-mid-blazer-black-shoesj">nike mid blazer black</a> <a href="http://www.dynamixawards.com/tampa-bay-rays-nike-mlb-string-bill-snapback-cap-hatk">tampa bay rays nike mlb string bill snapback cap</a> <a href="http://www.nerdalertnews.com/nike-superfly-cr7-ag-cleats-sort-hvid-bl%C3%A5-skoj">nike superfly cr7 ag cleats sort hvid bl氓</a> <a href="http://www.dmvantalya.com/ralph-lauren-bag-tag-poloh">ralph lauren bag tag</a> <a href="http://www.houshyaree.com/nike-hypervenom-red-shoesi">nike hypervenom red</a>
zeraxia http://www.zeraxia.com/
webrushllc
 webrushllc 2019-05-16 17:34回复
#226
<a href="http://www.awassessment.com/nike-air-max-90-essential-noir-chaussuresl">nike air max 90 essential noir</a> <a href="http://www.websiteopmaat.com/nike-air-max-90-essential-noir-blanc-dark-gris-chaussuresl">nike air max 90 essential noir blanc dark gris</a> <a href="http://www.lopifitfl.com/nike-lebron-13-blau-lagoon-schuhej">nike lebron 13 blau lagoon</a> <a href="http://www.aurorefleurs.com/adidas-nmd-runner-r1-legend-ink-schwarz-schuhei">adidas nmd runner r1 legend ink schwarz</a> <a href="http://www.ezedcal.com/kvinners-nike-huarache-utility-gr%C3%A5-obuvj">kvinners nike huarache utility gr氓</a> <a href="http://www.calsportswear.com/nike-air-max-90-femminile-wholevendita-azure-bianca-scarpel">nike air max 90 femminile wholevendita azure bianca</a>
webrushllc http://www.webrushllc.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸