This is a discussion on Pass octal value to function within the PHP Language forums, part of the PHP Programming Forums category; Does anyone know how to pass an octal value to a function successfully? I am trying to create a class ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Does anyone know how to pass an octal value to a function
successfully? I am trying to create a class to handle directory permissions but passing the permission settings is going nowhere. Octals seem to automatically get converted to decimal when sent and when trying to convert back using decoct the 0 is dropped. I have also tried sending as a string but chmod() does not accept string input and I haven't been able to convert back to a number & retain the leading 0. Thanks sample. test(0777); function test($myvar){ echo "PASSED VAL:".$myvar; // PASSED VAL:511 echo "DECOCT:".decoct($myvar); // DECOCT:777 echo "STRING:".(('0'.decoct($myvar))*1); // STRING:777 |
|
|||
|
"Brad-H" <brad.hile@gmail.com> wrote in message
news:632f8a86.0501231653.782d0f0e@posting.google.c om... > Does anyone know how to pass an octal value to a function > successfully? > I am trying to create a class to handle directory permissions but > passing the permission settings is going nowhere. > > Octals seem to automatically get converted to decimal when sent and > when trying to convert back using decoct the 0 is dropped. > I have also tried sending as a string but chmod() does not accept > string input and I haven't been able to convert back to a number & > retain the leading 0. > > Thanks > > sample. > > test(0777); > > function test($myvar){ > echo "PASSED VAL:".$myvar; > // PASSED VAL:511 ok so what's wrong there? i guess if you'd pass the (decimal) 511 to chmod, it'll interpret it just like it'd interpret a literal 0777. > echo "DECOCT:".decoct($myvar); > // DECOCT:777 > echo "STRING:".(('0'.decoct($myvar))*1); > // STRING:777 try echo "STRING:". '0'.(decoct($myvar)*1); you first prepended the '0', making it a string, and then multiplied by 1, turning it into an integer again. |