Search code examples
phpstringoopoctal

strange behaviour on php


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?


Solution

  • 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.