690 karma · joined November 3, 2010
But one way that is easier than diving into the source code is to just dump the opcodes using vld (see pecl.vld). I have a little wrapper shell script /usr/local/bin/vld:
#!/bin/sh -e
exec php -dvld.active=1 -d vld.execute=0 "$@"
Then for the hello world program with the print() call: % vld hello1.php
Finding entry points
Branch analysis from position: 0
Return found
filename: /tmp/hello1.php
function name: (null)
number of ops: 3
compiled vars: none
line # * op fetch ext return operands
---------------------------------------------------------------------------------
2 0 > PRINT ~0 'Hello+World'
1 FREE ~0
4 2 > RETURN 1
branch: # 0; line: 2- 4; sop: 0; eop: 2
path #1: 0,
vs. the one that just contains the string: Hello World % vld hello2.php
Finding entry points
Branch analysis from position: 0
Return found
filename: /tmp/hello2.php
function name: (null)
number of ops: 2
compiled vars: none
line # * op fetch ext return operands
---------------------------------------------------------------------------------
2 0 > ECHO 'Hello+World%0A'
1 > RETURN 1
branch: # 0; line: 2- 2; sop: 0; eop: 1
path #1: 0,Hello World
The one they have with <?php print("Hello World"); ?> is also an opcode longer than using <?php echo "Hello World"; ?> because off the FREE on the return value from the print. But a file just containing the string: Hello World and nothing else will generate the same opcodes as the echo version so they are equivalent and you might as well use the shorter form. A file without an opening <?php tag is still a perfectly valid PHP program.
http://www.zeromq.org/bindings:javascript
Semantically it is clean, but the flash part is a bit ugly.
$a = array(1,2,array(3,4));
becomes: $a = [1,2,[3,4]];
Also 0b101010
works in 5.4. php > $ಠ_ಠ = 1;
php > echo $ಠ_ಠ;
1
php > $π = pi();
php > echo $π;
3.1415926535897931159979634685442
php > function ಠ_ಠ() { echo 1; }
php > ಠ_ಠ();
1(Unless things have changed, I graduated in 1993 and this was the case back then)
Inside on* handlers and style attributes, the rules are different. Take something like this:
<?php $foo = htmlspecialchars($_GET['foo'], ENT_QUOTES);?> <a href="" onmouseover="a='Fantas<?php echo $foo?>tic';">Mouse Over Me</a>
htmlspecialchars() does its job here. It turns a single quote into ' however, inside on* and style attributes the ' entity is treated as a raw single quote. You need to double-escape in this particular case to be safe, or better yet, don't use raw on* handlers and style attributes. There are much cleaner ways to do those, but if you have to, don't ever put user data in them because you will mess up the escaping.
You can try a live example here:
http://talks.php.net/show/flux/14
It is not possible to write a single generic html escaping function that will work in all contexts. If it was, I would have written htmlspecialchars() differently.
There are more examples of how you can mess up even if you always quote your attributes if your escaping function isn't smart. The UTF-7 hack was mentioned, which is good, but the invalid UTF-8 hack wasn't explained. That is, if you send an invalid UTF-8 sequence, like %E0 then certain browsers (well, just IE) will lose their minds unless you make sure you don't display that invalid UTF-8 sequence back to the user. So htmlspecialchars() does more than just escape the set of chars you mentioned, it also validates the characters and makes sure it never outputs an invalid UTF-8 byte sequence.
0xE0 by itself is the first byte of a 3-byte UTF-8 char and IE will simply eat the following 2 bytes to make up the char. So if you output: "<e0>"> even though the byte is inside quotes, IE will eat the following "> and replace those 3 bytes with the dreaded (?) char, but more disastrously it will think it is still inside the quoted attribute so the next raw quote it sees will end the attribute and you have yourself another quoted xss hole.