Page 1 of 1
Wierd Syntax
Posted: Mon Dec 21, 2009 6:00 pm
by LarryKreeger
I've been working with LDAPS to reset a users password and password has to be in UTF-8 so
the code reads through an array byte by byte and does this.
$newPassword = "{$Password[$i]}\000";
1. What is the "\" doing? It's not a division operator. Somehow it's appending 3 zeros to the character.
2. Why the "{" brackets? This isn't a function.
The code works but I would just like to understand why.

Re: Wierd Syntax
Posted: Mon Dec 21, 2009 6:07 pm
by daedalus__
when you use a double quote string you can encapsulate variable names in silly brackets to make sure the parser knows its a variable.
like if you say
it'll think that $wiener__ is the variable name so you wrap it
http://us.php.net/manual/en/language.ty ... ng.parsing
Re: Wierd Syntax
Posted: Mon Dec 21, 2009 6:10 pm
by AbraCadaver
Yes, and since you're using an array with [] sometimes it can not be interpreted as a var and it is also easier to read. \ is an esacape character. \n is a newline, \r is a return character, \000 is a null character. Dunno why they are using it there. It may have some significance in LDAP.
Re: Wierd Syntax
Posted: Mon Dec 21, 2009 6:38 pm
by s.dot
This:
Code: Select all
$newPassword = "{$Password[$i]}\000";
is the same as
Code: Select all
$newPassword = $Password[$i] . "\000";
is the same as
Code: Select all
$newPassword = "" . $Password[$i] . "\000";
Just different ways to encapsulate an array index within a string.
Re: Wierd Syntax
Posted: Mon Dec 21, 2009 8:30 pm
by daedalus__
AbraCadaver wrote:\000 is a null character.
lol i was so mad i couldn't remember that.
Re: Wierd Syntax
Posted: Tue Dec 22, 2009 10:27 am
by LarryKreeger
Thanks guys. The {} makes absolute sense. However, we finally found more about the \000. Apparently that is an escape sequence that says the string in front of it is octal. At least that is my interpretation of what I've been reading. We found that in some PERL documentation but it fits with what the PHP is doing. Now I'm going to get an extra large cup of coffee because I need it.
Re: Wierd Syntax
Posted: Tue Dec 22, 2009 11:05 am
by AbraCadaver
LarryKreeger wrote:Thanks guys. The {} makes absolute sense. However, we finally found more about the \000. Apparently that is an escape sequence that says the string in front of it is octal. At least that is my interpretation of what I've been reading. We found that in some PERL documentation but it fits with what the PHP is doing. Now I'm going to get an extra large cup of coffee because I need it.
Yes, \000 is the octal escape sequence for a null byte. \x00 would be the hexadecimal equivalent. Many times \000 would be the decimal code, \o000 would be the octal and \x000 would be the hex, but PHP only supports the \000 octal form and \x000 hex form.
Re: Wierd Syntax
Posted: Tue Dec 22, 2009 12:14 pm
by LarryKreeger
Ok obviously I haven't had enough coffee.
Sooooo you can store octals by \333 or \011 or whatever but \000 is reserved by unicode to denote the end of the character because unicode characters are variable lengths.
Re: Wierd Syntax
Posted: Tue Dec 22, 2009 6:04 pm
by Weirdan
LarryKreeger wrote:Sooooo you can store octals by \333 or \011 or whatever but \000 is reserved by unicode to denote the end of the character because unicode characters are variable lengths.
Null character has no special significance to either Unicode or to its (most widespread) UTF-8 encoding. Sidenote: Unicode (Universal Character Set to be precise) is not encoding, it's character set, and depending on particular encoding its characters could be encoded in variable or constant (bit)lengths.
Re: Wierd Syntax
Posted: Thu Dec 24, 2009 12:02 pm
by LarryKreeger
Thanks guys that helped a lot.