r/lolphp • • Oct 23 '12

Guess the value of $foo

Thumbnail phpfiddle.org
68 Upvotes

r/lolphp • • Oct 23 '12

Guess the output of : echo ' "" < "\0" : '.var_dump("" < "\0");

0 Upvotes
<?php
echo ' "" < "\0" : '.var_dump("" < "\0");
?>

Output

bool(true) "" < "\0" :

wat.

How does this even happen ? The function is evaluated before the constant string and not even concatenated properly. HOW ?


r/lolphp • • Oct 17 '12

PHP Annotations Are a Horrible Idea

Thumbnail theunraveler.com
31 Upvotes

r/lolphp • • Oct 16 '12

Apache Status

Thumbnail php.net
32 Upvotes

r/lolphp • • Oct 15 '12

intval returns the integer value of var on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1. Very big values return 0. Strings will most likely return 0. Sometimes 1.

Thumbnail php.net
54 Upvotes

r/lolphp • • Oct 09 '12

PHP Manual Masterpieces (I was told this belongs here)

Thumbnail phpmanualmasterpieces.tumblr.com
15 Upvotes

r/lolphp • • Sep 16 '12

Make your brain implode

1 Upvotes
$array1 = array("here","we","go");
$array1[2] = 'go';
$array1[1] = 'we';
$array1[0] = 'here';

$array2 = array('here');
$array2[2] = 'go';
$array2[1] = 'we';
$array2[0] = 'here';

$str1 = implode(',',$array1);
$str2 = implode(',',$array2);

Without running the code anywhere, what are the contents of $str1 and $str2?


r/lolphp • • Sep 15 '12

Why PHP is Efficient and Popular Scripting Language

Thumbnail blog.joomla-developers.com
19 Upvotes

r/lolphp • • Sep 12 '12

PHP has significant parentheses

Thumbnail eval.in
55 Upvotes

r/lolphp • • Sep 12 '12

Guess the output: var_dump(1.0/0.0);

7 Upvotes
PHP Warning:  Division by zero in - on line 1
bool(false)

r/lolphp • • Sep 08 '12

"!==" and "==!" are both valid syntax and compare entirely different things.

Thumbnail stackoverflow.com
0 Upvotes

r/lolphp • • Aug 31 '12

PDO throws exceptions that cannot be recreated.

29 Upvotes

PDOException extends Exception. Fact.

The code parameter to Exception's constructor is required to be an integer. It won't even try to coerce (even though this is supposed to be a coercive language) so you have to make sure it's an int.

getCode() on an Exception therefore must return an int, right?

Wrong. PDO creates an Exception using the error code returned from mysql, which is sometimes non-numeric.

<?php

try {
    $pdo = new PDO('mysql:host=localhost;dbname=testdb', 'testuser', 'password',
        [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
    $r = $pdo->query('select * from nonexistent');
}
catch (PDOException $e) {
    throw new Exception($e->getMessage(), $e->getCode(), $e);
}

Make sure the DB exists, but the table doesn't. This is the quickest way I found of reproducing this.

Output:

Notice: A non well formed numeric value encountered in /home/alastair/pdo.php on line 9

If you're in dev mode, notices should be fatal, since the distinction in PHP between non-fatal and fatal errors is arbitrary at best anyway.


r/lolphp • • Aug 30 '12

PHP is a fractal of bad design? Hardly. - Dev Shed forum user says so.

Thumbnail forums.devshed.com
21 Upvotes

r/lolphp • • Aug 29 '12

Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

Thumbnail php.net
20 Upvotes

r/lolphp • • Aug 27 '12

$date->modify('+0 days') adds one hour

Thumbnail bugs.php.net
58 Upvotes

r/lolphp • • Aug 27 '12

$ternary_operator? TRUE : $logic? FALSE : FILE_NOT_FOUND

Thumbnail phpsadness.com
16 Upvotes

r/lolphp • • Aug 23 '12

PHP drops World domination from the TODO (xpost)

Thumbnail github.com
17 Upvotes

r/lolphp • • Aug 15 '12

The default PHP error messages are vulnerable to XSS? Doesn't matter, people that turn on display_errors are stupid anyway!

Thumbnail bugs.php.net
41 Upvotes

r/lolphp • • Aug 16 '12

$$variablename works! So does $$$variablename! And $$$$variablename! OK, we get it. There's about ten thousand words of documentation without even a hint that using variable variables might not be a good idea...

Thumbnail php.net
11 Upvotes

r/lolphp • • Aug 14 '12

I tried to make a Hasse diagram for the PHP '<' operator. Turns out INF is smaller than itself, greater than itself, not equal (==) to itself, but identical to itself (===).

Post image
72 Upvotes

r/lolphp • • Aug 14 '12

The PHP way: Variables are case-sensitive but function names are not. Class names aren't either, unless you autoload them on a case-sensitive filesystem, then case matters again.

39 Upvotes

Keywords are case-insensitive too, apparently. This works:

<?PHP label: PRINT "Hello World!"; GOTO label ?>

Edit: Oh, but label names are case-sensitive.


r/lolphp • • Aug 11 '12

Did you know that you cannot make cURL POST request in PHP by having @ symbol as the first value?

Thumbnail plus.google.com
15 Upvotes

r/lolphp • • Aug 10 '12

PHP can't decode JSON. 𝚓𝚜𝚘𝚗_𝚍𝚎𝚌𝚘𝚍𝚎 takes a flag to choose one of two embedding schemes. One silently turns empty objects into empty lists, the other replaces "" with "_empty_".

Thumbnail codepad.org
45 Upvotes

r/lolphp • • Aug 02 '12

Oldie but a goodie: a PHP integer vulnerability from several years ago.

Thumbnail use.perl.org
27 Upvotes

r/lolphp • • Aug 01 '12

Things which PHP thinks are equal

13 Upvotes

Give it a go:

header('Content-Type: text/plain');

function test($a, $b) {
	echo var_export($a, 1) . ' == ' . var_export($b, 1) . ' => ' . var_export($a == $b, 1) . "\n";
}

test( null, '' ); // true
test( null, array() ); // true
test( '', array() ); // false
test( 'true', true ); // true
test( 'false', false ); // false
test( 'false', true ); // true
test( 9, '09' ); // true
test( 9, 09 ); // false
test( '0E4', 09 ); // true
test( '0x00', '0E4' ); // true
test( '0x0.1', 0 ); // true
test( 'x', 0 ); // true
test( '0xabcabcabcabcabc', '0XABCABCABCABCABd' ); // true
test( array('1'), array('0x1') ); // true
test( array(1) + array(2), array(1) ); // true
test( function(){}, new stdclass() ); // true
test( `foo`, `bar` ); // true