问题描述
我认为我刚刚遇到了我短暂的开发人员生涯中遇到的最奇怪的错误。似乎我无法将值8分配给任何变量。例如:
I think I just encountered the strangest 'bug' I've ever encountered in my short developer life. It seems like I just can't assign the value eight to any variable. For exemple:
<?php
$seven = 07;
$eight = 08; //what's wrong here?
$sevenB = 7;
$eightB = 8;
echo $seven;
echo $eight;
echo $sevenB;
echo $eightB;
?>
输出为:
7078
NetBeans中的调试器告诉我0分配给$ eight,而其他变量很好。
如果我删除了值之前的零,则分配了八个,但是一旦在构造函数中使用了此变量,就会再次将其替换为零。 WTF?
The debugger in NetBeans tells me 0 is assigned to $eight, while the other variables are fine.If I remove the zeroes before the values, eight gets assigned, but as soon as this variable is used in a constructor, then it's replaced by zero again. WTF?
这是我的配置:WAMP 2.0g,PHP 5.2.9,Apache 2.2.11,NetBeans 6.7.1。
禁用Xdebug(2.05)不会改变任何事情。
Here's my config: WAMP 2.0g, PHP 5.2.9, Apache 2.2.11, NetBeans 6.7.1.Disabling Xdebug (2.05) doesn't change a thing.
谁对这种不一致的行为负责?如何解决这个问题?
Who is responsible for this inconsistent behavior? How to fix this?
感谢您的帮助!
推荐答案
PHP使用数字来处理数字
PHP treats numbers with a preceding 0 as an octal.
Re:。
这篇关于奇怪的PHP行为:不会将整数8分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!