subreddit
stringclasses
7 values
author
stringlengths
3
20
id
stringlengths
5
7
content
stringlengths
67
30.4k
score
int64
0
140k
lolphp
notian
e9xhx9l
<|sols|><|sot|>C's strlen() ftw<|eot|><|sol|>http://php.net/manual/en/sqlite3.escapestring.php<|eol|><|sor|>Okay....what am I missing?<|eor|><|soopr|>here's my problem: <?php function my_retarded_escape(string $str): string { $parts = explode("\00", $str); $parts = array_map([ 'SQLite3', 'escapeString' ], $parts); $str = implode("' || x'00' || '", $parts); return $str; } $db = new PDO('sqlite::memory:', '', '', array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); $db->exec(' CREATE TABLE foo(input TEXT);'); $text = "tro\x00lolo"; $db->query("INSERT INTO foo(`input`) VALUES ('" . SQLite3::escapeString($text) . "'),('" . my_retarded_escape($text) . "');"); var_dump($db->query("SELECT * FROM foo")->fetchAll(PDO::FETCH_ASSOC)); https://3v4l.org/V6Lqt people can't count on SQLite3::escapeString to properly escape their data, have to do weird jumps around it to have it properly escape anything that may include null bytes. while escaping null bytes for sqlite queries \*are\* possible, or so it seems.<|eoopr|><|sor|>Why aren't you using a prepared statement or pdo::quote? Do those also fail? Edit; quote didn't work, prepare did, https://3v4l.org/umFH1<|eor|><|eols|><|endoftext|>
12
lolphp
erig
e9xcmt9
<|sols|><|sot|>C's strlen() ftw<|eot|><|sol|>http://php.net/manual/en/sqlite3.escapestring.php<|eol|><|sor|>Okay....what am I missing?<|eor|><|soopr|>> Warning This function is not (yet) binary safe! >>To properly handle BLOB fields which may contain NUL characters, use SQLite3Stmt::bindParam() instead. <|eoopr|><|sor|>And... what is the connection to strlen of C?<|eor|><|soopr|>it's obviously used to check the length of the input string somewhere. https://3v4l.org/AdMOU<|eoopr|><|sor|>php source: > sqlite3_mprintf("%q", ZSTR_VAL(sql)) sqlite3 source: > %q, %Q: The argument is a zero-terminated string. The string is printed with all single quote (') characters doubled so that the string can safely appear inside an SQL string literal. The %Q substitution type also puts single-quotes on both ends of the substituted string. Seems the only way in sqlite3 at a C API level to deal with binary content is to use prepared statements, which is what the PHP manual suggests anyway.<|eor|><|eols|><|endoftext|>
7
lolphp
shitcanz
8el49p
<|sols|><|sot|>They made fun of PHP, now lets bash node as a retaliation<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8ed9tt/used_php_in_a_hackathon_was_made_fun_of_and_it/<|eol|><|eols|><|endoftext|>
0
lolphp
human_bacon
dxw3tme
<|sols|><|sot|>They made fun of PHP, now lets bash node as a retaliation<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8ed9tt/used_php_in_a_hackathon_was_made_fun_of_and_it/<|eol|><|sor|>As much as I hate PHP, you cannot judge a developer's ability simple because they choose to use a certain tool. I know some very good developers who code in PHP, they can make it sufferable.<|eor|><|eols|><|endoftext|>
30
lolphp
JiminP
dxw5zzl
<|sols|><|sot|>They made fun of PHP, now lets bash node as a retaliation<|eot|><|sol|>https://www.reddit.com/r/PHP/comments/8ed9tt/used_php_in_a_hackathon_was_made_fun_of_and_it/<|eol|><|sor|>TBH IMHO PHP is not a bad language for *quickly prototyping* something, so it is a sensible choice, especially so considering that they are using PHP7.<|eor|><|eols|><|endoftext|>
13
lolphp
polish_niceguy
1yvt2t
<|soss|><|sot|>What's the deal with current php.net logo?<|eot|><|sost|>Is it some internal joke, Don Quijote reference or simply the current status of PHP? [Mirror](http://i.imgur.com/AusAQHR.gif)<|eost|><|eoss|><|endoftext|>
0
lolphp
jamwaffles
1n8rww
<|soss|><|sot|>This is an array. Do stuff with it. No? Fine. Sudo do stuff with it.<|eot|><|sost|>I ran into an interesting little fuck up with PHP's implicit typing today: $iWannaUseThePikey = array( // Look ma, it's an array 'foo' => '1', 'bar' => '2', 'baz' => '3', 'zip' => '1'); // This throws type warnings all over the place - no Timmy, it's not an array $boris = array_count_values($iWannaUseThePikey); // This doesn't. Let's cast the array to an array just to make sure... oh ok now it's an array $avi = array_count_values((array)$iWannaUseThePikey); Here's some real-world data for your enjoyment, just in case you think my data's wrong (from `var_dump()`). Definitely looks like an array to me... array(25) { ["05F06CRD43"]=> string(1) "8" ["05F12RBK43"]=> string(1) "8" ["05F11MUL43"]=> string(1) "8" ["05E42MUL42"]=> < snip > ["05F09FOR32"]=> string(1) "7" ["65Z09MUL43"]=> string(1) "8" ["65Z07BLA44"]=> string(1) "8" }<|eost|><|eoss|><|endoftext|>
0
lolphp
ealf
1mxrwx
<|sols|><|sot|>array_product() returns the product of the values in an array. Guess what it returns if the array is empty.<|eot|><|sol|>http://php.net/array_product<|eol|><|eols|><|endoftext|>
0
lolphp
infinull
ccdlyj6
<|sols|><|sot|>array_product() returns the product of the values in an array. Guess what it returns if the array is empty.<|eot|><|sol|>http://php.net/array_product<|eol|><|sor|>This actually makes perfect sense, for example `product []` in haskell is 1 (see: http://tryhaskell.org/) Product is defined "product" as reduce/fold with an initial value of 1 and an operation of multiply: (in python): def product(xs): return reduce(operator.mul, xs, 1) (in python 3, reduce is no longer builtin and must be imported from itertools) from a mathematical standpoint if `sum([])` (in php `array_sum(array())`) is 0 (true in at least PHP, python and haskell), then `product([])` should be 1 since 1 is the identity value of multiplication and 0 is the identity of addition. PHP has a habit of doing something different for empty arrays or arrays with one value, this is "lol" if only because this is correct.<|eor|><|eols|><|endoftext|>
15
lolphp
smog_alado
ccdlv65
<|sols|><|sot|>array_product() returns the product of the values in an array. Guess what it returns if the array is empty.<|eot|><|sol|>http://php.net/array_product<|eol|><|sor|>Returning 1 as the product of the empty array makes perfect sense to me, since 1 is the neutral element for multiplication. The weird thing is that it used to return 0.<|eor|><|eols|><|endoftext|>
10
lolphp
theatrus
ccdni0t
<|sols|><|sot|>array_product() returns the product of the values in an array. Guess what it returns if the array is empty.<|eot|><|sol|>http://php.net/array_product<|eol|><|sor|>This actually makes perfect sense, for example `product []` in haskell is 1 (see: http://tryhaskell.org/) Product is defined "product" as reduce/fold with an initial value of 1 and an operation of multiply: (in python): def product(xs): return reduce(operator.mul, xs, 1) (in python 3, reduce is no longer builtin and must be imported from itertools) from a mathematical standpoint if `sum([])` (in php `array_sum(array())`) is 0 (true in at least PHP, python and haskell), then `product([])` should be 1 since 1 is the identity value of multiplication and 0 is the identity of addition. PHP has a habit of doing something different for empty arrays or arrays with one value, this is "lol" if only because this is correct.<|eor|><|sor|>It's lol as the function behavior is now different (even though it's better). <|eor|><|eols|><|endoftext|>
9
lolphp
infinull
ccdnewu
<|sols|><|sot|>array_product() returns the product of the values in an array. Guess what it returns if the array is empty.<|eot|><|sol|>http://php.net/array_product<|eol|><|sor|>This actually makes perfect sense, for example `product []` in haskell is 1 (see: http://tryhaskell.org/) Product is defined "product" as reduce/fold with an initial value of 1 and an operation of multiply: (in python): def product(xs): return reduce(operator.mul, xs, 1) (in python 3, reduce is no longer builtin and must be imported from itertools) from a mathematical standpoint if `sum([])` (in php `array_sum(array())`) is 0 (true in at least PHP, python and haskell), then `product([])` should be 1 since 1 is the identity value of multiplication and 0 is the identity of addition. PHP has a habit of doing something different for empty arrays or arrays with one value, this is "lol" if only because this is correct.<|eor|><|sor|>this is not haskell, its real life. so 0.<|eor|><|sor|>That would break all sorts of nice mathematical properties though. For example (back to python) `product(l1 + l2)` should be equal to `product(l1) * product(l2)`. If `product([]) == 0` then this isn't the case. In order to be consistent, `product([])` should be an error or return NULL/None/Nil or return 1.<|eor|><|eols|><|endoftext|>
6
lolphp
IJCQYR
1gekbx
<|sols|><|sot|>Unserialization can result in code being loaded and executed due to object instantiation and autoloading<|eot|><|sol|>http://www.alertlogic.com/writing-exploits-for-exotic-bug-classes/<|eol|><|eols|><|endoftext|>
0
lolphp
kasnalin
cajgqnp
<|sols|><|sot|>Unserialization can result in code being loaded and executed due to object instantiation and autoloading<|eot|><|sol|>http://www.alertlogic.com/writing-exploits-for-exotic-bug-classes/<|eol|><|sor|>Well, yes, if you don't heed the manual's advice and pass untrusted input to `unserialize()`, which can create arbitrary objects, bad things will happen. It's the same with, say, Python's `pickle`.<|eor|><|eols|><|endoftext|>
5
lolphp
Daishiman
kvpea
<|soss|><|sot|>The PDO::quote method is an instance method, so even if you want to create some quoted SQL parameters, you'll have to construct a useless PDO instance.<|eot|><|sost|><|eost|><|eoss|><|endoftext|>
0
lolphp
obi_hoernchen
d0lxng
<|sols|><|sot|>"This is documented behaviour..."<|eot|><|sol|>https://github.com/doctrine/orm/issues/5287<|eol|><|eols|><|endoftext|>
0
lolphp
the_alias_of_andrea
ezaluvf
<|sols|><|sot|>"This is documented behaviour..."<|eot|><|sol|>https://github.com/doctrine/orm/issues/5287<|eol|><|sor|>This isn't PHP the language, just code written in PHP, so not really on-topic.<|eor|><|eols|><|endoftext|>
14
lolphp
obi_hoernchen
ezamvmb
<|sols|><|sot|>"This is documented behaviour..."<|eot|><|sol|>https://github.com/doctrine/orm/issues/5287<|eol|><|sor|>Can someone explain the issue to me? I don't have enough context to know why this is surprising behavior.<|eor|><|soopr|>`Query::iterate()` returns an `IterableResult`, which is an iterator over a collection of entities. `IterableResult::next()` which, in the case of the example code, is called by the `foreach` loop, should return the next entity from the collection or `false` if there are no more elements. However, if there are more elements, instead of just returning the next element, it actually returns an array with the next element at the first index. Not only is this completely nonsensical in this context, but it's also really confusing, as the methods name very much implies that the method will only return a single item.<|eoopr|><|eols|><|endoftext|>
5
lolphp
FreaXoMatic
75o0vb
<|sols|><|sot|>var_dump($test2) = a<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/8a78d479c3c45e2e7e189a5d524ca928054c92d5<|eol|><|eols|><|endoftext|>
0
lolphp
squiggleslash
do7t2io
<|sols|><|sot|>var_dump($test2) = a<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/8a78d479c3c45e2e7e189a5d524ca928054c92d5<|eol|><|soopr|>Can someone explain why $test2 equals to 'a' instead of anything else. Btw, this works only on 5.3 and above. <?php $aest['test'] = "testa"; $test = test; $test2 = aest['test']; var_dump($test); var_dump($test2); var_dump($aest['test']);<|eoopr|><|sor|>syntax error! test and aest are undefined constants. maybe you meant $test and $aest, but even then $test would be undefined in the first occasion<|eor|><|soopr|>I understand that but it doesn't equal to a syntax error. It just uses aest the first letter and i'm trying to find an explanation why it's only the first letter except "lolphp". Even $test = test; is interpreted as filling the $test with a string.<|eoopr|><|sor|>I would assume the process is: $test2 = *aest*\['test'] aest -> undefined constant, so assumed to be "aest" (ie a string) (Yes, PHP *tells* you this: - Notice: Use of undefined constant aest - assumed 'aest' in \[...]\[...] on line 5) So... $test2 = "aest"\['test'] Now, 'test' is treated as an integer because "aest" is a string (not an associative array) and is being indexed. 'test' is not an integer, so PHP changes it to zero (Again, PHP tells you this: Warning: Illegal string offset 'test' in \[...]\[...] on line 5) So... $test2 = "aest"\[0] Which is 'a', because 'a' is the first (0 offset) character of "aest". TBH this is not an LOL. PHP is actually complaining pretty much about every single thing you're doing. It complains that aest is not defined. It complaints that 'test' is not an integer. It outputs garbage because you've given it garbage, but it is actually telling you it's garbage, which is what separates bad behavior from good. <|eor|><|eols|><|endoftext|>
11
lolphp
Almamu
do7tlzs
<|sols|><|sot|>var_dump($test2) = a<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/8a78d479c3c45e2e7e189a5d524ca928054c92d5<|eol|><|soopr|>Can someone explain why $test2 equals to 'a' instead of anything else. Btw, this works only on 5.3 and above. <?php $aest['test'] = "testa"; $test = test; $test2 = aest['test']; var_dump($test); var_dump($test2); var_dump($aest['test']);<|eoopr|><|sor|>The problem is obvious, php is converting aest in this line to a string as the warnings say: $test2 = aest['test'] And 'test', as you're accessing a string (remember aest is converted to string as there is no constant calles aest) is converted to int because how types work in php, which translates to 0. So you get the first character of the string 'aest' which is 'a'. If you change that line to something like: $test2 = aest['2test']; Youll see that it has the value 's'. EDIT: oh I see someone already explained it way better than me hahah, nvm then<|eor|><|eols|><|endoftext|>
5
lolphp
mcosta
5hw6rb
<|sols|><|sot|>Why Rounding Does Not Always Work As Expected<|eot|><|sol|>https://wiki.debian.org/PHP/Rounding<|eol|><|eols|><|endoftext|>
0
lolphp
Deviltry1
db3jgx9
<|sols|><|sot|>Why Rounding Does Not Always Work As Expected<|eot|><|sol|>https://wiki.debian.org/PHP/Rounding<|eol|><|sor|>Why the hell Debian wiki has wiki for PHP?<|eor|><|eols|><|endoftext|>
9
lolphp
carlos_vini
db44sxp
<|sols|><|sot|>Why Rounding Does Not Always Work As Expected<|eot|><|sol|>https://wiki.debian.org/PHP/Rounding<|eol|><|sor|>This example works since PHP 5.2.7: https://3v4l.org/oOAmC. More than 8 years ago.<|eor|><|eols|><|endoftext|>
5
lolphp
jmalloc
1p3xo4
<|sols|><|sot|>PHP considered harmful... by chrome.<|eot|><|sol|>http://i.imgur.com/PooWVpo.png<|eol|><|eols|><|endoftext|>
0
lolphp
geerlingguy
1no3pb
<|sols|><|sot|>Most PHP applications Ive encountered in the wild<|eot|><|sol|>http://hardtickettohomevideo.files.wordpress.com/2012/09/tumblr_m3th8ack7x1qlgjmlo1_1280.png<|eol|><|eols|><|endoftext|>
0
lolphp
RonAtDD
1loc7a
<|sols|><|sot|>This is 3 days old, and nobody has gotten a lol yet? Face::sad()<|eot|><|sol|>http://www.reddit.com/r/PHPhelp/comments/1lgzx2/help_with_my_dic/<|eol|><|eols|><|endoftext|>
0
lolphp
lindy-hop
1k0ms0
<|sols|><|sot|>PHP can't even get the damn' double-claw hammer right.<|eot|><|sol|>http://www.reddit.com/r/whatisthisthing/comments/1jygsd/what_is_this_doubleclawed_hammer_for/<|eol|><|eols|><|endoftext|>
0
lolphp
jamwaffles
1ja3j7
<|sols|><|sot|>Even these people know what's right<|eot|><|sol|>http://www.developerarguments.com/php-vs-anything-else/<|eol|><|eols|><|endoftext|>
0
lolphp
notwhereyouare
1gnl43
<|soss|><|sot|>fun with converting timestamps to readable formation<|eot|><|sost|>So, I'm trying to get php to convert a ungodly timestamp into a readable format. I have the following stuff $originalString = 20130606000000; $readableDate = substr($soar_begin_date,4,2).'-'.substr($soar_begin_date,6,2).'-'.substr($soar_begin_date,0,4); $attemptAtNiceDate = date("F j, Y",strtotime($walkup_date)); The output? 06-06-2013=>1322974800=>December 4, 2011 <|eost|><|eoss|><|endoftext|>
0
lolphp
midir
calxm5h
<|soss|><|sot|>fun with converting timestamps to readable formation<|eot|><|sost|>So, I'm trying to get php to convert a ungodly timestamp into a readable format. I have the following stuff $originalString = 20130606000000; $readableDate = substr($soar_begin_date,4,2).'-'.substr($soar_begin_date,6,2).'-'.substr($soar_begin_date,0,4); $attemptAtNiceDate = date("F j, Y",strtotime($walkup_date)); The output? 06-06-2013=>1322974800=>December 4, 2011 <|eost|><|sor|>1. `$originalString` is actually a double. 2. In a three-line example you refer to two variables that don't exist (`$soar_begin_date` and `$walkup_date`). 3. You're testing with a date where the month and date of month have the same numeric value, so you won't notice if they're reversed. 4. They are reversed. 5. I can't reproduce the one problem you actually complain about: `echo date("F j, Y", strtotime('06-06-2013'));` => `June 6, 2013` 6. strtotime can actually handle that "ungodly timestamp" natively: `echo date("F j, Y", strtotime('20130606000000'));` => `June 6, 2013` I'm guessing you're a bit short on sleep..<|eor|><|eoss|><|endoftext|>
5
lolphp
ezzatron
sdcpp
<|sols|><|sot|>PHP SOAP error message rednecks<|eot|><|sol|>http://qkme.me/3ot67n<|eol|><|eols|><|endoftext|>
0
lolphp
phplovesong
i89p5r
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|eols|><|endoftext|>
0
lolphp
IluTov
g174i3m
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>This has 0 to do with parsing. The reason it fails is because PHP 4 style constructors are deprecated. That is, PHP used to have constructors with the same name as the class instead of the `__construct` keyword. Those were removed from PHP 8, and thus this error also goes away with PHP 8.<|eor|><|eols|><|endoftext|>
22
lolphp
elcapitanoooo
g170lbj
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>This is obviously a "lol developer", but at the same it shows how fragile the php parser actually is. By design the "__construct" should only be "visible" inside the class and not affected by any outside naming. For example (in python): class __init__: msg = '' def __init__(self): self.msg = 'LOL' Is weird, but totally valid and works as intended.<|eor|><|eols|><|endoftext|>
19
lolphp
stfcfanhazz
g19g8ey
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>Why would you name a class __construct?<|eor|><|eols|><|endoftext|>
10
lolphp
Takeoded
g179ebd
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>haha yeah, it matches the signature of both modern php5+ constructors, *AND* the signature of old php4 constructors, PHP7 is unsure which of those it is, and assumes you want a PHP4 constructor.. (even tho it (also) matches the signature of modern php5+ constructors)<|eor|><|eols|><|endoftext|>
8
lolphp
smegnose
g17ek3s
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>It is funny, though I'd bet you any money it's less performant to do an extra `if` to check whether the class name is exactly `__construct` after checking for a PHP4-style constructor method. You're not meant to use reserved words for anything other than their designated purpose, and anything starting with `__` is fair game to PHP devs.<|eor|><|eols|><|endoftext|>
6
lolphp
Altreus
g17l3kv
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>This has 0 to do with parsing. The reason it fails is because PHP 4 style constructors are deprecated. That is, PHP used to have constructors with the same name as the class instead of the `__construct` keyword. Those were removed from PHP 8, and thus this error also goes away with PHP 8.<|eor|><|sor|>Seems like a standard PHP apologist sentiment. Why are people who defend PHP so happy to accept such low standards from the language? It is perfectly acceptable to expect that a modern programming language is capable of enforcing its own rules. If the parser gets confused, if there's any inconsistency, if there's silly behaviour, if the developer has to go to pains to get the system to do what it feels like it should have done by default *that's a problem*. Complaining about this stuff is fine, indeed I encourage it, but only a PHP apologist would dismiss the complaint and tell the developer to git gud. If you're gonna deprecate something, fucking deprecate it, and don't lay it on the developer who tries experiments.<|eor|><|eols|><|endoftext|>
5
lolphp
IluTov
g18j98l
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>This has 0 to do with parsing. The reason it fails is because PHP 4 style constructors are deprecated. That is, PHP used to have constructors with the same name as the class instead of the `__construct` keyword. Those were removed from PHP 8, and thus this error also goes away with PHP 8.<|eor|><|sor|>Well they could have done a better job by checking for new constructors. Now this is in a limbo state, its both old and new. So if __constructor was used assume its new, if classname is used (thats obviously not named __constructor) use old constructor.<|eor|><|sor|>They could've. Maybe nobody thought of it, maybe they chose not to to avoid an additional runtime check for something you shouldn't be doing anyway. Either way, I'm not hesitant to admit there are many things PHP got wrong but this is not one of those cases.<|eor|><|eols|><|endoftext|>
5
lolphp
cosmicsans
g17of17
<|sols|><|sot|>PHP parser gets confused<|eot|><|sol|>https://repl.it/repls/WelloffWeirdGlobalarrays<|eol|><|sor|>This has 0 to do with parsing. The reason it fails is because PHP 4 style constructors are deprecated. That is, PHP used to have constructors with the same name as the class instead of the `__construct` keyword. Those were removed from PHP 8, and thus this error also goes away with PHP 8.<|eor|><|sor|>Seems like a standard PHP apologist sentiment. Why are people who defend PHP so happy to accept such low standards from the language? It is perfectly acceptable to expect that a modern programming language is capable of enforcing its own rules. If the parser gets confused, if there's any inconsistency, if there's silly behaviour, if the developer has to go to pains to get the system to do what it feels like it should have done by default *that's a problem*. Complaining about this stuff is fine, indeed I encourage it, but only a PHP apologist would dismiss the complaint and tell the developer to git gud. If you're gonna deprecate something, fucking deprecate it, and don't lay it on the developer who tries experiments.<|eor|><|sor|>There are two types of programming languages: 1. Programming Languages that people complain about. 2. Programming Languages that nobody uses.<|eor|><|sor|>Much like consumerism, everything is made cheaply and doesn't last and people complain but buy it anyway<|eor|><|sor|>> and people complain but buy it anyway I want to state that the tone of this question is not argumentative, but should be read in a soft voice as a genuine question: What other option is there? When everything's made as cheap as possible in a race to the bottom what option do we as consumers have?<|eor|><|eols|><|endoftext|>
5
lolphp
Jinxuan
ej4q3c
<|soss|><|sot|>new statement cannot parse with parenthesis<|eot|><|sost|>This code works: ``` class A {} $a = 'A'; new $a; // Return a new instance ofA ``` However, if we add a parenthesis, then it cannot be parsed: ``` class A {} $a = 'A'; new ($a); //PHP Parse error: syntax error, unexpected '(' new 'A'; // PHP Parse error: syntax error, unexpected ''A'' (T\_CONSTANT\_ENCAPSED\_STRING) new A::class; // PHP Parse error: syntax error, unexpected 'class' (T\_CLASS), expecting variable ```<|eost|><|eoss|><|endoftext|>
0
lolphp
squiggleslash
fcwjbmc
<|soss|><|sot|>new statement cannot parse with parenthesis<|eot|><|sost|>This code works: ``` class A {} $a = 'A'; new $a; // Return a new instance ofA ``` However, if we add a parenthesis, then it cannot be parsed: ``` class A {} $a = 'A'; new ($a); //PHP Parse error: syntax error, unexpected '(' new 'A'; // PHP Parse error: syntax error, unexpected ''A'' (T\_CONSTANT\_ENCAPSED\_STRING) new A::class; // PHP Parse error: syntax error, unexpected 'class' (T\_CLASS), expecting variable ```<|eost|><|sor|>Not sure this counts as an LOL. Would "new (A)" work? Because if not, then it seems consistent, new is supposed to be followed by the identifier. The fact PHP allows you to instead specify a variable is a feature, but that doesn't imply it's letting you use an expression, as your subsequent examples (new 'A', etc) show. Languages generally only allow parentheses when they're expecting an expression. In this case PHP isn't expecting one. I'm not even sure I want PHP to allow an expression to be specified as 'new' would then need a priority like other operators, and, well, it's PHP, do you really think "new 'handler\_class\_' . get_object_type($something)" is going to be parsed the way you think it would be?<|eor|><|eoss|><|endoftext|>
7
lolphp
LennyZoid
7gnhan
<|soss|><|sot|>Question about PHP...<|eot|><|sost|>1.Why people hate PHP? 2.What are your thoughts on Node.js 3.Why "PYTHON" btw?<|eost|><|eoss|><|endoftext|>
0
lolphp
xiongchiamiov
dqkn5e0
<|soss|><|sot|>Question about PHP...<|eot|><|sost|>1.Why people hate PHP? 2.What are your thoughts on Node.js 3.Why "PYTHON" btw?<|eost|><|sor|>This isn't really a PHP discussion forum, but 1. PHP has grown organically, rather than being designed, and as such has a whole bunch of warts. The past five years new people have gotten involved who have improved it a lot, but there's still a lot to do. 1. It's fine for small little servers, but JavaScript as an ecosystem needs a lot of maturing before I want to deal with it. 1. Python is easy for beginners, has libraries for everything, has tons of community support, and is carefully designed such that it's *less* bad than many other options, while also being mature enough to use for production stuff. It is not perfect, nor is it the best solution for every case.<|eor|><|eoss|><|endoftext|>
8
lolphp
marcini82
dqsnexr
<|soss|><|sot|>Question about PHP...<|eot|><|sost|>1.Why people hate PHP? 2.What are your thoughts on Node.js 3.Why "PYTHON" btw?<|eost|><|sor|>I know it's a lolphp subreddit and if you read it, you might think that php is the worst programming language that ever exist and all php programmers hate it, but in fact reality isn't that black and white. All languages have it's advantages and disadvantages. JavaScript - I know several programmers who hate it because of lack of basic features known from other languages, its rapid changes in community standards, which make it difficult to maintain project in long term, incompatibility between next versions of libraries, where nobody cares about backwards compatibility etc. PHP - has its quirks, you can tell it's stupid, but in the end it does its job. And it's not the same language as a few years ago. PHP7 is a big improvement. Python - it's a matter of taste, but some people used to languages which use brackets, may not feel comfortable with it's syntax.<|eor|><|eoss|><|endoftext|>
5
lolphp
sickjobpeople
3vspsb
<|sols|><|sot|>A proposed CACHE standard. Because caching should always be this convoluted.<|eot|><|sol|>https://github.com/php-fig/fig-standards/blob/eb3e9edab3adc754ae9aace2d113fc175a359334/proposed/cache.md<|eol|><|eols|><|endoftext|>
0
lolphp
computerfreak97
cxqbi43
<|sols|><|sot|>A proposed CACHE standard. Because caching should always be this convoluted.<|eot|><|sol|>https://github.com/php-fig/fig-standards/blob/eb3e9edab3adc754ae9aace2d113fc175a359334/proposed/cache.md<|eol|><|sor|>This really isn't that convoluted...<|eor|><|eols|><|endoftext|>
13
lolphp
Sheepshow
cxqi7d7
<|sols|><|sot|>A proposed CACHE standard. Because caching should always be this convoluted.<|eot|><|sol|>https://github.com/php-fig/fig-standards/blob/eb3e9edab3adc754ae9aace2d113fc175a359334/proposed/cache.md<|eol|><|sor|> public function isHit(); Small typo there. Should be public function iShit();<|eor|><|eols|><|endoftext|>
10
lolphp
iopq
1k9mvw
<|soss|><|sot|>round() doesn't actually round<|eot|><|sost|>I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like `18.799999999999` apparently, someone used `round($amount, 2)` and expected PHP to actually round the number to two digits For certain float values that just doesn't work. I found an example like this: echo round(-0.07, 2); //-0.07000000000000001 this is what happens when your precision is set to 17 of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity<|eost|><|eoss|><|endoftext|>
0
lolphp
mirhagk
cbmtygx
<|soss|><|sot|>round() doesn't actually round<|eot|><|sost|>I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like `18.799999999999` apparently, someone used `round($amount, 2)` and expected PHP to actually round the number to two digits For certain float values that just doesn't work. I found an example like this: echo round(-0.07, 2); //-0.07000000000000001 this is what happens when your precision is set to 17 of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity<|eost|><|sor|>If you truly want to round to 2 digits in any langauge, you must use an integer and treat the last 2 as decimal places. Or better yet use a decimal/money type that is made to work with base 10 numbers and actually can store floating point numbers rounded to 2 digits. I'm really scared that you're writing a payment system and don't know about floating point errors. I'm also scared that you're not doing the payment system in a database langauge where concurrency and transactions have already been solved, and you won't leave the database in an inconsistent state.<|eor|><|eoss|><|endoftext|>
18
lolphp
ioctl79
cbmtyq3
<|soss|><|sot|>round() doesn't actually round<|eot|><|sost|>I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like `18.799999999999` apparently, someone used `round($amount, 2)` and expected PHP to actually round the number to two digits For certain float values that just doesn't work. I found an example like this: echo round(-0.07, 2); //-0.07000000000000001 this is what happens when your precision is set to 17 of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity<|eost|><|sor|>This is why you don't use floats for monetary values, regardless of language. Store an integer number of pennies, or better yet, wrap your integer number of pennies in an object that does conversions, calculations, and formatting.<|eor|><|eoss|><|endoftext|>
15
lolphp
midir
cbmsjkn
<|soss|><|sot|>round() doesn't actually round<|eot|><|sost|>I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like `18.799999999999` apparently, someone used `round($amount, 2)` and expected PHP to actually round the number to two digits For certain float values that just doesn't work. I found an example like this: echo round(-0.07, 2); //-0.07000000000000001 this is what happens when your precision is set to 17 of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity<|eost|><|sor|>It's not PHP's fault -- all contemporary languages use the same floating-point types. PHP gives you the [precision](http://php.net/manual/en/ini.core.php#ini.precision) setting so you can work around the floating-point limitations for simple display needs, but no, the numbers won't ever quite "add up". 0.07 is not a number that a binary floating-point type can exactly represent, any more than decimal can exactly represent . See http://floating-point-gui.de/<|eor|><|eoss|><|endoftext|>
5
lolphp
midir
cbmvbew
<|soss|><|sot|>round() doesn't actually round<|eot|><|sost|>I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like `18.799999999999` apparently, someone used `round($amount, 2)` and expected PHP to actually round the number to two digits For certain float values that just doesn't work. I found an example like this: echo round(-0.07, 2); //-0.07000000000000001 this is what happens when your precision is set to 17 of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity<|eost|><|sor|>It's not PHP's fault -- all contemporary languages use the same floating-point types. PHP gives you the [precision](http://php.net/manual/en/ini.core.php#ini.precision) setting so you can work around the floating-point limitations for simple display needs, but no, the numbers won't ever quite "add up". 0.07 is not a number that a binary floating-point type can exactly represent, any more than decimal can exactly represent . See http://floating-point-gui.de/<|eor|><|sor|>It's PHP fault, we aren't talking about a low level language, python gets it right.<|eor|><|sor|>[No it doesn't.](http://docs.python.org/2/tutorial/floatingpoint.html)<|eor|><|eoss|><|endoftext|>
5
lolphp
sclv
18e5ny
<|sols|><|sot|>PHP versus PCP<|eot|><|sol|>http://www.dadhacker.com/blog/?p=1914<|eol|><|eols|><|endoftext|>
0
lolphp
Takeoded
kdluto
<|sols|><|sot|>how to do async queries in PDO<|eot|><|sol|>https://gist.github.com/divinity76/adcf1526d3e6a536fda20fdb1dd86339<|eol|><|eols|><|endoftext|>
0
lolphp
sproingie
gfy0e6u
<|sols|><|sot|>how to do async queries in PDO<|eot|><|sol|>https://gist.github.com/divinity76/adcf1526d3e6a536fda20fdb1dd86339<|eol|><|sor|>echoing code to be eval'd on the command line seems a little silly when `pcntl_fork` is a thing. But yes, PDO needs async suppport.<|eor|><|eols|><|endoftext|>
11
lolphp
duskwuff
gfxwu6b
<|sols|><|sot|>how to do async queries in PDO<|eot|><|sol|>https://gist.github.com/divinity76/adcf1526d3e6a536fda20fdb1dd86339<|eol|><|sor|>1. The overhead of launching a subprocess, connecting to the database, and serializing/deserializing the query and results negates virtually all of the benefits of an asynchronous database interface. 2. Any query which returns a large result will cause the child process to block while writing to stdout, causing it to never exit.<|eor|><|eols|><|endoftext|>
11
lolphp
lankybiker
gfz2ykm
<|sols|><|sot|>how to do async queries in PDO<|eot|><|sol|>https://gist.github.com/divinity76/adcf1526d3e6a536fda20fdb1dd86339<|eol|><|sor|>Creative solution But why not use mysqli? Are you targeting another dB type?<|eor|><|eols|><|endoftext|>
5
lolphp
nyamsprod
8f0wan
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|eols|><|endoftext|>
0
lolphp
Diiix
dxzvoba
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|sor|>>I'm using an undocumented API and experiencing unexpected behaviour Wow that's really interesting, please tell me more.<|eor|><|eols|><|endoftext|>
29
lolphp
Diiix
dxzxbmu
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|sor|>>I'm using an undocumented API and experiencing unexpected behaviour Wow that's really interesting, please tell me more.<|eor|><|soopr|>If an undocumented API leads to bugs then hell yeah that's a problem. * Should we be able de loop over a `DateTime` object IMHO no. * Should we be able to use a `DateTime` object with `http_build_query` no.. but thanks to undocumented properties **made** public now you can [https://3v4l.org/MGC4X](https://3v4l.org/MGC4X) . Undocumented or not those properties should at least it follow basic OOP expectations.<|eoopr|><|sor|>That's pretty rich coming from someone who thinks [documentation justifies actual bugs in their own code](https://github.com/thephpleague/csv/issues/256), but not when it applies to someone elses code.<|eor|><|eols|><|endoftext|>
19
lolphp
Diiix
dy0029v
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|sor|>>I'm using an undocumented API and experiencing unexpected behaviour Wow that's really interesting, please tell me more.<|eor|><|soopr|>If an undocumented API leads to bugs then hell yeah that's a problem. * Should we be able de loop over a `DateTime` object IMHO no. * Should we be able to use a `DateTime` object with `http_build_query` no.. but thanks to undocumented properties **made** public now you can [https://3v4l.org/MGC4X](https://3v4l.org/MGC4X) . Undocumented or not those properties should at least it follow basic OOP expectations.<|eoopr|><|sor|>That's pretty rich coming from someone who thinks [documentation justifies actual bugs in their own code](https://github.com/thephpleague/csv/issues/256), but not when it applies to someone elses code.<|eor|><|soopr|>Sorry but using comments and thread out of context is not the best way to engage in a discussion my 2 cents.<|eoopr|><|sor|>What context is missing? The entire discussion is right there.<|eor|><|soopr|>Well you should improve your [detective skills a little bit then](https://github.com/thephpleague/csv/pull/285) and try to stay on topic when you disagree with someone.<|eoopr|><|sor|>I have no idea how that is even relevant, but whatever took place there took place *six months later*, thanks to *someone else*. *Your* stance for *your* project stood, for at least six months, that documentation justifies bugs, and you made no attempt to fix it yourself. Your attitude on your projects has always been to close issues as fast as possible, with or without any resolution, to make it look like there are no problems with any of your projects - when in fact - nothing could be further from the truth.<|eor|><|eols|><|endoftext|>
14
lolphp
Diiix
dxzyg1r
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|sor|>>I'm using an undocumented API and experiencing unexpected behaviour Wow that's really interesting, please tell me more.<|eor|><|soopr|>If an undocumented API leads to bugs then hell yeah that's a problem. * Should we be able de loop over a `DateTime` object IMHO no. * Should we be able to use a `DateTime` object with `http_build_query` no.. but thanks to undocumented properties **made** public now you can [https://3v4l.org/MGC4X](https://3v4l.org/MGC4X) . Undocumented or not those properties should at least it follow basic OOP expectations.<|eoopr|><|sor|>That's pretty rich coming from someone who thinks [documentation justifies actual bugs in their own code](https://github.com/thephpleague/csv/issues/256), but not when it applies to someone elses code.<|eor|><|soopr|>Sorry but using comments and thread out of context is not the best way to engage in a discussion my 2 cents.<|eoopr|><|sor|>What context is missing? The entire discussion is right there.<|eor|><|eols|><|endoftext|>
13
lolphp
mstx
dxzrrhs
<|sols|><|sot|>DateTime hidden public properties behaviour<|eot|><|sol|>https://3v4l.org/mWluN<|eol|><|sor|>Just because a property is public doesn't necessarily mean you can change it to whatever you want. <|eor|><|eols|><|endoftext|>
7
lolphp
doubtfulwager
81omom
<|soss|><|sot|>PHP operations on different data types<|eot|><|sost|>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<|eost|><|eoss|><|endoftext|>
0
lolphp
doubtfulwager
dv4847j
<|soss|><|sot|>PHP operations on different data types<|eot|><|sost|>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<|eost|><|sor|>[removed]<|eor|><|soopr|>No need to be mad.<|eoopr|><|eoss|><|endoftext|>
8
lolphp
Oeldin1234
80ebsn
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|eols|><|endoftext|>
0
lolphp
Oeldin1234
duuvxgj
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|soopr|>You could argue that Strings are true per definition, but then, why are "" and "0" false?<|eoopr|><|eols|><|endoftext|>
17
lolphp
Razakel
duuzih4
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|soopr|>You could argue that Strings are true per definition, but then, why are "" and "0" false?<|eoopr|><|sor|>PHP isn't a strongly-typed language unless you're using OOP, and even then primitive fields are still weakly-typed. In a C-style string "" = 0x00 "0" gets coerced to an integer first. So both are zero-valued, then coerced to a boolean, equalling false.<|eor|><|eols|><|endoftext|>
12
lolphp
squiggleslash
duwh1js
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|sor|>I'll allow it. While technically It's Documented(tm) a reasonable programmer would expect a function that accepts a string whose name implies it'll convert it to a boolean to accept strings like "true" and "false", especially as the function, as actually implemented, has no reason to exist (both (x)==true and (bool)(x) do exactly the same thing as the actual function. This is a classic double claw "hammer" LOL. <|eor|><|eols|><|endoftext|>
6
lolphp
barubary
duwzrq4
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|soopr|>You could argue that Strings are true per definition, but then, why are "" and "0" false?<|eoopr|><|sor|>I don't get this. Why would you expect the string `"false"` to be `false`?<|eor|><|eols|><|endoftext|>
6
lolphp
guy99882
dv61ar6
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|soopr|>You could argue that Strings are true per definition, but then, why are "" and "0" false?<|eoopr|><|sor|>PHP isn't a strongly-typed language unless you're using OOP, and even then primitive fields are still weakly-typed. In a C-style string "" = 0x00 "0" gets coerced to an integer first. So both are zero-valued, then coerced to a boolean, equalling false.<|eor|><|sor|>> In a C-style string "" = 0x00 No, the first char in `""` is a NUL byte though. char a[] = ""; printf("%p: %c\n", a, *a); // 0xdeadbeef: 0<|eor|><|sor|>And what exactly is a NUL byte if not 0x00?<|eor|><|eols|><|endoftext|>
5
lolphp
barubary
duxmtuv
<|sols|><|sot|>"false" is definitely true<|eot|><|sol|>http://sandbox.onlinephpfunctions.com/code/490635ed9830900ebf50e5303b7271dcf2a5d692<|eol|><|soopr|>You could argue that Strings are true per definition, but then, why are "" and "0" false?<|eoopr|><|sor|>I don't get this. Why would you expect the string `"false"` to be `false`?<|eor|><|soopr|>Because I expect a function called boolval, to try to find the best matching boolean for anything I pass it. > <|eoopr|><|sor|>Eh? Would you expect `if ($foo)` and `if (boolval($foo))` to behave differently?<|eor|><|eols|><|endoftext|>
5
lolphp
iftpadfs
5nea9e
<|sols|><|sot|>Wikipedia<|eot|><|sol|>https://imgur.com/a/eZDyR<|eol|><|eols|><|endoftext|>
0
lolphp
dotted
dcb4tfp
<|sols|><|sot|>Wikipedia<|eot|><|sol|>https://imgur.com/a/eZDyR<|eol|><|sor|>not really lolphp<|eor|><|eols|><|endoftext|>
13
lolphp
iftpadfs
dcaslt6
<|sols|><|sot|>Wikipedia<|eot|><|sol|>https://imgur.com/a/eZDyR<|eol|><|soopr|>They joys of non type safe programming.<|eoopr|><|eols|><|endoftext|>
8
lolphp
the_alias_of_andrea
410xuq
<|soss|><|sot|>Does anyone else think PHP can become the next Apple?<|eot|><|sost|>https://www.reddit.com/r/PHP/comments/40ziuk/does_anyone_else_think_php_can_become_the_next/<|eost|><|eoss|><|endoftext|>
0
lolphp
catcradle5
cyyz2uo
<|soss|><|sot|>Does anyone else think PHP can become the next Apple?<|eot|><|sost|>https://www.reddit.com/r/PHP/comments/40ziuk/does_anyone_else_think_php_can_become_the_next/<|eost|><|sor|>I mean, that's clearly satirical Nobody is taking this seriously<|eor|><|soopr|>Poe's law.<|eoopr|><|sor|>You can't use Poe's law as a blanket excuse for not getting blatant sarcasm. >php is exploding at an alarming rate >PHP is becoming as popular as tech giants such as Apple and Microsoft >I thought this was really exciting as I have never heard of a language going public before but I was pretty excited and later spoke to my wife about investing some of our savings into PHP. >a function that will boot up a vagrant box and perform all the necessary dependency injections, continuous integration, unit testing etc and be ready to scaffold frameworks out of the box. maybe >function vagrant(Array $arguments)<|eor|><|eoss|><|endoftext|>
12
lolphp
cube-drone
cyyrvss
<|soss|><|sot|>Does anyone else think PHP can become the next Apple?<|eot|><|sost|>https://www.reddit.com/r/PHP/comments/40ziuk/does_anyone_else_think_php_can_become_the_next/<|eost|><|sor|>I mean, that's clearly satirical Nobody is taking this seriously<|eor|><|eoss|><|endoftext|>
11
lolphp
myaut
cyz1aio
<|soss|><|sot|>Does anyone else think PHP can become the next Apple?<|eot|><|sost|>https://www.reddit.com/r/PHP/comments/40ziuk/does_anyone_else_think_php_can_become_the_next/<|eost|><|sor|>Judging by amount of holy wars around PHP, it is clearly an "Apple of Discord".<|eor|><|eoss|><|endoftext|>
9
lolphp
Zenmaster13
3tknqt
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|eols|><|endoftext|>
0
lolphp
the_alias_of_andrea
cx6yqnk
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>implode() is a function for making an array of strings into a single string with separators. If you give it an array with elements that aren't strings, they're converted to strings. This appears to use PHP's normal conversion rules. There's nothing wrong with implode() itself.<|eor|><|eols|><|endoftext|>
43
lolphp
philsown
cx7dbkz
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>In PHP, 1 and '' are the string representations of booleans, so it's not that crazy.<|eor|><|eols|><|endoftext|>
17
lolphp
thenickdude
cx79c2b
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>Why would you even want to call implode on an array of booleans?<|eor|><|eols|><|endoftext|>
13
lolphp
Fahkfahkfahkfahkfahk
cx7kmn6
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>>implode() can, for historical reasons, accept its parameters in either order. <|eor|><|eols|><|endoftext|>
9
lolphp
badmonkey0001
cx86e2f
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>>implode() can, for historical reasons, accept its parameters in either order. <|eor|><|sor|>Yet for things like jQuery, that's acceptable sugar to many folks.<|eor|><|sor|>jQuery? It's 2015, not 2008, who the hell still uses jQuery?..<|eor|><|sor|>Over [60%](http://w3techs.com/technologies/details/js-jquery/1/all) of websites including the one you're looking at now.<|eor|><|eols|><|endoftext|>
8
lolphp
olsner
cx74k1r
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>implode() is a function for making an array of strings into a single string with separators. If you give it an array with elements that aren't strings, they're converted to strings. This appears to use PHP's normal conversion rules. There's nothing wrong with implode() itself.<|eor|><|sor|>Huh, that actually makes sense (except for the conversion stuff, but if it's going to output a string of course it has to do that).<|eor|><|eols|><|endoftext|>
7
lolphp
Fahkfahkfahkfahkfahk
cx81w4t
<|sols|><|sot|>Using implode() on an array of booleans will cast TRUE to 1 and FALSE to ''<|eot|><|sol|>http://php.net/manual/en/function.implode.php<|eol|><|sor|>>implode() can, for historical reasons, accept its parameters in either order. <|eor|><|sor|>Yet for things like jQuery, that's acceptable sugar to many folks.<|eor|><|sor|>That's why I don't let JavaScript programmer's decide what is and isn't acceptable. Gimme strong types!<|eor|><|eols|><|endoftext|>
6
lolphp
luminairex
zjqvc
<|sols|><|sot|>"!==" and "==!" are both valid syntax and compare entirely different things. <|eot|><|sol|>http://stackoverflow.com/questions/12313423/difference-between-and<|eol|><|eols|><|endoftext|>
0
lolphp
fragglet
c65d37y
<|sols|><|sot|>"!==" and "==!" are both valid syntax and compare entirely different things. <|eot|><|sol|>http://stackoverflow.com/questions/12313423/difference-between-and<|eol|><|sor|>Not a WTF; someone simply failed to understand the syntax.<|eor|><|eols|><|endoftext|>
5
lolphp
reddituser11111
21gk55
<|sols|><|sot|>PHP closing tag? Who needs it!<|eot|><|sol|>https://www.google.com/search?q=php+closing+tag&oq=php+closing+tag&aqs=chrome..69i57j0l5.1405j0j7&sourceid=chrome&espv=210&es_sm=119&ie=UTF-8#q=php+closing+tag+best+practices<|eol|><|eols|><|endoftext|>
0
lolphp
huf
cgcth0f
<|sols|><|sot|>PHP closing tag? Who needs it!<|eot|><|sol|>https://www.google.com/search?q=php+closing+tag&oq=php+closing+tag&aqs=chrome..69i57j0l5.1405j0j7&sourceid=chrome&espv=210&es_sm=119&ie=UTF-8#q=php+closing+tag+best+practices<|eol|><|sor|>uhm, yes? and? do you really want to spend hours hunting for that one file that had some trash after the closing tag? the fact that an opening tag is needed *is* a lolphp. being able to omit the closing tag is nice.<|eor|><|eols|><|endoftext|>
24
lolphp
n1c0_ds
cgcw732
<|sols|><|sot|>PHP closing tag? Who needs it!<|eot|><|sol|>https://www.google.com/search?q=php+closing+tag&oq=php+closing+tag&aqs=chrome..69i57j0l5.1405j0j7&sourceid=chrome&espv=210&es_sm=119&ie=UTF-8#q=php+closing+tag+best+practices<|eol|><|sor|>uhm, yes? and? do you really want to spend hours hunting for that one file that had some trash after the closing tag? the fact that an opening tag is needed *is* a lolphp. being able to omit the closing tag is nice.<|eor|><|sor|>Completely agreed. Of all the things to pick, this one is fine.<|eor|><|eols|><|endoftext|>
5
lolphp
allthediamonds
20pnkr
<|soss|><|sot|>You know Rasmus Lerdorf's famous quote about restarting Apache every 10 requests? It's an actual setting on PHP-FPM.<|eot|><|sost|>> ; The number of requests each child process should execute before respawning. > ; This can be useful to work around memory leaks in 3rd party libraries. For > ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. > ; Default Value: 0 > ;pm.max_requests = 500 Oh, PHP, you never disappoint.<|eost|><|eoss|><|endoftext|>
0
lolphp
bart2019
cg5jt50
<|soss|><|sot|>You know Rasmus Lerdorf's famous quote about restarting Apache every 10 requests? It's an actual setting on PHP-FPM.<|eot|><|sost|>> ; The number of requests each child process should execute before respawning. > ; This can be useful to work around memory leaks in 3rd party libraries. For > ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. > ; Default Value: 0 > ;pm.max_requests = 500 Oh, PHP, you never disappoint.<|eost|><|sor|>It's not to restart Apache, but the PHP (F)CGI child process.<|eor|><|eoss|><|endoftext|>
8
lolphp
Twirrim
cg5l65s
<|soss|><|sot|>You know Rasmus Lerdorf's famous quote about restarting Apache every 10 requests? It's an actual setting on PHP-FPM.<|eot|><|sost|>> ; The number of requests each child process should execute before respawning. > ; This can be useful to work around memory leaks in 3rd party libraries. For > ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. > ; Default Value: 0 > ;pm.max_requests = 500 Oh, PHP, you never disappoint.<|eost|><|sor|>I imagine it helps avoid dealing with memory leaks. With no JIT to worry about, and systems caching, it probably doesn't present much of a performance hit. nscd, which I have a love/hate relationship with includes a paranoia config option to force it to routinely restart itself http://man7.org/linux/man-pages/man5/nscd.conf.5.html<|eor|><|eoss|><|endoftext|>
8
lolphp
allthediamonds
cg5lx3z
<|soss|><|sot|>You know Rasmus Lerdorf's famous quote about restarting Apache every 10 requests? It's an actual setting on PHP-FPM.<|eot|><|sost|>> ; The number of requests each child process should execute before respawning. > ; This can be useful to work around memory leaks in 3rd party libraries. For > ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. > ; Default Value: 0 > ;pm.max_requests = 500 Oh, PHP, you never disappoint.<|eost|><|sor|>It's not to restart Apache, but the PHP (F)CGI child process.<|eor|><|soopr|>I know it doesn't restart Apache, but it's its PHP equivalent.<|eoopr|><|eoss|><|endoftext|>
5
lolphp
yousai
1qdi2w
<|sols|><|sot|>My current pet peeve with PHP<|eot|><|sol|>http://i.imgur.com/vjQ0kS6.png<|eol|><|eols|><|endoftext|>
0
lolphp
phper1
197qzb
<|sols|><|sot|>[WebComic] Lots of PHP Frameworks<|eot|><|sol|>http://comics.knreddy.com/?p=php-fx<|eol|><|eols|><|endoftext|>
0