473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jul 17 '05 #1
2 4283
"Brad-H" <br*******@gmail.com> wrote in message
news:63**************************@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.
Jul 17 '05 #2
You could just send the octal as a string -> "0777" instead of just
0777. PHP is pretty loose, strings and integers can be interchanged.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Sean McIlroy | last post by:
I recently found out that unicode("\347", "iso-8859-1") is the lowercase c-with-cedilla, so I set out to round up the unicode numbers of the extra characters you need for French, and I found them...
1
by: Stan | last post by:
The convert method allows us to change any base number (bin, octal, hex ) to decimal, but how can I change a decimal value back to an octal number??? Thanks in advance Stan
27
by: fuch6921 | last post by:
I want to read in an Octal number argument and have it stored as an octal number. For instance the user will type: ./a.out 777 and it will store the octal number 777. But it atoi does this as an...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
7
by: Gary Brown | last post by:
Hi, I have a whole bunch of integer constants that are best given in octal (PDP-1 opcodes). It makes a huge difference in readability and authenticity if these can be entered in octal. I...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
10
by: laurent.pauloin | last post by:
Hello, I would like to print a signed octal. With a signed short it's printf %hi but what about an octal ? Tk !
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.