Home  >  Article  >  php教程  >  演示const

演示const

PHP中文网
PHP中文网Original
2016-05-26 08:18:461051browse

php代码

<?php
/*
 * const
 */
 
 /*常量相对于变量:
  * 1、使用了const修饰符不要再同时使用private、public等修饰符
  * 2、符号前不要加$
  * 3、访问常量无需实例化,它是全局的,不能通过对象访问常量
  * 4、不能也不应该被重新赋值
  * 5、使用::来访问
  * */
 
 class xin {
    const name = "星星 
";
 	const age = 34;
 }
 
 echo xin::name;
 echo xin::age;
 
 $xind = new xin();

Statement:
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
Previous article:计算正态分布Next article:演示静态static