好!欢迎访问迷津渡口 现在时间是: 天气 °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
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
brotherfriend
 brotherfriend 约 5 小时前回复
#127
<a href="http://www.lasdamas.net/nike-air-force-1-dusty-gr%C3%A5-schuhea">nike air force 1 dusty gr氓</a> <a href="http://www.lavoilebleue.net/nike-tanjun-blanc-marron-chaussuresa">nike tanjun blanc marron</a> <a href="http://www.lifechurchindy.net/nike-free-3.0-v4-lyser%C3%B8d-and-bl%C3%A5-obuva">nike free 3.0 v4 lyser酶d and bl氓</a> <a href="http://www.lincei.net/jordan-flight-runner-2-gr%C3%A5-butyc">jordan flight runner 2 gr氓</a> <a href="http://www.litpower.net/kyrie-1-naranja-and-blanco-vine-scarpeb">kyrie 1 naranja and blanco vine</a> <a href="http://www.lngstation.net/lebron-13-todas-negro-zombie-kurpesf">lebron 13 todas negro zombie</a>
brotherfriend http://www.brotherfriend.net/
tubetotext
 tubetotext 2019-03-20 09:15回复
#126
<a href="http://www.cakeeaterspgh.com/nike-womens-chris-godwin-red-name-number-logo-tampa-bay-buccaneers-nfl-12-t-shirt-nflw">nike womens chris godwin red name number logo tampa bay buccaneers nfl 12 t shirt</a> <a href="http://www.itlooksohot.com/new-balance-990-plata-verde-schuhef">new balance 990 plata verde</a> <a href="http://www.naijareward.com/adidas-zx-flux-scarpe-maschio-belt-scarpef">adidas zx flux scarpe maschio belt</a> <a href="http://www.nhadatmoivn.com/nike-air-max-1-cuir-granite-hot-rouge-kurpese">nike air max 1 cuir granite hot rouge</a> <a href="http://www.piernowedding.com/nike-air-force-one-bambini-rosa-schuhef">nike air force one bambini rosa</a> <a href="http://www.storagelayout.com/nike-kd-7-kvinders-bl%C3%A5-hvid-schuheb">nike kd 7 kvinders bl氓 hvid</a>
tubetotext http://www.tubetotext.com/
reganwhimpey
 reganwhimpey 2019-03-20 03:08回复
#125
<a href="http://www.inckua.com/dallas-cowboys-adjustable-cap-hatg">dallas cowboys adjustable cap</a> <a href="http://www.essodustade.com/adidas-foot-shoes-skox">adidas foot shoes</a> <a href="http://www.olgroupusainc.com/nike-zoom-pegasus-33-kvinders-bl%C3%A5-shoesb">nike zoom pegasus 33 kvinders bl氓</a> <a href="http://www.caryongpum.com/adidas-superstar-boost-pink-runningb">adidas superstar boost pink</a> <a href="http://www.postanje.com/ugg-boots-bailey-button-bling-uggsr">ugg boots bailey button bling</a> <a href="http://www.synergysimple.com/ray-ban-aviator-sunglasses-buy-online-sunglassesr">ray ban aviator sunglasses buy online</a>
reganwhimpey http://www.reganwhimpey.com/
bartezloudge
 bartezloudge 2019-03-20 02:30回复
#124
<a href="http://www.completefight.com/nike-free-5.0-schwarz-wei%C3%9F-cool-grau-butye">nike free 5.0 schwarz wei脽 cool grau</a> <a href="http://www.dealingsnet.com/kyrie-3-for-vendita-maschio-obuvd">kyrie 3 for vendita maschio</a> <a href="http://www.eyehearsea.com/nike-air-max-jr-wei%C3%9F-sox-scarpee">nike air max jr wei脽 sox</a> <a href="http://www.flixflight.com/salomon-speedcross-3-sort-kvinders-keys-obuvd">salomon speedcross 3 sort kvinders keys</a> <a href="http://www.adappi.com/nike-air-flight-89-gr%C3%B8nn-tree-chaussuresg">nike air flight 89 gr酶nn tree</a> <a href="http://www.berealto.com/curry-2-schuhe-herren-king-chaussuresa">curry 2 schuhe herren king</a>
[url=http://www.bartezloudge.com/]bartezloudge[/url]
inwardoutward
 inwardoutward 2019-03-19 19:38回复
#123
<a href="http://www.interfaithstewards.net/nike-huarache-blanc-bleu-violet-schuhee">nike huarache blanc bleu violet</a> <a href="http://www.inwardoutward.net/air-jordan-14-thunder-bon-march%C3%A9-obuvd">air jordan 14 thunder bon march茅</a> <a href="http://www.isabellenhuette.net/air-jordan-retro-28-blanc-bleu-ciel-butyd">air jordan retro 28 blanc bleu ciel</a> <a href="http://www.jeffersonshine.net/nike-lebron-13-gs-wolf-gr%C3%A5-wolf-obuvc">nike lebron 13 gs wolf gr氓 wolf</a> <a href="http://www.jerfsa.net/nike-gris-blazer-low-vintage-kurpesf">nike gris blazer low vintage</a> <a href="http://www.jgeinc.net/roshe-run-nike-schwarz-rot-kurpesa">roshe run nike schwarz rot</a>
inwardoutward http://www.inwardoutward.net/
prohaarklinik
 prohaarklinik 2019-03-19 18:09回复
#122
<a href="http://www.theislandbody.com/los-angeles-rams-47-nfl-kids-clean-up-cap-hath">los angeles rams 47 nfl kids clean up cap</a> <a href="http://www.zululeads.com/nike-kobe-10-poison-vert-sequoia-volt-chaussuresh">nike kobe 10 poison vert sequoia volt</a> <a href="http://www.notmyrichie.com/nike-air-max-zero-blanc-rouge-chaussuresj">nike air max zero blanc rouge</a> <a href="http://www.mintyschoice.com/dam%C3%A4nner-nike-roshe-run-triangle-blau-orangen-schuhej">dam盲nner nike roshe run triangle blau orangen</a> <a href="http://www.mamapjblog.com/nike-lunar-presto-sort-bl%C3%A5-skok">nike lunar presto sort bl氓</a> <a href="http://www.pdfunicorn.com/air-jordan-true-flight-viola-verde-scarpeh">air jordan true flight viola verde</a>
prohaarklinik http://www.prohaarklinik.com/
findatrans
 findatrans 2019-03-18 12:13回复
#121
<a href="http://www.colintilley.com/nike-roshe-run-hvit-camo-obuvj">nike roshe run hvit camo</a> <a href="http://www.xthbgc.com/maschio-asics-asics-gel-kayano-20-oro-viola-scarpep">maschio asics asics gel kayano 20 oro viola</a> <a href="http://www.iberishop.com/adidas-nmd-runner-oranger-vert-chaussuresh">adidas nmd runner oranger vert</a> <a href="http://www.karmacanix.com/prada-flower-wallet-pradah">prada flower wallet</a> <a href="http://www.tobepartridge.com/chicago-bulls-custom-jersey-nfli">chicago bulls custom jersey</a> <a href="http://www.shopdunks.com/kvinders-nike-air-max-tailwind-5-lyser%C3%B8d-bl%C3%A5-skoq">kvinders nike air max tailwind 5 lyser酶d bl氓</a>
findatrans http://www.findatrans.com/
magicstockdz
 magicstockdz 2019-03-17 16:12回复
#120
<a href="http://www.paulabandura.com/hermes-coaching-scarf-scarfr">hermes coaching scarf</a> <a href="http://www.cartsdk.com/bon-march%C3%A9-nike-zoom-structure-19-hommes-jaune-sneakerd">bon march茅 nike zoom structure 19 hommes jaune</a> <a href="http://www.breachurch.com/gold-purple-womens-nike-shoes-2017-shoes-shoesf">gold purple womens nike shoes 2017 shoes</a> <a href="http://www.facommobiles.com/ray-ban-jackie-ohh-violet-sunglassesr">ray ban jackie ohh violet</a> <a href="http://www.sarkariresurt.com/polo-ralph-lauren-textured-henley-shirt-uk-polod">polo ralph lauren textured henley shirt uk</a> <a href="http://www.oriturk.com/ray-ban-sunglasses-clubmaster-green-sunglassesr">ray ban sunglasses clubmaster green</a>
magicstockdz http://www.magicstockdz.com/
ladivorcecpa
 ladivorcecpa 2019-03-17 07:53回复
#119
<a href="http://www.hitsturbines.com/kvinners-air-jordan-10-royal-bl%C3%A5-obuvf">kvinners air jordan 10 royal bl氓</a> <a href="http://www.jadamsrealtor.com/nike-sb-stefan-janoski-max-kvinders-sort-orange-obuvd">nike sb stefan janoski max kvinders sort orange</a> <a href="http://www.karenconti.com/air-max-1-ultra-essential-svart-kurpesf">air max 1 ultra essential svart</a> <a href="http://www.cliffsears.com/nike-air-max-1-zwart-laser-crimson-bianca-obuvb">nike air max 1 zwart laser crimson bianca</a> <a href="http://www.rfsloan.com/under-armour-curry-3-wei%C3%9F-schwarz-turnschuhe-butya">under armour curry 3 wei脽 schwarz turnschuhe</a> <a href="http://www.gfwholesalers.com/old-lebron-james-jersey-nflu">old lebron james jersey</a>
ladivorcecpa http://www.ladivorcecpa.com/
rsvppersonnel
 rsvppersonnel 2019-03-15 19:16回复
#118
<a href="http://www.teamdalarna.com/under-armour-curry-one-bleu-vert-chaussuresl">under armour curry one bleu vert</a> <a href="http://www.syairshamyoun.com/air-jordan-retro-9-vert-jaune-chaussuresq">air jordan retro 9 vert jaune</a> <a href="http://www.fizalisfresh.com/adidas-zx-630-rot-himmelblau-schuhei">adidas zx 630 rot himmelblau</a> <a href="http://www.fsscas.com/nike-air-max-tailwind-6-dam%C3%A4nner-grau-wei%C3%9F-schuheh">nike air max tailwind 6 dam盲nner grau wei脽</a> <a href="http://www.imagimp.com/mennns-nike-air-max-tailwind-8-bl%C3%A5-hvit-obuvj">mennns nike air max tailwind 8 bl氓 hvit</a> <a href="http://www.burmamaritime.com/nike-air-max-90-premium-tape-blu-hero-camo-scarpep">nike air max 90 premium tape blu hero camo</a>
rsvppersonnel http://www.rsvppersonnel.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸