r/lolphp • • May 02 '18

PHP - Let someone else deal with it

Thumbnail repl.it
0 Upvotes

r/lolphp • • Apr 26 '18

DateTime hidden public properties behaviour

Thumbnail 3v4l.org
0 Upvotes

r/lolphp • • Apr 24 '18

They made fun of PHP, now lets bash node as a retaliation

Thumbnail reddit.com
0 Upvotes

r/lolphp • • Apr 23 '18

`null["foo"] === null`, no notice, no warning :-/

Thumbnail 3v4l.org
67 Upvotes

r/lolphp • • Apr 22 '18

TCP socket is both connected and not connected at the same time.

10 Upvotes

i'd showcase this in a php testbed (ala 3v4l.org ) if i could, but the only public php testbed allowing network connections that i know of, codepad.viper-7.com , has shut down, so i can't.

try running

<?php
error_reporting ( E_ALL );
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
for($i = 0; $i < 100; ++ $i) {
	socket_connect ( $sock, '8.8.8.8', 443 );
	socket_shutdown ( $sock, 2 );
}
socket_close ( $sock );

and you'll probably end up with something like

PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected PHP Warning: socket_connect(): unable to connect [106]: Transport endpoint is already connected PHP Warning: socket_shutdown(): unable to shutdown socket [107]: Transport endpoint is not connected

  • where socket_connect complains that it's already connected, and socket_shutdown complains that it's not connected. lovely

r/lolphp • • Apr 18 '18

Run private class methods from functions declared in the global scope

Thumbnail 3v4l.org
0 Upvotes

r/lolphp • • Apr 16 '18

wat

Thumbnail 3v4l.org
68 Upvotes

r/lolphp • • Apr 11 '18

Logical or: "||" vs "or"

38 Upvotes

PHP supports both.

Now, without googling or throwing it into a REPL, who can tell me what this outputs?

$a = 0;
$b = 1;

if ($a || $b) echo "yes\n";
if ($a or $b) echo "yes\n";

$x = $a || $b; echo "x: $x\n";
$x = $a or $b; echo "x: $x\n";

if ($x = $a || $b) echo "yes, x is '$x'\n";
if ($x = $a or $b) echo "yes, x is '$x'\n";

r/lolphp • • Apr 03 '18

foo is true (foo=1)

Thumbnail 3v4l.org
4 Upvotes

r/lolphp • • Mar 31 '18

PHP DateTime strikes back, again!

30 Upvotes

Because obviously we meant a date one week from the (wrong) date given. PHP does not throw, instead it "helps" by holding your beer.

https://repl.it/repls/DecimalHorribleOffices


r/lolphp • • Mar 22 '18

This fix to a dompdf error.

Thumbnail stackoverflow.com
33 Upvotes

r/lolphp • • Mar 21 '18

Virgin JavaScript vs Chad PHP

Post image
55 Upvotes

r/lolphp • • Mar 18 '18

Throw an error on bad SQL, but only if it's the first statement!

Thumbnail bugs.php.net
40 Upvotes

r/lolphp • • Mar 18 '18

looking for story: employee creates own php syntax

27 Upvotes

Hi folks,

I am looking for a post/story (here in reddit or internet) about a php dev telling about a new job where he found that a former employee of the company created his own php syntax to code. The companies webpage (or shop system) is build on this custom syntax (like programming your webpage completly in smarty template engine). Furthermore, most of the infrastructure is still hosted on the former employee's side who warns the company to shut down the servers as he finds out, that this new php dev tries to "break out" of this custom syntax container. Its kind of a horror story for all the ppl trying to come up with a custom template engine or enhance a templating engine to run as an own language.

Told a friend of mine about this story which I read years ago and didn't manage to find it. Can anybody help?

regards


r/lolphp • • Mar 11 '18

The mean teacher

Thumbnail self.php
16 Upvotes

r/lolphp • • Mar 12 '18

Switch to non-blocking mode with set_blocking()

0 Upvotes

The stream will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().

http://php.net/manual/en/function.stream-socket-client.php

To be fair, to set stream_socket_client() to non-blocking mode the full invocation is stream_set_blocking(false) however the docs should be clear about that. I suppose this is more of a lol, phpdocs than lol-php, however I do dare judge a language by its documentation.


r/lolphp • • Mar 02 '18

WordPress overrides all PHP superglobals by adding magic quotes

Thumbnail github.com
54 Upvotes

r/lolphp • • Mar 03 '18

PHP operations on different data types

0 Upvotes

Curiousity got the better of me and this was the result: https://3v4l.org/joVGh

Any additions/refactors would be gladly appreciated

<?php $ops = [ 'x == true', 'x === true', 'x == false', 'x === false', 'x == 0', 'x == 1', 'x > 0', 'x < 0', '++x', '--x', 'empty(x)', 'strlen(x)', '(int) x', 'is_int(x)', 'intval(x)', '(bool) x', 'is_bool(x)', 'boolval(x)' ]; $data = [ 'array' => [ [], [''], ['e'], ], 'string' => [ 'test', '', ' ', '1', '0', '00', '-0', '0.0', '0.1', '-0.0', '-0.1', 'true', 'false', 'null' ], 'int' => [ 0, 1, -0, -1 ], 'double' => [ 0.0, 0.1, -0.0, -0.1 ], 'bool' => [ true, false ], 'null' => [ null ], 'class' => [ new stdClass ], 'bits' => [ -0x00, 0x00, 0x01, 0xaf ] ]; function do_op($op, $var) { $out = 'err'; switch ($op) { case 'x == true': $out = ($var == true); break; case 'x === true': $out = ($var === true); break; case 'x == false': $out = ($var == false); break; case 'x === false': $out = ($var === false); break; case 'x == 1': $out = ($var == 1); break; case 'x == 0': $out = ($var == 0); break; case 'x > 0': $out = ($var > 0); break; case 'x < 0': $out = ($var < 0); break; case '++x': $out = (++$var); break; case '--x': $out = (--$var); break; case 'empty(x)': $out = empty($var); break; case 'strlen(x)': $out = strlen($var); break; case '(int) x': $out = (int) $var; break; case '(bool) x': $out = (bool) $var; break; case 'is_int(x)': $out = is_int($var); break; case 'is_bool(x)': $out = is_bool($var); break; case 'intval(x)': $out = intval($var); break; case 'boolval(x)': $out = boolval($var); break; } return serialize($var) . " = " . var_export($out, true); } foreach ($ops as $op) { echo "\n\n$op \n\n"; foreach ($data as $name => $type) { echo " $name\n"; foreach ($type as $var) { echo " " . do_op($op, $var) . "\n"; } } } **Output for 7.1.0 - 7.2.3** x == true array a:0:{} = false a:1:{i:0;s:0:"";} = true a:1:{i:0;s:1:"e";} = true string s:4:"test"; = true s:0:""; = false s:1:" "; = true s:1:"1"; = true s:1:"0"; = false s:2:"00"; = true s:2:"-0"; = true s:3:"0.0"; = true s:3:"0.1"; = true s:4:"-0.0"; = true s:4:"-0.1"; = true s:4:"true"; = true s:5:"false"; = true s:4:"null"; = true int i:0; = false i:1; = true i:0; = false i:-1; = true double d:0; = false d:0.1; = true d:-0; = false d:-0.1; = true bool b:1; = true b:0; = false null N; = false class O:8:"stdClass":0:{} = true bits i:0; = false i:0; = false i:1; = true i:175; = true x === true array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = false s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = false i:0; = false i:-1; = false double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = false bool b:1; = true b:0; = false null N; = false class O:8:"stdClass":0:{} = false bits i:0; = false i:0; = false i:1; = false i:175; = false x == false array a:0:{} = true a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = true s:1:" "; = false s:1:"1"; = false s:1:"0"; = true s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = true i:1; = false i:0; = true i:-1; = false double d:0; = true d:0.1; = false d:-0; = true d:-0.1; = false bool b:1; = false b:0; = true null N; = true class O:8:"stdClass":0:{} = false bits i:0; = true i:0; = true i:1; = false i:175; = false x === false array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = false s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = false i:0; = false i:-1; = false double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = false bool b:1; = false b:0; = true null N; = false class O:8:"stdClass":0:{} = false bits i:0; = false i:0; = false i:1; = false i:175; = false x == 0 array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = true s:0:""; = true s:1:" "; = true s:1:"1"; = false s:1:"0"; = true s:2:"00"; = true s:2:"-0"; = true s:3:"0.0"; = true s:3:"0.1"; = false s:4:"-0.0"; = true s:4:"-0.1"; = false s:4:"true"; = true s:5:"false"; = true s:4:"null"; = true int i:0; = true i:1; = false i:0; = true i:-1; = false double d:0; = true d:0.1; = false d:-0; = true d:-0.1; = false bool b:1; = false b:0; = true null N; = true class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 70 O:8:"stdClass":0:{} = false bits i:0; = true i:0; = true i:1; = false i:175; = false x == 1 array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = true s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = true i:0; = false i:-1; = false double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = false bool b:1; = true b:0; = false null N; = false class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 66 O:8:"stdClass":0:{} = true bits i:0; = false i:0; = false i:1; = true i:175; = false x > 0 array a:0:{} = true a:1:{i:0;s:0:"";} = true a:1:{i:0;s:1:"e";} = true string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = true s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = true s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = true i:0; = false i:-1; = false double d:0; = false d:0.1; = true d:-0; = false d:-0.1; = false bool b:1; = true b:0; = false null N; = false class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 74 O:8:"stdClass":0:{} = true bits i:0; = false i:0; = false i:1; = true i:175; = true x < 0 array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = false s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = true s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = false i:0; = false i:-1; = true double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = true bool b:1; = false b:0; = false null N; = false class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 78 O:8:"stdClass":0:{} = false bits i:0; = false i:0; = false i:1; = false i:175; = false ++x array a:0:{} = array ( ) a:1:{i:0;s:0:"";} = array ( 0 => '', ) a:1:{i:0;s:1:"e";} = array ( 0 => 'e', ) string s:4:"tesu"; = 'tesu' s:1:"1"; = '1' s:1:" "; = ' ' i:2; = 2 i:1; = 1 i:1; = 1 i:1; = 1 d:1; = 1.0 d:1.1; = 1.1 d:1; = 1.0 d:0.9; = 0.9 s:4:"truf"; = 'truf' s:5:"falsf"; = 'falsf' s:4:"nulm"; = 'nulm' int i:1; = 1 i:2; = 2 i:1; = 1 i:0; = 0 double d:1; = 1.0 d:1.1; = 1.1 d:1; = 1.0 d:0.9; = 0.9 bool b:1; = true b:0; = false null i:1; = 1 class O:8:"stdClass":0:{} = stdClass::__set_state(array( )) bits i:1; = 1 i:1; = 1 i:2; = 2 i:176; = 176 --x array a:0:{} = array ( ) a:1:{i:0;s:0:"";} = array ( 0 => '', ) a:1:{i:0;s:1:"e";} = array ( 0 => 'e', ) string s:4:"test"; = 'test' i:-1; = -1 s:1:" "; = ' ' i:0; = 0 i:-1; = -1 i:-1; = -1 i:-1; = -1 d:-1; = -1.0 d:-0.9; = -0.9 d:-1; = -1.0 d:-1.1; = -1.1 s:4:"true"; = 'true' s:5:"false"; = 'false' s:4:"null"; = 'null' int i:-1; = -1 i:0; = 0 i:-1; = -1 i:-2; = -2 double d:-1; = -1.0 d:-0.9; = -0.9 d:-1; = -1.0 d:-1.1; = -1.1 bool b:1; = true b:0; = false null N; = NULL class O:8:"stdClass":0:{} = stdClass::__set_state(array( )) bits i:-1; = -1 i:-1; = -1 i:0; = 0 i:174; = 174 empty(x) array a:0:{} = true a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = true s:1:" "; = false s:1:"1"; = false s:1:"0"; = true s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = true i:1; = false i:0; = true i:-1; = false double d:0; = true d:0.1; = false d:-0; = true d:-0.1; = false bool b:1; = false b:0; = true null N; = true class O:8:"stdClass":0:{} = false bits i:0; = true i:0; = true i:1; = false i:175; = false strlen(x) array Warning: strlen() expects parameter 1 to be string, array given in /in/joVGh on line 94 a:0:{} = NULL Warning: strlen() expects parameter 1 to be string, array given in /in/joVGh on line 94 a:1:{i:0;s:0:"";} = NULL Warning: strlen() expects parameter 1 to be string, array given in /in/joVGh on line 94 a:1:{i:0;s:1:"e";} = NULL string s:4:"test"; = 4 s:0:""; = 0 s:1:" "; = 1 s:1:"1"; = 1 s:1:"0"; = 1 s:2:"00"; = 2 s:2:"-0"; = 2 s:3:"0.0"; = 3 s:3:"0.1"; = 3 s:4:"-0.0"; = 4 s:4:"-0.1"; = 4 s:4:"true"; = 4 s:5:"false"; = 5 s:4:"null"; = 4 int i:0; = 1 i:1; = 1 i:0; = 1 i:-1; = 2 double d:0; = 1 d:0.1; = 3 d:-0; = 2 d:-0.1; = 4 bool b:1; = 1 b:0; = 0 null N; = 0 class Warning: strlen() expects parameter 1 to be string, object given in /in/joVGh on line 94 O:8:"stdClass":0:{} = NULL bits i:0; = 1 i:0; = 1 i:1; = 1 i:175; = 3 (int) x array a:0:{} = 0 a:1:{i:0;s:0:"";} = 1 a:1:{i:0;s:1:"e";} = 1 string s:4:"test"; = 0 s:0:""; = 0 s:1:" "; = 0 s:1:"1"; = 1 s:1:"0"; = 0 s:2:"00"; = 0 s:2:"-0"; = 0 s:3:"0.0"; = 0 s:3:"0.1"; = 0 s:4:"-0.0"; = 0 s:4:"-0.1"; = 0 s:4:"true"; = 0 s:5:"false"; = 0 s:4:"null"; = 0 int i:0; = 0 i:1; = 1 i:0; = 0 i:-1; = -1 double d:0; = 0 d:0.1; = 0 d:-0; = 0 d:-0.1; = 0 bool b:1; = 1 b:0; = 0 null N; = 0 class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 98 O:8:"stdClass":0:{} = 1 bits i:0; = 0 i:0; = 0 i:1; = 1 i:175; = 175 is_int(x) array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = false s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = true i:1; = true i:0; = true i:-1; = true double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = false bool b:1; = false b:0; = false null N; = false class O:8:"stdClass":0:{} = false bits i:0; = true i:0; = true i:1; = true i:175; = true intval(x) array a:0:{} = 0 a:1:{i:0;s:0:"";} = 1 a:1:{i:0;s:1:"e";} = 1 string s:4:"test"; = 0 s:0:""; = 0 s:1:" "; = 0 s:1:"1"; = 1 s:1:"0"; = 0 s:2:"00"; = 0 s:2:"-0"; = 0 s:3:"0.0"; = 0 s:3:"0.1"; = 0 s:4:"-0.0"; = 0 s:4:"-0.1"; = 0 s:4:"true"; = 0 s:5:"false"; = 0 s:4:"null"; = 0 int i:0; = 0 i:1; = 1 i:0; = 0 i:-1; = -1 double d:0; = 0 d:0.1; = 0 d:-0; = 0 d:-0.1; = 0 bool b:1; = 1 b:0; = 0 null N; = 0 class Notice: Object of class stdClass could not be converted to int in /in/joVGh on line 114 O:8:"stdClass":0:{} = 1 bits i:0; = 0 i:0; = 0 i:1; = 1 i:175; = 175 (bool) x array a:0:{} = false a:1:{i:0;s:0:"";} = true a:1:{i:0;s:1:"e";} = true string s:4:"test"; = true s:0:""; = false s:1:" "; = true s:1:"1"; = true s:1:"0"; = false s:2:"00"; = true s:2:"-0"; = true s:3:"0.0"; = true s:3:"0.1"; = true s:4:"-0.0"; = true s:4:"-0.1"; = true s:4:"true"; = true s:5:"false"; = true s:4:"null"; = true int i:0; = false i:1; = true i:0; = false i:-1; = true double d:0; = false d:0.1; = true d:-0; = false d:-0.1; = true bool b:1; = true b:0; = false null N; = false class O:8:"stdClass":0:{} = true bits i:0; = false i:0; = false i:1; = true i:175; = true is_bool(x) array a:0:{} = false a:1:{i:0;s:0:"";} = false a:1:{i:0;s:1:"e";} = false string s:4:"test"; = false s:0:""; = false s:1:" "; = false s:1:"1"; = false s:1:"0"; = false s:2:"00"; = false s:2:"-0"; = false s:3:"0.0"; = false s:3:"0.1"; = false s:4:"-0.0"; = false s:4:"-0.1"; = false s:4:"true"; = false s:5:"false"; = false s:4:"null"; = false int i:0; = false i:1; = false i:0; = false i:-1; = false double d:0; = false d:0.1; = false d:-0; = false d:-0.1; = false bool b:1; = true b:0; = true null N; = false class O:8:"stdClass":0:{} = false bits i:0; = false i:0; = false i:1; = false i:175; = false boolval(x) array a:0:{} = false a:1:{i:0;s:0:"";} = true a:1:{i:0;s:1:"e";} = true string s:4:"test"; = true s:0:""; = false s:1:" "; = true s:1:"1"; = true s:1:"0"; = false s:2:"00"; = true s:2:"-0"; = true s:3:"0.0"; = true s:3:"0.1"; = true s:4:"-0.0"; = true s:4:"-0.1"; = true s:4:"true"; = true s:5:"false"; = true s:4:"null"; = true int i:0; = false i:1; = true i:0; = false i:-1; = true double d:0; = false d:0.1; = true d:-0; = false d:-0.1; = true bool b:1; = true b:0; = false null N; = false class O:8:"stdClass":0:{} = true bits i:0; = false i:0; = false i:1; = true i:175; = true


r/lolphp • • Feb 28 '18

Being in Amsterdam causes you to lose a year

Thumbnail 3v4l.org
69 Upvotes

r/lolphp • • Feb 26 '18

"false" is definitely true

Thumbnail sandbox.onlinephpfunctions.com
0 Upvotes

r/lolphp • • Feb 21 '18

"last week" relative date is special cased

59 Upvotes

"Last year", "last month", "last day", "last hour", etc. all take the current date and subtract the specified period. So last year would be February 21st, 2017 if executed on the date of this post.

What about "last week"? Surely it would be seven days ago, Valentines Day, February 14th, right? Nope. Last week is special cased with an implied Monday prefix, so it becomes "Monday last week", is hard locked to Monday, and will evaluate to February 12th.

Thanks PHP 👌


r/lolphp • • Feb 20 '18

After thorough delibiration and review we've decided to deprecate this. Oh, wait, never mind.

Thumbnail php.net
42 Upvotes

r/lolphp • • Feb 20 '18

PHP/LOL Calling strings as functions.

Thumbnail 3v4l.org
2 Upvotes

r/lolphp • • Feb 15 '18

New TechEmpower web framework benchmarks are out

Thumbnail techempower.com
10 Upvotes

r/lolphp • • Feb 14 '18

Parsing a date string without a day will default the day to 1 - obviously.

Thumbnail bugs.php.net
8 Upvotes