比如: <?php define("c","surfchen"); define("c","冲浪"); echo c; ?> output: surfchenPHP Notice: Constant c already defined in F:\yb\remote\test4.php on line 3 难道类里的常量例外?
应该是个BUG。。在CVS里的版本已经解决了。。 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
<?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------------------------------------------------------------------------