Home > php教程 > PHP源码 > 演示const

演示const

PHP中文网
Release: 2016-05-26 08:18:46
Original
1130 people have browsed it

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();
Copy after login

Related labels:
source:php.cn
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template