常量可以二次赋值吗??不是应该抛出一个:Notice: Constant c already defined吗?
解决方案 »
- 在线代理程序firefox下的问题
- php 生成静态页面,如何添加google广告?
- 关于更新数据库问题!
- 大型网站架构问题。高手请入
- 附件上传下载怎么写啊
- 高人们看看啊,十几口子等着答案下锅呐 phpwind论坛安装问题
- 登陆问题
- Failed opening required './include/common.php' ,改成$_SERVER["DOCUMENT_ROOT"].'/include/common.php' 才行
- 言出必行,欠分要给。(该给chxzll(chxzll) 的100分,并感谢他的帮助!)
- PHP初学者的问题,快来拿分呀!!!
- 怎么用PUBLIC出错?
- phpMyAdmin 260变化不小啊,漂亮多了
<?php
define("c","surfchen");
define("c","冲浪");
echo c;
?>
output:
surfchenPHP Notice: Constant c already defined in F:\yb\remote\test4.php on line 3
难道类里的常量例外?
放在外面看看
++++=============================什么意思呢?
<?php
class Mother
{
const c="surfchen";
const c="冲浪";
}
echo Mother::c;
?>在这里。为什么常量c能二次赋值??如果能二次,那它还叫常量吗?
子类不能继承父类的private变量。所以两次赋值不冲突。
如果你把父的public const c=".."。应该是要throw出exception.
可能是我给出的代码过多了,给你们一种另外的感觉了现在不要看楼顶帖的看下面这个<?php
class Mother
{
const c="surfchen";
const c="冲浪";
}
echo Mother::c;
?>
为什么输出的是冲浪?常量的基本定义就是一个只能赋值一次的量。如果在一个常量的赋值操作之前已经进行过了赋值操作,那么此次操作将会抛出一个错误。
另外我想顺便说一下在一个类里,如果成员没有声明作用域,那么它默认是public.
所以 pwtitle(doodoo) 所说的public const c=""肯定会抛出一个错误。。
php.net那里的专家的回复
呵呵,看来还是php.net最专业New Comment:seems to work fine now,
great many thanks for improving PHP's quality
best regards
Previous Comments:
------------------------------------------------------------------------[2004-09-10 15:12:15] [email protected] mean FIXED in CVS, try latest snapshots.------------------------------------------------------------------------[2004-09-10 15:11:12] [email protected] try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip------------------------------------------------------------------------