Home > Backend Development > PHP Tutorial > php变量的新手有关问题

php变量的新手有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:01:02
Original
774 people have browsed it

php变量的新手问题

<br />/**<br />*java的实现<br />*/<br />public class Test{<br />   public final static String COMPANY_NAME="xxxx牛逼公司";//公司名称<br />}<br />其他地方想要用公司名称  可通过Test.COMPANY_NAME来引用<br />php是怎么实现这样的功能?全局变量?<br />
Copy after login

------解决方案--------------------
可以如:
class a{
public $s='test';

function test(){
echo '111';
}
}


$a = new a;
echo $a->s;
------解决方案--------------------

class Test{
public static $COMPANY_NAME="xxxx牛逼公司";//公司名称
}

Test::$COMPANY_NAME;
------解决方案--------------------
也可以直接define
define("COMPANY_NAME","xxxx牛逼公司");
直接用COMPANY_NAME就可以:
echo COMPANY_NAME;
------解决方案--------------------
final 只能用於修飾類和方法,不能修飾變量。
<br />class Test{<br />   public static $COMPANY_NAME="xxxx牛逼公司";//公司名称<br />}<br /><br />echo Test::$COMPANY_NAME;<br />
Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template