Pass octal value to function

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-24-2005
Brad-H
 
Posts: n/a
Default Pass octal value to function

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
Reply With Quote
  #2 (permalink)  
Old 01-24-2005
skrebbel
 
Posts: n/a
Default Re: Pass octal value to function

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


Reply With Quote
  #3 (permalink)  
Old 01-25-2005
Jeff
 
Posts: n/a
Default Re: Pass octal value to function

You could just send the octal as a string -> "0777" instead of just
0777. PHP is pretty loose, strings and integers can be interchanged.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0