奇怪的PHP行为:不会将整数8分配给变量 [英] Weird PHP behavior: won't assign the integer 8 to a variable

查看:81
本文介绍了奇怪的PHP行为:不会将整数8分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我刚刚遇到了我短暂的开发人员生涯中遇到的最奇怪的错误。似乎我无法将值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:整数

这篇关于奇怪的PHP行为:不会将整数8分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆