{"id":275,"date":"2011-08-31T13:02:12","date_gmt":"2011-08-31T20:02:12","guid":{"rendered":"http:\/\/www.hongyu.org\/wordpress\/?p=275"},"modified":"2011-08-31T13:02:12","modified_gmt":"2011-08-31T20:02:12","slug":"php-const-and-static-variables","status":"publish","type":"post","link":"https:\/\/www.hongyu.org\/wordpress\/?p=275","title":{"rendered":"PHP const and static variables"},"content":{"rendered":"<p>In addition to that const variables can&#8217;t be changed, another difference between const and static is that some variables like arrays are not allowed in class constants, so<\/p>\n<p><code>class mytest<br \/>\n{<br \/>\n    public static $c = array(1=> 'hello', 2=>'world');<br \/>\n}<\/code><br \/>\nworks, but<\/p>\n<p><code>class mytest<br \/>\n{<br \/>\n    const c = array(1=> 'hello', 2=>'world');<br \/>\n}<\/code><br \/>\nwon&#8217;t.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In addition to that const variables can&#8217;t be changed, another difference between const and static is that some variables like arrays are not allowed in class constants, so class mytest { public static $c = array(1=> &#8216;hello&#8217;, 2=>&#8217;world&#8217;); } works, but class mytest { const c = array(1=> &#8216;hello&#8217;, 2=>&#8217;world&#8217;); } won&#8217;t.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/275"}],"collection":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=275"}],"version-history":[{"count":1,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":276,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/275\/revisions\/276"}],"wp:attachment":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}