php 上的奇怪行为 [英] strange behaviour on php

查看:66
本文介绍了php 上的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我为什么我运行以下代码会得到奇怪的结果吗?

ID=$id;$this->balance=$balance;$this->name=$name;}函数 getBalance(){返回 $this->balance;}函数 setBalance($bal){$this->balance=$bal;}函数 getId(){返回 $this->ID;}函数 setId($i){$this->ID=$i;})$b=新银行(yaniv,027447002, 15000);

现在当我尝试回声时:

$b->ID

我得到一个奇怪的 6180354,而不是预期的 027447002,但如果我像这样启动对象:

$b=new bank(yaniv,'027447002',15000);

(注意我引用了 id 属性)它工作正常.任何建议为什么会发生这种情况以及解决它的正确方法是什么?

解决方案

027447002 位于 八进制,因为它以零为前缀.将其转换为十进制,您将得到 6180354!

有关详细信息,请参阅关于整数的手册页.>

Can some one please tell me why I get odd results rurning the following code?

<?php
class Bank
{
    var $ID;
    var $balance;
    var $name;
    function bank($name,$id,$balance=0)
    {
        $this->ID=$id;
        $this->balance=$balance;
        $this->name=$name;
    }
    function getBalance()
    {
        return $this->balance;
    }
    function setBalance($bal)
    {
        $this->balance=$bal;
    }
    function getId()
    {
        return $this->ID;
    }
    function setId($i)
    {
        $this->ID=$i;
    }
)
$b= new bank(yaniv,027447002, 15000);

Now when I try to echo:

$b->ID 

Instead of the expected 027447002 I get an odd 6180354, but if I initiate the object like this :

$b=new bank(yaniv,'027447002',15000);

(notice I quoted the id property) it works OK. Any suggestion why is this happening and what is the right way to fix it?

解决方案

027447002 is in octal, as it prefixed with a zero. Convert that to decimal and you get 6180354!

See the manual page on integers for details.

这篇关于php 上的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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