subreddit
stringclasses 7
values | author
stringlengths 3
20
| id
stringlengths 5
7
| content
stringlengths 67
30.4k
| score
int64 0
140k
|
---|---|---|---|---|
lolphp | simukis | rmaxq | <|sols|><|sot|>Float comparison<|eot|><|sol|>http://codepad.org/GJ7YoH0G<|eol|><|eols|><|endoftext|> | 0 |
lolphp | Takeoded | ovp71b | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|eols|><|endoftext|> | 0 |
lolphp | 99999999977prime | h7ayjm2 | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | chucker23n | h7ayukg | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|sor|>Shouldnt there be a not supported warning on serialization, then?<|eor|><|eols|><|endoftext|> | 14 |
lolphp | rbmichael | h7cd877 | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|sor|>Shouldnt there be a not supported warning on serialization, then?<|eor|><|sor|>That's the real "lol" here. If unserializing a DOMDocument has no hope of working, PHP should definitely Fatal error at the moment of serialization.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | chucker23n | h7b04yx | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|sor|>Shouldnt there be a not supported warning on serialization, then?<|eor|><|sor|>Knowing whether an object is built-in or user-defined is left as education for the developer.<|eor|><|sor|>So is knowing whether an API is safe to call, apparently. (No, asking devs to read the docs for every single function they call is not reasonable.)<|eor|><|eols|><|endoftext|> | 7 |
lolphp | GoTriggerYourself | h7fn6aj | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|soopr|>>You can never serialize internal classes
Not true.
```
<?php
$dt=new DateTime("2020-01-01",timezone_open("UTC"));
$s=serialize($dt);
echo $s;
?>
```
serializes to
```
O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}
```<|eoopr|><|sor|>> There are some historical exceptions to the above rule,<|eor|><|sor|>> You can never serialize internal classes<|eor|><|sor|>I don't make the rules.<|eor|><|sor|>But a big problem here shines through in your comment. If you start out with a statement X is always true and I was looking for cases when X is false to make sure my code works, then why would I keep reading? Later on you write Sometimes X is false, but I would have no reason to read that. Now, if my code depends on X being true, that problem originated from bad documentation, not from me not reading further after the statement X is always true.
Clarity matters. That is why documentation is important, and that is why functions should raise errors on bad inputs instead of doing weird and unexpected shit, even if that weird and unexpected shit is clearly defined in the documentation. This post is not very exiting, but arguably fits in r/LolPHP.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | chucker23n | h7bx73x | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|sor|>Shouldnt there be a not supported warning on serialization, then?<|eor|><|sor|>Knowing whether an object is built-in or user-defined is left as education for the developer.<|eor|><|sor|>So is knowing whether an API is safe to call, apparently. (No, asking devs to read the docs for every single function they call is not reasonable.)<|eor|><|sor|>>So is knowing whether an API is safe to call
Just like clicking a [random link] (https://youtu.be/QZShA_a-5r8) on the internet.<|eor|><|sor|>https://i.imgur.com/IjSafwa.jpg
Good tools prevent this sort of problem.<|eor|><|sor|>The same can be applied here, good tools can prevent these issues if you, somehow, miss them ;)<|eor|><|sor|>Good tool: an API that detects its being used inappropriately and shows a warning.
Even better tool: an IDE that detects this as youre writing the code.
Bad tool: a language that just shrugs.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | GoTriggerYourself | h7e7k84 | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>You can never serialize internal classes, only user defined classes. There is no lol here.
> Note:
Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the[Serializable](https://www.php.net/manual/en/class.serializable.php)interface or the magic[__serialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.serialize)/[__unserialize()](https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize)or[__sleep()](https://www.php.net/manual/en/language.oop5.magic.php#object.sleep)/[__wakeup()](https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup)methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized.
There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods.<|eor|><|soopr|>>You can never serialize internal classes
Not true.
```
<?php
$dt=new DateTime("2020-01-01",timezone_open("UTC"));
$s=serialize($dt);
echo $s;
?>
```
serializes to
```
O:8:"DateTime":3:{s:4:"date";s:26:"2020-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}
```<|eoopr|><|sor|>> There are some historical exceptions to the above rule,<|eor|><|sor|>> You can never serialize internal classes<|eor|><|eols|><|endoftext|> | 5 |
lolphp | chucker23n | h7bz1js | <|sols|><|sot|>DOMDocument + serialize()<|eot|><|sol|>https://3v4l.org/sCc8G<|eol|><|sor|>Knowing whether an object is built-in or user-defined is left as education for the developer.<|eor|><|sor|>So is knowing whether an API is safe to call, apparently. (No, asking devs to read the docs for every single function they call is not reasonable.)<|eor|><|sor|>>So is knowing whether an API is safe to call
Just like clicking a [random link] (https://youtu.be/QZShA_a-5r8) on the internet.<|eor|><|sor|>https://i.imgur.com/IjSafwa.jpg
Good tools prevent this sort of problem.<|eor|><|sor|>The same can be applied here, good tools can prevent these issues if you, somehow, miss them ;)<|eor|><|sor|>Good tool: an API that detects its being used inappropriately and shows a warning.
Even better tool: an IDE that detects this as youre writing the code.
Bad tool: a language that just shrugs.<|eor|><|sor|>> Even better tool: an IDE that detects this as youre writing the code.
You gave yourself the answer here buddy. The language has this properly documented and warned. IDEs should detect and warn you about this (or at least static analyzer tools like phpstan). You can't just use something without taking into account side-effects and drawbacks, and you should be aware of those at any time.<|eor|><|sor|>To be clear, I find this particular example overblown.
That said:
> You cant just use something without taking into account side-effects and drawbacks
Again, I dont think its practical of all APIs to expect devs to read the entire docs before starting to use them.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | phplovesong | b0yboc | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | colshrapnel | eihxvwl | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>"I am trying to access an array key that doesn't exist. It is stupid PHP to blame!" <|eor|><|eoss|><|endoftext|> | 25 |
lolphp | jesseschalken | eii3bnl | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>"I am trying to access an array key that doesn't exist. It is stupid PHP to blame!" <|eor|><|soopr|>Its not about "an access key" list\[0\] should return the item in that position. PHP does this when the array contains only simple values, but PHP changes behaviour when the array contains key/val pairs.
To demonstrate:
​
$list = \['a', 'b', 'c'\];
$list\[0\] => 'a'
​
$list2 = \['a' => 'data', 'b' => 'data2', 'c' => 'data3'\];
$list2\[0\] => \['a' => data'\]
​<|eoopr|><|sor|>In terms of their API, PHP arrays are *always* maps/dictionaries. `['a', 'b', 'c']` is just shorthand for `[0 => 'a', 1 => 'b', 2 => 'c']`.
`$a[0]` *does not* refer to the first element. It refers to the *element with key 0*, which, if the array was written `['a', 'b']`, will coincidentally be the first element, but if it were written `[4 => 'b', 0 => 'a']` it will actually be the last.
In terms of their implementation, PHP *does* optimize arrays that have keys like *0,1,2...N* to be stored as a plain C array to save the overhead of using a hash table, but this is just a performance optimization. It's still a map/dictionary in terms of the API, and the implementation will automatically transition to a real hash table as soon as it ceases to have simple *0,1,2...N* keys.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | jesseschalken | eii9gia | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>"I am trying to access an array key that doesn't exist. It is stupid PHP to blame!" <|eor|><|soopr|>Its not about "an access key" list\[0\] should return the item in that position. PHP does this when the array contains only simple values, but PHP changes behaviour when the array contains key/val pairs.
To demonstrate:
​
$list = \['a', 'b', 'c'\];
$list\[0\] => 'a'
​
$list2 = \['a' => 'data', 'b' => 'data2', 'c' => 'data3'\];
$list2\[0\] => \['a' => data'\]
​<|eoopr|><|sor|>In terms of their API, PHP arrays are *always* maps/dictionaries. `['a', 'b', 'c']` is just shorthand for `[0 => 'a', 1 => 'b', 2 => 'c']`.
`$a[0]` *does not* refer to the first element. It refers to the *element with key 0*, which, if the array was written `['a', 'b']`, will coincidentally be the first element, but if it were written `[4 => 'b', 0 => 'a']` it will actually be the last.
In terms of their implementation, PHP *does* optimize arrays that have keys like *0,1,2...N* to be stored as a plain C array to save the overhead of using a hash table, but this is just a performance optimization. It's still a map/dictionary in terms of the API, and the implementation will automatically transition to a real hash table as soon as it ceases to have simple *0,1,2...N* keys.<|eor|><|soopr|>Meh.. This is just yarning and trying to find a rationale why the PHP array works the way it does. The array implementation is typical PHP, sort of like the norm other languages have, but still different. Its like the PHP ternary, backwards and broken by design. <|eoopr|><|sor|>I'm just telling you how PHP's arrays work so you can stop being surprised by them. I never said they were well designed.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | mawburn | eii2h5z | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>"I am trying to access an array key that doesn't exist. It is stupid PHP to blame!" <|eor|><|sor|>>an _array_ **key**
<|eor|><|eoss|><|endoftext|> | 11 |
lolphp | mr_ywg | eij0foz | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>The most harmful thing with PHP arrays is that developers that only know this language fails to understand the difference between list and maps. When they switch to other language they do stupide things and don't understand why their contribution is rejected.<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | dotancohen | eiq1u4n | <|soss|><|sot|>PHP: The array<|eot|><|sost|>PHP arrays are known to be bad. But having not used PHP in long time i recently was amazed how poorly they actually have built the array. Its basically a "all-things-fits" data structure. The best part is PHP will actually change the behaviour of the array depending on what it contains. Thats just fucking awesome!
​
[https://repl.it/repls/OutgoingSpiritedLifecycle](https://repl.it/repls/OutgoingSpiritedLifecycle)<|eost|><|sor|>"I am trying to access an array key that doesn't exist. It is stupid PHP to blame!" <|eor|><|sor|>>an _array_ **key**
<|eor|><|sor|>From [the fine manual](http://php.net/manual/en/language.types.array.php):
\> An array in PHP is actually an ordered map.
I agree that calling hashmaps "arrays" and then even having push and pop syntax is beyond stupid. However, it really is something that one learns on the first day they touch PHP. It is PHP's distinguishing feature, not unlike Python's whitespace or Java's verbosity.
​<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | Takeoded | 6rpmq7 | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|eols|><|endoftext|> | 0 |
lolphp | muffe2k | dl73c5v | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>Although the wording is not the best, you can clearly see that the second argument is not optional with a quick look at the method signature. \_()_/ <|eor|><|eols|><|endoftext|> | 20 |
lolphp | mikeputerbaugh | dl7dudi | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>[deleted]<|eor|><|soopr|>>PASSWORD_DEFAULT - Use the bcrypt algorithm **(default as of PHP 5.5.0).**<|eoopr|><|sor|>In PHP 5.5.0, the value of the constant PASSWORD_DEFAULT corresponds to the bcrypt algorithm.
This does not imply that there is a default value for the second argument of password_hash().
<|eor|><|eols|><|endoftext|> | 20 |
lolphp | deusex_ | dl7ufxp | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>[deleted]<|eor|><|soopr|>>PASSWORD_DEFAULT - Use the bcrypt algorithm **(default as of PHP 5.5.0).**<|eoopr|><|sor|>In PHP 5.5.0, the value of the constant PASSWORD_DEFAULT corresponds to the bcrypt algorithm.
This does not imply that there is a default value for the second argument of password_hash().
<|eor|><|sor|>Still a wtf, though, because when you upgrade versions, you stand a chance of trying to verify passwords using a different alg than they were originally hashed with if the DFAULT changes. <|eor|><|sor|>Not true, password_verify detects the type of hash from the hash itself. You are not supposed to compare hashed passwords using password_hash<|eor|><|eols|><|endoftext|> | 18 |
lolphp | Saltub | dl7s3aw | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>The only thing I can find to laugh at is you, OP.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | danabrey | dl7hubx | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>Meh, more /r/lolphpuserdidntreadthedocsproperly<|eor|><|eols|><|endoftext|> | 9 |
lolphp | nikic | dl7y6c7 | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>Rationale for this design decision, in case it's not obvious:
> By not having a default value (and hence being a mandatory argument), it forces implementing developers to understand that the default argument can change over time. This has a few benefits in that developers need to recognize that storage requirements may change over time, that portability may be affected, etc.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | djxfade | dlpj55b | <|sols|><|sot|>password_hash requires the 2nd argument, although it has a default value... wtf<|eot|><|sol|>http://php.net/manual/en/function.password-hash.php<|eol|><|sor|>Although the wording is not the best, you can clearly see that the second argument is not optional with a quick look at the method signature. \_()_/ <|eor|><|sor|>Hey buddy, you dropper this \\<|eor|><|eols|><|endoftext|> | 5 |
lolphp | 00Davo | 3hoikf | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|eols|><|endoftext|> | 0 |
lolphp | SnowdogU77 | cu96xv4 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|eols|><|endoftext|> | 39 |
lolphp | BilgeXA | cu9ev90 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|eols|><|endoftext|> | 26 |
lolphp | BilgeXA | cu9g6w1 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|soopr|>You're kidding, right? We're comparing an integer and a float. They're both numeric types; promoting those numbers to the same type for comparison really is the expected behaviour here. Almost every language does it, and the few others that don't promote numbers will all statically reject your program until you add the appropriate type conversions. (Off the top of my head: Haskell, ML, and Rust. There'd be more. They'd all be statically type-checked.)
Of course, it works with `==`, but you shouldn't have to resort to non-commutative non-transitive over-loose "equality" simply to check whether zero is equal to zero.<|eoopr|><|sor|>`===` is specifically for type comparison. The types are different.<|eor|><|eols|><|endoftext|> | 24 |
lolphp | smog_alado | cu97s4e | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>Now that's a damn good question.<|eor|><|sor|>The most likely reason PHP's ceil returns floats is because that is what the ceil function in the C library does.
The most likely reason the C library returns floats is because this way you avoid a costly round trip floating point to integer and then back to floating point if the output of ceil is used in a floating point operation.<|eor|><|eols|><|endoftext|> | 23 |
lolphp | barubary | cu9cgev | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>Now that's a damn good question.<|eor|><|sor|>The most likely reason PHP's ceil returns floats is because that is what the ceil function in the C library does.
The most likely reason the C library returns floats is because this way you avoid a costly round trip floating point to integer and then back to floating point if the output of ceil is used in a floating point operation.<|eor|><|sor|>Also because floating point numbers can easily exceed the range of an int, plus things like Inf and NaN.<|eor|><|eols|><|endoftext|> | 22 |
lolphp | the_biz | cu9wyv9 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>It's just more convenient to keep on working on floats when you do stuff with floats.
Why should it change data type, just because you ask it to round it off?
Ninja edit: This is of course when using it with `ceil(0.0)` or similar, not in the above use case.<|eor|><|sor|>the entire point of ceil / floor / round is to turn fractions into whole numbers, and integer is the default representation for whole numbers
it's like you write something that divides an unknown quantity by 2 and want to handle the case where the unkonwn quantity is odd, so you use 1 of ceil/floor/round. you can't be expected to type-check the result...<|eor|><|eols|><|endoftext|> | 17 |
lolphp | madsohm | cu98pik | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>It's just more convenient to keep on working on floats when you do stuff with floats.
Why should it change data type, just because you ask it to round it off?
Ninja edit: This is of course when using it with `ceil(0.0)` or similar, not in the above use case.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | BilgeXA | cu9gi1u | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|soopr|>You're kidding, right? We're comparing an integer and a float. They're both numeric types; promoting those numbers to the same type for comparison really is the expected behaviour here. Almost every language does it, and the few others that don't promote numbers will all statically reject your program until you add the appropriate type conversions. (Off the top of my head: Haskell, ML, and Rust. There'd be more. They'd all be statically type-checked.)
Of course, it works with `==`, but you shouldn't have to resort to non-commutative non-transitive over-loose "equality" simply to check whether zero is equal to zero.<|eoopr|><|sor|>`===` is specifically for type comparison. The types are different.<|eor|><|soopr|>I'm aware, and I think it's a problem with the language. You don't want "type comparison" or "loose comparison". You want sane equality, which is safe and behaves sensibly for at least all the built-in types. And you want to get that without having to choose between two seemingly similar operators based on your particular context and which operator's flaws are *less bad* for your use-case.
The language designers are supposed to work this stuff out for you. Zend did not.<|eoopr|><|sor|>lol<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Carlos_Sagan | cu97ad8 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|eols|><|endoftext|> | 10 |
lolphp | xiata | cu9m2lb | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|soopr|>You're kidding, right? We're comparing an integer and a float. They're both numeric types; promoting those numbers to the same type for comparison really is the expected behaviour here. Almost every language does it, and the few others that don't promote numbers will all statically reject your program until you add the appropriate type conversions. (Off the top of my head: Haskell, ML, and Rust. There'd be more. They'd all be statically type-checked.)
Of course, it works with `==`, but you shouldn't have to resort to non-commutative non-transitive over-loose "equality" simply to check whether zero is equal to zero.<|eoopr|><|sor|>`===` is specifically for type comparison. The types are different.<|eor|><|soopr|>I'm aware, and I think it's a problem with the language. You don't want "type comparison" or "loose comparison". You want sane equality, which is safe and behaves sensibly for at least all the built-in types. And you want to get that without having to choose between two seemingly similar operators based on your particular context and which operator's flaws are *less bad* for your use-case.
The language designers are supposed to work this stuff out for you. Zend did not.<|eoopr|><|sor|>From the php docs:
> float ceil ( float $value )
The real wtf is that you want a function that takes in a float and is guaranteed to return a float to return floats *sometimes*, as in only when the input was float-like, and sometimes return integers when the input was integer-like.
Why is this important? ceil() is intended to be used with floating point operations. If you wrote code where you are explicitly working with floats, it makes sense to continue to use the same type. You are likely going to continue to do floating point operations, returning an integer will in most cases require a integer -> float conversion.<|eor|><|eols|><|endoftext|> | 10 |
lolphp | the_biz | cuegr8g | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>It's just more convenient to keep on working on floats when you do stuff with floats.
Why should it change data type, just because you ask it to round it off?
Ninja edit: This is of course when using it with `ceil(0.0)` or similar, not in the above use case.<|eor|><|sor|>the entire point of ceil / floor / round is to turn fractions into whole numbers, and integer is the default representation for whole numbers
it's like you write something that divides an unknown quantity by 2 and want to handle the case where the unkonwn quantity is odd, so you use 1 of ceil/floor/round. you can't be expected to type-check the result...<|eor|><|sor|>I think this is because integers use integer division, meaning 3/2 == 1. While 3.0/2 == 1.5. You don't really want a variable you know is a float to get silently converted to a data type with different arithmetic rules.
Holy shit, did I just defend PHP? I feel *dirty*...<|eor|><|sor|>actually 3/2 returns a double but 4/2 returns an int<|eor|><|eols|><|endoftext|> | 9 |
lolphp | 00Davo | cu9y6hh | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|soopr|>You're kidding, right? We're comparing an integer and a float. They're both numeric types; promoting those numbers to the same type for comparison really is the expected behaviour here. Almost every language does it, and the few others that don't promote numbers will all statically reject your program until you add the appropriate type conversions. (Off the top of my head: Haskell, ML, and Rust. There'd be more. They'd all be statically type-checked.)
Of course, it works with `==`, but you shouldn't have to resort to non-commutative non-transitive over-loose "equality" simply to check whether zero is equal to zero.<|eoopr|><|sor|>`===` is specifically for type comparison. The types are different.<|eor|><|soopr|>I'm aware, and I think it's a problem with the language. You don't want "type comparison" or "loose comparison". You want sane equality, which is safe and behaves sensibly for at least all the built-in types. And you want to get that without having to choose between two seemingly similar operators based on your particular context and which operator's flaws are *less bad* for your use-case.
The language designers are supposed to work this stuff out for you. Zend did not.<|eoopr|><|sor|>You really shouldn't use `===` unless you specifically want to check that the value *and* the type are the same.
If you use it in place of `==` as some sanity security and you think that it's useful, you probably write bad code.<|eor|><|soopr|>If `==` really did check whether the values are the same, I'd agree with you, but `("b238ee8" == 0) && (0 == false) && ("b238ee8" != false)`.
`==` is an operator that tests whether the values sort of maybe look similar, maybe. I'd love an operator that actually tests whether the values are the same, but there isn't one. `===` is a *lot* closer to correct, with this particular post showing off one of the exceptions.<|eoopr|><|eols|><|endoftext|> | 8 |
lolphp | coredumperror | cuei9yv | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>It's just more convenient to keep on working on floats when you do stuff with floats.
Why should it change data type, just because you ask it to round it off?
Ninja edit: This is of course when using it with `ceil(0.0)` or similar, not in the above use case.<|eor|><|sor|>the entire point of ceil / floor / round is to turn fractions into whole numbers, and integer is the default representation for whole numbers
it's like you write something that divides an unknown quantity by 2 and want to handle the case where the unkonwn quantity is odd, so you use 1 of ceil/floor/round. you can't be expected to type-check the result...<|eor|><|sor|>I think this is because integers use integer division, meaning 3/2 == 1. While 3.0/2 == 1.5. You don't really want a variable you know is a float to get silently converted to a data type with different arithmetic rules.
Holy shit, did I just defend PHP? I feel *dirty*...<|eor|><|sor|>actually 3/2 returns a double but 4/2 returns an int<|eor|><|sor|>Oh right, this is PHP. I forgot that it pretends to be C, but mostly fails.
And now I feel even dirtier, because I defended PHP and was *wrong*. This is all your fault! ;)<|eor|><|eols|><|endoftext|> | 8 |
lolphp | josefx | cuide43 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>It's just more convenient to keep on working on floats when you do stuff with floats.
Why should it change data type, just because you ask it to round it off?
Ninja edit: This is of course when using it with `ceil(0.0)` or similar, not in the above use case.<|eor|><|sor|>the entire point of ceil / floor / round is to turn fractions into whole numbers, and integer is the default representation for whole numbers
it's like you write something that divides an unknown quantity by 2 and want to handle the case where the unkonwn quantity is odd, so you use 1 of ceil/floor/round. you can't be expected to type-check the result...<|eor|><|sor|>They also return a float in most other languages - the result can be bigger than PHP_INT_MAX. <|eor|><|eols|><|endoftext|> | 7 |
lolphp | josefx | cuidiex | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|sor|>In Javascript, the OP's perfectly reasonable assumption holds:
< 0 === Math.ceil(0)
> true
The only LOL Here is *you* don't understand why a number might be equal to itself.<|eor|><|sor|>[deleted]<|eor|><|sor|>OK then does C have a true integer data type?
+/u/CompileBot C
#include <stdio.h>
int main() {
float f = 0.0;
int i = 0;
printf("%s\n", ((int)f == i) ? "equal" : "unequal");
return 0;
}
<|eor|><|sor|>You are comparing a strict equality check === to a normal equality check == . Sometimes it would be nice to have === in C and C++ just to suppress the implicit type conversions. <|eor|><|eols|><|endoftext|> | 6 |
lolphp | smog_alado | cua37mi | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>That would be because ceil returns a float. 0.0 === ceil(0)<|eor|><|sor|>But why?<|eor|><|sor|>Now that's a damn good question.<|eor|><|sor|>The most likely reason PHP's ceil returns floats is because that is what the ceil function in the C library does.
The most likely reason the C library returns floats is because this way you avoid a costly round trip floating point to integer and then back to floating point if the output of ceil is used in a floating point operation.<|eor|><|sor|>But why PHP? Half of it is global functions based on C, and then half of it is objects loosely based on Java which do the same things. It's mostly dynamic typed but then it does stupid static typed things like this.<|eor|><|sor|>It makes perfect sense for 0 to not be equal to 0.0 when using ===. The problem is that PHP's == is so shitty and loose that you can't ever trust it and therefore have to resort to the overly-strict ===<|eor|><|eols|><|endoftext|> | 6 |
lolphp | marishtar | cua1lg4 | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|soopr|>You're kidding, right? We're comparing an integer and a float. They're both numeric types; promoting those numbers to the same type for comparison really is the expected behaviour here. Almost every language does it, and the few others that don't promote numbers will all statically reject your program until you add the appropriate type conversions. (Off the top of my head: Haskell, ML, and Rust. There'd be more. They'd all be statically type-checked.)
Of course, it works with `==`, but you shouldn't have to resort to non-commutative non-transitive over-loose "equality" simply to check whether zero is equal to zero.<|eoopr|><|sor|>`===` is specifically for type comparison. The types are different.<|eor|><|soopr|>I'm aware, and I think it's a problem with the language. You don't want "type comparison" or "loose comparison". You want sane equality, which is safe and behaves sensibly for at least all the built-in types. And you want to get that without having to choose between two seemingly similar operators based on your particular context and which operator's flaws are *less bad* for your use-case.
The language designers are supposed to work this stuff out for you. Zend did not.<|eoopr|><|sor|>From the php docs:
> float ceil ( float $value )
The real wtf is that you want a function that takes in a float and is guaranteed to return a float to return floats *sometimes*, as in only when the input was float-like, and sometimes return integers when the input was integer-like.
Why is this important? ceil() is intended to be used with floating point operations. If you wrote code where you are explicitly working with floats, it makes sense to continue to use the same type. You are likely going to continue to do floating point operations, returning an integer will in most cases require a integer -> float conversion.<|eor|><|soopr|>No, I don't want that at all. A function `float -> float` always returning a float is perfectly sensible. Of course, considering that `ceil()` was in fact passed an integer-typed value, I'd also find it perfectly sensible were it given a type along the lines of `Num a => a -> a`, but a simple non-overloaded `float -> float` is fine.
The real problem is the presence of two equality operators, neither of which apparently behaves at all similarly to the equality operators in other languages. JavaScript does the same thing but manages to avoid the issue almost coincidentally by only having one numeric type, so `===` is applicable everywhere as the equality operator. PHP does not, so you're left with choosing the operator that's "less" flawed for your particular context, as I rambled about earlier.<|eoopr|><|sor|>What would the purpose of calling ceil() on a known integer be?<|eor|><|eols|><|endoftext|> | 6 |
lolphp | poizan42 | cubtd8a | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>The only *lol* here is your lack of understanding of basic programming fundamentals, namely: *data types*.<|eor|><|sor|>I laugh at PHP having different data types for numbers. Really, it's hilarious.
A language that at one side tries to do away with the concept of data types by promoting automatic conversion between strings and numbers, etc, to try to make it easier and more intuitive to the newbie programmer will at the other side introduce the completely non-intuitive distinction between floats and ints.
Why is that necessary? What does it accomplish? (besides becoming more of a laughing stock?)
Either you treat all numbers like numbers and forget there are different types like other well thought out languages such as Perl where a numerical comparison between 0 and 0.0 will yield what you expect; or you have a full typed language.
But of course that isn't good enough for PHP.
So, yeah, i'm figuratively laughing my ass off right now at the stupidity that led to this situation and at your defending it like it weren't something to be fixed. <|eor|><|sor|>JavaScript:
> 9007199254740992 === 9007199254740993
<- true
Completely intuitive, right?<|eor|><|eols|><|endoftext|> | 5 |
lolphp | diarrhea_on_rye | cutppav | <|sols|><|sot|>0 !== ceil(0)<|eot|><|sol|>https://3v4l.org/HD5HD<|eol|><|sor|>Did you actually read the documentation of ceil()? Do you also wonder why 0 === 0.0 evaluates to false? Welcome in the land of floating point arithmetic.<|eor|><|soopr|>Floating point arithmetic isn't the problem - an IEEE 754 float 0.0 compares equal to an int 0 in any other language allowing that comparison, without running into float imprecision issues.
PHP's type system is the problem. It's atrocious.<|eoopr|><|sor|>I don't see the problem here. `0 == 0.0` returns true. `0 === 0.0` returns false. The first is a value comparison. The second is a value and type comparison. Int is a different type than float.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | Serialk | 2oek8k | <|sols|><|sot|>The PHP way of creating a directory without race conditions<|eot|><|sol|>http://stackoverflow.com/questions/19964287/mkdir-function-throw-exception-file-exists-even-after-checking-that-directory/25219407#25219407<|eol|><|eols|><|endoftext|> | 0 |
lolphp | suspiciously_calm | cmmhoab | <|sols|><|sot|>The PHP way of creating a directory without race conditions<|eot|><|sol|>http://stackoverflow.com/questions/19964287/mkdir-function-throw-exception-file-exists-even-after-checking-that-directory/25219407#25219407<|eol|><|sor|>This is a lolposix. I wouldn't know how to code around that in Posix either, other than trying and checking for EEXIST.<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Innominate8 | cmmo5vy | <|sols|><|sot|>The PHP way of creating a directory without race conditions<|eot|><|sol|>http://stackoverflow.com/questions/19964287/mkdir-function-throw-exception-file-exists-even-after-checking-that-directory/25219407#25219407<|eol|><|sor|>This is a lolposix. I wouldn't know how to code around that in Posix either, other than trying and checking for EEXIST.<|eor|><|sor|>You create the directory. The creation will succeed if and only if no file or directory with that name exists, and will fail otherwise.
This is a fairly common trick for implementing simple locks.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | ElusiveGuy | cmmnf1a | <|sols|><|sot|>The PHP way of creating a directory without race conditions<|eot|><|sol|>http://stackoverflow.com/questions/19964287/mkdir-function-throw-exception-file-exists-even-after-checking-that-directory/25219407#25219407<|eol|><|sor|>This is a lolposix. I wouldn't know how to code around that in Posix either, other than trying and checking for EEXIST.<|eor|><|sor|>This seems to be common to most OS APIs - checking for returned errors or exceptions rather than pre-checking for existence is a common pattern. Mostly because even if you could guarantee a file can't be deleted between a check and access, there's no guarantee that the media the file is located on (network? removeable?) will still be accessible. Heck, it's even possible for the file to disappear after opening, e.g. between reads, even *with* the file locking Windows allows.
Some examples for C#/.NET/Win32:
http://blogs.msdn.com/b/jaredpar/archive/2009/12/10/the-file-system-is-unpredictable.aspx
http://blogs.msdn.com/b/ericlippert/archive/2008/09/10/vexing-exceptions.aspx
http://stackoverflow.com/a/265958<|eor|><|eols|><|endoftext|> | 5 |
lolphp | sloat | 2j63fo | <|soss|><|sot|>Parts of the standard library are optional<|eot|><|sost|>Earlier today, I had to recompile core PHP (via Homebrew) in order to the the imap functions working. I would understand if it was an extension, but this is their standard library. It should not be optional.
Is there any rationalization for doing this, or am I just crazy?<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | Altreus | 2fzp4m | <|sols|><|sot|>Function deprecated in 5.5.0 has been throwing E_DEPRECATED since 5.3.0<|eot|><|sol|>http://uk1.php.net/manual/en/function.mysql-db-query.php<|eol|><|eols|><|endoftext|> | 0 |
lolphp | TimeToogo | cke92jg | <|sols|><|sot|>Function deprecated in 5.5.0 has been throwing E_DEPRECATED since 5.3.0<|eot|><|sol|>http://uk1.php.net/manual/en/function.mysql-db-query.php<|eol|><|sor|>Actually the entire mysql **extension** was deprecated as of 5.5.0
The linked function is correctly documented to have been deprecated in 5.3 if you read warning under the function definition.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | yousai | 2ednxn | <|sols|><|sot|>Gotta love php.ini defaults!<|eot|><|sol|>http://i.imgur.com/vPAPK0v.png<|eol|><|eols|><|endoftext|> | 0 |
lolphp | DCoder1337 | cjyhku4 | <|sols|><|sot|>Gotta love php.ini defaults!<|eot|><|sol|>http://i.imgur.com/vPAPK0v.png<|eol|><|sor|>There are two default ini files - `php.ini-development` and `php.ini-production`. `display_errors` defaults to `Off` in the production one, and [has been that way since its introduction in 2009](https://github.com/php/php-src/blame/master/php.ini-production#L469).
Not a lolphp, more of a loldev, either they based their config on the development ini file, or just copied over the development/testing machine's config during deployment.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | gu3st12 | cjyslig | <|sols|><|sot|>Gotta love php.ini defaults!<|eot|><|sol|>http://i.imgur.com/vPAPK0v.png<|eol|><|sor|>I think there needs to be a flair for posts that say "loldev" instead. Most of the stupid shit I see posts are from devs who don't know what they're doing, not a fault with PHP.
But of course, the PHP haters will leech onto anything. <|eor|><|eols|><|endoftext|> | 6 |
lolphp | Jonno_FTW | 1ybbdv | <|sols|><|sot|>Useful PHP Templating Feature in your IDE Plugin? Yeah lets remove it for no reason<|eot|><|sol|>https://bugs.eclipse.org/bugs/show_bug.cgi?id=318164<|eol|><|eols|><|endoftext|> | 0 |
lolphp | ajmarks | cfj55hm | <|sols|><|sot|>Useful PHP Templating Feature in your IDE Plugin? Yeah lets remove it for no reason<|eot|><|sol|>https://bugs.eclipse.org/bugs/show_bug.cgi?id=318164<|eol|><|sor|>Where's the lulz?<|eor|><|eols|><|endoftext|> | 6 |
lolphp | djsumdog | 1my1ix | <|sols|><|sot|>DateTimes are interpreted as mm/dd/yyyy unless you use hyphens, then it assumes you're European and uses dd/mm/yyyy<|eot|><|sol|>https://twitter.com/serenecloud/status/381986015159648256<|eol|><|eols|><|endoftext|> | 0 |
lolphp | shitcanz | e9476a | <|sols|><|sot|>catch requires an annotation for consistency<|eot|><|sol|>https://repl.it/repls/StupendousLastMemory<|eol|><|eols|><|endoftext|> | 0 |
lolphp | bopp | fagf53j | <|sols|><|sot|>catch requires an annotation for consistency<|eot|><|sol|>https://repl.it/repls/StupendousLastMemory<|eol|><|sor|>I don't see how `catch` would make sense, if you don't specify _what_ it needs to catch. <|eor|><|eols|><|endoftext|> | 9 |
lolphp | duskwuff | fagfwyx | <|sols|><|sot|>catch requires an annotation for consistency<|eot|><|sol|>https://repl.it/repls/StupendousLastMemory<|eol|><|soopr|>Basically you must annotate each catch with a Exception type. But all other PHP constructs are dynamic.<|eoopr|><|sor|>The type name isn't just a type declaration; it controls which exceptions are caught by the clause. This syntax was added in PHP 5.0 (along with exceptions) long before type annotations were even under consideration.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | Cranio76 | fagl82d | <|sols|><|sot|>catch requires an annotation for consistency<|eot|><|sol|>https://repl.it/repls/StupendousLastMemory<|eol|><|sor|>It's not a bug, it's a feature. And it's not an annotation, it's a type hint which is a fundamental part of the construct.
Plus, if you want general catch-all, you can catch `\Exception` or `\Throwable`.
Honestly, can't see any reason for this post here,<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Mark_Messa | dlqui9 | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | SixFootJockey | f4tlzq3 | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|eoss|><|endoftext|> | 15 |
lolphp | ranisalt | f4trlia | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|soopr|>> PHP's session is giving the client a key to that session.
Actually, is the other way around in the example I've posted.<|eoopr|><|sor|>No, you're highlighting a malicious client passing an invalid key to the server.
You can configure PHP to not accept session IDs that were not generated on the server.
> session.use_strict_mode specifies whether the module will use strict session id mode. If this mode is enabled, the module does not accept uninitialized session ID. If uninitialized session ID is sent from browser, new session ID is sent to browser. Applications are protected from session fixation via session adoption with strict mode. Defaults to 0 (disabled).
>
> https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode<|eor|><|sor|>As always, the sane, safe and secure option is off by default.<|eor|><|eoss|><|endoftext|> | 12 |
lolphp | SixFootJockey | f4tmqzt | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|eoss|><|endoftext|> | 11 |
lolphp | Max-P | f4tr7z7 | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>The session ID is literally just a name for the file that contains the session data in the temporary directory. If it doesn't exist, it's created and you get an empty session.
There are no security implications whatsoever. The worst that can happen is to create a whole bunch of empty sessions, which you could just as easily trigger by not accepting cookies and loading a page that calls `session_start()`. Since legit clients will be using the ID generated by the server, this will not impact any legitimate client.
The whole security around sessions is based on the fact that it's practically impossible to guess *someone else's* session ID. If you're using the session ID for something sensitive, you're essentially trusting a browser cookie and it's on you.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | AyrA_ch | f4uj19w | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|sor|>> Your task is to ensure that the key is being used by the correct owner.
To be fair, nobody does this. I don't remember to ever not be able to copy session Ids between different browsers and applications. Fixing the session on the IP breaks it for mobile users and fixing it on the user agent is annoying to the user because browsers update frequently these days and if you are able to steal a session id, you likely also are able to copy the user agent.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | SixFootJockey | f4tp6qx | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|soopr|>> PHP's session is giving the client a key to that session.
Actually, is the other way around in the example I've posted.<|eoopr|><|sor|>No, you're highlighting a malicious client passing an invalid key to the server.
You can configure PHP to not accept session IDs that were not generated on the server.
> session.use_strict_mode specifies whether the module will use strict session id mode. If this mode is enabled, the module does not accept uninitialized session ID. If uninitialized session ID is sent from browser, new session ID is sent to browser. Applications are protected from session fixation via session adoption with strict mode. Defaults to 0 (disabled).
>
> https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode<|eor|><|eoss|><|endoftext|> | 7 |
lolphp | SixFootJockey | f4tsbgh | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|soopr|>> PHP's session is giving the client a key to that session.
Actually, is the other way around in the example I've posted.<|eoopr|><|sor|>No, you're highlighting a malicious client passing an invalid key to the server.
You can configure PHP to not accept session IDs that were not generated on the server.
> session.use_strict_mode specifies whether the module will use strict session id mode. If this mode is enabled, the module does not accept uninitialized session ID. If uninitialized session ID is sent from browser, new session ID is sent to browser. Applications are protected from session fixation via session adoption with strict mode. Defaults to 0 (disabled).
>
> https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode<|eor|><|sor|>As always, the sane, safe and secure option is off by default.<|eor|><|sor|>As is tradition.
I wouldn't count it as making the sessions safe and secure though. A malicious client can still pass a valid session ID that belongs to another client.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | weirdasianfaces | f4tvxlf | <|soss|><|sot|>PHP Session: ID generated server side only?<|eot|><|sost|>Consider the following PHP script:
<?php
session_start();
echo session_id();
When you open this page via browser, you should see the session ID **generated by the server.**
For a standard php.ini setup, this session ID might be 32 characters long ranging from 0-9 a-v (5 bits per character). Example:
va9o92iefqoe0ouiado99r9hr299oamc
Now, suppose you manually changed in the browser the cookie's session ID from `va9o92iefqoe0ouiado99r9hr299oamc` to `z`, and then accessed again the above script:
At first, I would expect that PHP should be smart enough to recognize that such session ID was not generated by the server and, therefore, it should be ignored and a new one should be generated server side. Unfortunately, this is not what happens. Actually, PHP just moves forward with `z` as session ID.
I'm not sure how a malicious user could exploit that, but I don't like the idea of session ID being generated client side.
**Question**
Am I missing something? If not, how to harden PHP session to mitigate such issue?
***
**Follow-Up**
According to php.ini:
; Whether to use strict session mode.
; Strict session mode does not accept an uninitialized session ID, and
; regenerates the session ID if the browser sends an uninitialized session ID.
; Strict mode protects applications from session fixation via a session adoption
; vulnerability. It is disabled by default for maximum compatibility, but
; enabling it is encouraged.
; https://wiki.php.net/rfc/strict_sessions
session.use_strict_mode = 0
Also, available at the [PHP Manual](https://www.php.net/manual/en/function.session-destroy.php):
> When `session.use_strict_mode` is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. **Enabling `session.use_strict_mode` is recommended for all sites.**
Therefore, just changing to `session.use_strict_mode = 1` is enough to avoid client side generation of session ID.<|eost|><|sor|>If you're trusting only a cookie's value then you've already failed security.
This is not exclusive to PHP.<|eor|><|soopr|>I'm thrusting session_start(), not exactly cookie's value ...<|eoopr|><|sor|>Yes you are. PHP's session is giving the client a key to that session. Any further request is using that key to pair with an active session.
Your task is to ensure that the key is being used by the correct owner.<|eor|><|soopr|>> PHP's session is giving the client a key to that session.
Actually, is the other way around in the example I've posted.<|eoopr|><|sor|>No, you're highlighting a malicious client passing an invalid key to the server.
You can configure PHP to not accept session IDs that were not generated on the server.
> session.use_strict_mode specifies whether the module will use strict session id mode. If this mode is enabled, the module does not accept uninitialized session ID. If uninitialized session ID is sent from browser, new session ID is sent to browser. Applications are protected from session fixation via session adoption with strict mode. Defaults to 0 (disabled).
>
> https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode<|eor|><|sor|>As always, the sane, safe and secure option is off by default.<|eor|><|sor|>As is tradition.
I wouldn't count it as making the sessions safe and secure though. A malicious client can still pass a valid session ID that belongs to another client.<|eor|><|sor|>Yeah to clarify what this config setting does: it prevents an attacker from somehow getting a victim to use a session ID that is known to the attacker. This imo isn't a very significant security mitigation since the scenarios where that would work are pretty limited. See this for more info: https://www.owasp.org/index.php/Session_fixation
If an attacker can for somehow leak a valid session ID from the victim they could still hijack it.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | MMauro94 | 66vj72 | <|sols|><|sot|>Having bare URLs in code doesn't give a compile error<|eot|><|sol|>https://3v4l.org/1jpiY<|eol|><|eols|><|endoftext|> | 0 |
lolphp | Rhomboid | dgllm0w | <|sols|><|sot|>Having bare URLs in code doesn't give a compile error<|eot|><|sol|>https://3v4l.org/1jpiY<|eol|><|sor|>That's not a lolphp. `//` starts a comment, so everything from there on is ignored. An identifier ending in a colon is a label (a possible target for `goto`.) So it's perfectly valid code. This is not specific to PHP; it also applies to several other languages, such as C and C++.
<|eor|><|eols|><|endoftext|> | 34 |
lolphp | sproingie | dglvj0g | <|sols|><|sot|>Having bare URLs in code doesn't give a compile error<|eot|><|sol|>https://3v4l.org/1jpiY<|eol|><|sor|>That's not a lolphp. `//` starts a comment, so everything from there on is ignored. An identifier ending in a colon is a label (a possible target for `goto`.) So it's perfectly valid code. This is not specific to PHP; it also applies to several other languages, such as C and C++.
<|eor|><|soopr|>Lol I didn't thought of that. Yet I didn't know PHP supported gotos.<|eoopr|><|sor|>Yes, but in classic PHP fashion, they did it half-assed: You can't label a loop to control it with `break` and `continue`. See, those don't take labels, but only numeric argument for levels to break out of instead. Compare to perl's `last`/`next` (to say nothing of `goto &sub`)<|eor|><|eols|><|endoftext|> | 5 |
lolphp | TheOnlyMrYeah | 2yfjei | <|sols|><|sot|>Object properties which are only accessible via foreach (x-post from /r/shittyprogramming)<|eot|><|sol|>http://np.reddit.com/r/shittyprogramming/comments/2yfhc2/php_objectproperties_that_are_only_accessible_via/<|eol|><|eols|><|endoftext|> | 0 |
lolphp | myaut | cp934px | <|sols|><|sot|>Object properties which are only accessible via foreach (x-post from /r/shittyprogramming)<|eot|><|sol|>http://np.reddit.com/r/shittyprogramming/comments/2yfhc2/php_objectproperties_that_are_only_accessible_via/<|eol|><|sor|>That's because in dynamic languages objects are usually implemented as hashes/dictionaries/whatever.
Python:
class C: pass
c = C()
setattr(c, '00', 0)
c.00 # error
getattr(c, '00') # OK
JavaScript:
var obj = {['00']: 0}
obj.00 # error
obj['00'] # OK
<|eor|><|eols|><|endoftext|> | 9 |
lolphp | cite-reader | cp9p685 | <|sols|><|sot|>Object properties which are only accessible via foreach (x-post from /r/shittyprogramming)<|eot|><|sol|>http://np.reddit.com/r/shittyprogramming/comments/2yfhc2/php_objectproperties_that_are_only_accessible_via/<|eol|><|sor|>You buried the lead! Go [one step further](http://codepad.org/bT0awVpM) and make an array with an inaccessible key.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | aaptel | 2c8z21 | <|sols|><|sot|>No way to insert multiple rows at the same time, building huge query string instead.<|eot|><|sol|>http://stackoverflow.com/a/9088630/151617<|eol|><|eols|><|endoftext|> | 0 |
lolphp | xiongchiamiov | cjd4afi | <|sols|><|sot|>No way to insert multiple rows at the same time, building huge query string instead.<|eot|><|sol|>http://stackoverflow.com/a/9088630/151617<|eol|><|soopr|>> While the overall query itself took milliseconds or less, the latter (single string) query was consistently 8 times faster or more. If this was built out to say reflect an import of thousands of rows on many more columns, the difference could be enormous.
Not sure that the overhead in handling a huge string will make this method scale.<|eoopr|><|sor|>Ok, so try it. These things are trivial to benchmark.
I don't get what's so lol about this.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | tdammers | cjd5b15 | <|sols|><|sot|>No way to insert multiple rows at the same time, building huge query string instead.<|eot|><|sol|>http://stackoverflow.com/a/9088630/151617<|eol|><|soopr|>> While the overall query itself took milliseconds or less, the latter (single string) query was consistently 8 times faster or more. If this was built out to say reflect an import of thousands of rows on many more columns, the difference could be enormous.
Not sure that the overhead in handling a huge string will make this method scale.<|eoopr|><|sor|>My guess is that yes, building that query string is faster for small data sets (10s of rows), *much* faster for medium-sized data sets (100s of rows, maybe 1000s), and will burn through your PHP memory limit (or your swap partition, as the situation may be) like there's no tomorrow for large datasets (millions or maybe billions of rows).
YMMV, but what it boils down to is that the one-large-query approach involves building a query string *and* a data structure to hold the values in memory, and to *keep it in memory* until the query is sent - this means that if you have a gigabyte of data to send, then you need to allocate at least a gigabyte of memory, but likely much more due to various overheads. The "one query per row" approach, however, can be written such that it runs in constant memory - read one row, send one row, read one row, send one row...; this scales linearly for arbitrary dataset sizes, until you hit the execution timeout limit. But then, you should be running this in a php-cli context anyway, because only idiots do this kind of thing synchronously in a HTTP context.
TL;DR: The overhead in handling a huge string will make this method crash and burn for really large data sets.<|eor|><|sor|>That data needs to be in memory anyways weather it is put in a string or bound inside a loop.<|eor|><|sor|>Uhm, no.
Look:
<?php
$f = fopen("foobar.csv", "r");
while (!feof($f)) {
$items = fgetcsv($f);
$statement->execute($items);
}
fclose($f);
No more than one record is held in active memory at once; I can run this over a ten-billion-line CSV file, and it'll still run in constant memory.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | supremecommand3r | 26auoy | <|soss|><|sot|>This place is scary<|eot|><|sost|>None of you have usernames, creeping me out
http://imgur.com/jDVrpb3<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | ajmarks | chpblv3 | <|soss|><|sot|>This place is scary<|eot|><|sost|>None of you have usernames, creeping me out
http://imgur.com/jDVrpb3<|eost|><|sor|>Mobile helps...
Or just go into the CSS and disable the `display:none` part for nicknames <|eor|><|sor|>Or just untick "Use subreddit style."<|eor|><|soopr|>Why is it like this? <|eoopr|><|sor|>Ours is not to reason why.<|eor|><|eoss|><|endoftext|> | 5 |
lolphp | kenbw2 | 1ypgpb | <|soss|><|sot|>string(3) " "<|eot|><|sost|>Defeated by a sign<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | tdammers | cfmkm64 | <|soss|><|sot|>string(3) " "<|eot|><|sost|>Defeated by a sign<|eost|><|sor|>Well, duh. PHP doesn't have a string type. It has a byte array type which, for weird reasons, ended up being called "string" in PHP. As long as you respect this, it will (mostly) work as "designed". The "manual" and the "documentation" also call these things "strings", so beware; reading them can be highly confusing.
In a similar fashion, PHP doesn't have arrays either. What PHP calls "arrays" is really more like an ordered hash map. Again, for reasons that are beyond me, PHP calls it "array", and decides that if you ever need a data structure, this will be it.<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | ajmarks | cfmkk9g | <|soss|><|sot|>string(3) " "<|eot|><|sost|>Defeated by a sign<|eost|><|sor|>Explanation?<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | deadman87 | 9tynx6 | <|sols|><|sot|>Magento got jokes<|eot|><|sol|>https://imgflip.com/i/2lnnyj<|eol|><|eols|><|endoftext|> | 0 |
lolphp | DCoder1337 | e90pu28 | <|sols|><|sot|>Magento got jokes<|eot|><|sol|>https://imgflip.com/i/2lnnyj<|eol|><|sor|>This is not really /r/lolphp material, more like /r/ProgrammingHorror .
That said, *all of Magento* qualifies as one big joke. For example:
* [Undefined classes, methods, and fields, oh my!](https://imgur.com/RMxWEgR)
* [You said you wanted a DB index, you didn't say anything about keeping your data](https://what.thedailywtf.com/topic/20898/the-index-is-more-important-than-the-data)
* [`sprintf` is hard, let's `@sprintf` instead](https://www.reddit.com/r/PHP/comments/7wo8e1/dell_debugging_in_production_sucks/du2q7dv/)
* [A screenful of ~~secrets~~annoyances](https://news.ycombinator.com/item?id=13343468)
* [Paid extensions: security fuckurity](https://news.ycombinator.com/item?id=13100162)<|eor|><|eols|><|endoftext|> | 21 |
lolphp | galaktos | e91657p | <|sols|><|sot|>Magento got jokes<|eot|><|sol|>https://imgflip.com/i/2lnnyj<|eol|><|sor|>This is not really /r/lolphp material, more like /r/ProgrammingHorror .
That said, *all of Magento* qualifies as one big joke. For example:
* [Undefined classes, methods, and fields, oh my!](https://imgur.com/RMxWEgR)
* [You said you wanted a DB index, you didn't say anything about keeping your data](https://what.thedailywtf.com/topic/20898/the-index-is-more-important-than-the-data)
* [`sprintf` is hard, let's `@sprintf` instead](https://www.reddit.com/r/PHP/comments/7wo8e1/dell_debugging_in_production_sucks/du2q7dv/)
* [A screenful of ~~secrets~~annoyances](https://news.ycombinator.com/item?id=13343468)
* [Paid extensions: security fuckurity](https://news.ycombinator.com/item?id=13100162)<|eor|><|sor|>> if you tell it to add a unique index and MySQL refuses to because existing data is not unique, the API will parse the MySQL error message to identify the duplicated fields/values and delete the duplicate rows silently.
JESUS WEPT<|eor|><|eols|><|endoftext|> | 16 |
lolphp | dividebyzero14 | e90eajm | <|sols|><|sot|>Magento got jokes<|eot|><|sol|>https://imgflip.com/i/2lnnyj<|eol|><|soopr|>It's XML hell<|eoopr|><|sor|>Hey, to be fair, you're eliminating boilerplate code. The replacement is boilerplate *markup*<|eor|><|eols|><|endoftext|> | 9 |
lolphp | redwall_hp | e91j8w9 | <|sols|><|sot|>Magento got jokes<|eot|><|sol|>https://imgflip.com/i/2lnnyj<|eol|><|sor|>This is not really /r/lolphp material, more like /r/ProgrammingHorror .
That said, *all of Magento* qualifies as one big joke. For example:
* [Undefined classes, methods, and fields, oh my!](https://imgur.com/RMxWEgR)
* [You said you wanted a DB index, you didn't say anything about keeping your data](https://what.thedailywtf.com/topic/20898/the-index-is-more-important-than-the-data)
* [`sprintf` is hard, let's `@sprintf` instead](https://www.reddit.com/r/PHP/comments/7wo8e1/dell_debugging_in_production_sucks/du2q7dv/)
* [A screenful of ~~secrets~~annoyances](https://news.ycombinator.com/item?id=13343468)
* [Paid extensions: security fuckurity](https://news.ycombinator.com/item?id=13100162)<|eor|><|sor|>Not sure I'd trust all the inspections, especially "undefined field/method/whatever" is just saying phpstorm couldn't resolve the identifier statically on the inferred type. Lots of systems use dynamically built-up methods (who thinks accessors should be written by hand?) which it can't detect. Ah, but then I went and read the HN rant and discovered what it's doing, and wow. They managed to make it even less type safe than PHP itself.
Still, my favorite is "silly assignment".
But ... despite all these WTFs, it and similar things are still used everywhere. One of the most depressing facts programmers get to learn is that code quality isn't even close to being the determining factor of success. One could reflect on PHP itself that way, though I'm satisfied that PHP is getting pushed more into the legacy bin as far as starting new projects goes ... if only the existing apps written in it would follow suit.
<|eor|><|sor|>If code quality determined success, the term "WordPress" wouldn't mean anything to anyone. Sadly, it does not.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | nowimpissed | 31j03g | <|sols|><|sot|>Heredocs & semicolons<|eot|><|sol|>http://ca3.php.net/manual/en/language.types.string.php#107138<|eol|><|eols|><|endoftext|> | 0 |
lolphp | philipwhiuk | cq282ay | <|sols|><|sot|>Heredocs & semicolons<|eot|><|sol|>http://ca3.php.net/manual/en/language.types.string.php#107138<|eol|><|sor|>Nope, I think that's reasonable behaviour. A ; ends a statement, a heredoc is not a statement, it's an expression.
You can't do
`2+3;`
either<|eor|><|eols|><|endoftext|> | 18 |
lolphp | vytah | cq2cvud | <|sols|><|sot|>Heredocs & semicolons<|eot|><|sol|>http://ca3.php.net/manual/en/language.types.string.php#107138<|eol|><|sor|>Nope, I think that's reasonable behaviour. A ; ends a statement, a heredoc is not a statement, it's an expression.
You can't do
`2+3;`
either<|eor|><|sor|>I agree, all of it makes sense: you have to write
$a = <<<END
END;
because you need the semicolon to end the statement, it's not a part of the heredoc syntax.
The only WTF here is that someone though that it had to be mentioned and explained like for five-year-olds. And that someone is just a random commenter.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | philipwhiuk | cq284ds | <|sols|><|sot|>Heredocs & semicolons<|eot|><|sol|>http://ca3.php.net/manual/en/language.types.string.php#107138<|eol|><|sor|>I would gag if I inherited code that was passing heredoc strings into functions like this.
It kind of makes sense, as you can't go `foo($str = 'abcd';);` but obviously `$str = 'abcd';` is fine as is `foo($str = 'abcd');`.<|eor|><|sor|>I think heredoc is almost never the right solution personally, but we are where we are.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | nowimpissed | cq2c0jx | <|sols|><|sot|>Heredocs & semicolons<|eot|><|sol|>http://ca3.php.net/manual/en/language.types.string.php#107138<|eol|><|sor|>More bizarre is how PHP's heredoc syntax has somehow sprouted an extra `<`. PHP uses three. Every other language with heredocs (sh, Perl, Ruby, Racket) uses two.<|eor|><|soopr|>Well, bash (since semi-recentlish, I belive) uses three `<`s for "here-strings".<|eoopr|><|sor|>bash uses two '<'s<|eor|><|soopr|>Two for "regular here-docs", three for the aforementioned "here-strings". From the `man` himself:
me@box:~$ man bash | grep -iA8 here\ string
Here Strings
A variant of here documents, the format is:
<<<word
The word undergoes brace expansion, tilde expansion, parameter and variable expansion,
command substitution, arithmetic expansion, and quote removal. Pathname expansion and
word splitting are not performed. The result is supplied as a single string to the com
mand on its standard input.
Edit: see it in action:
me@box:~$ cat <<< dog
dog
me@box:~$ <|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | myhf | 1y4wds | <|sols|><|sot|>List possible changes, updates, additions for php6<|eot|><|sol|>https://wiki.php.net/ideas/php6<|eol|><|eols|><|endoftext|> | 0 |
lolphp | elcapitanoooo | qo23yc | <|soss|><|sot|>Get class: Just a lol<|eot|><|sost|>Consider this example:
class A { }
class Foo {
public static function bar($x) {
echo get_class($x), "\n";
}
}
Foo::bar(new A());
Foo::bar(null);
Its just broken.<|eost|><|eoss|><|endoftext|> | 0 |
lolphp | sproingie | hjk3wst | <|soss|><|sot|>Get class: Just a lol<|eot|><|sost|>Consider this example:
class A { }
class Foo {
public static function bar($x) {
echo get_class($x), "\n";
}
}
Foo::bar(new A());
Foo::bar(null);
Its just broken.<|eost|><|sor|>https://3v4l.org/5Epdj
ENOLOL ... other than that OP can't seem to write functions outside of a class. _Sacre bleu_, `get_class(null)` is a type error?<|eor|><|eoss|><|endoftext|> | 13 |
lolphp | sproingie | hjk72ir | <|soss|><|sot|>Get class: Just a lol<|eot|><|sost|>Consider this example:
class A { }
class Foo {
public static function bar($x) {
echo get_class($x), "\n";
}
}
Foo::bar(new A());
Foo::bar(null);
Its just broken.<|eost|><|sor|>https://3v4l.org/5Epdj
ENOLOL ... other than that OP can't seem to write functions outside of a class. _Sacre bleu_, `get_class(null)` is a type error?<|eor|><|soopr|>Its not an error in earlier php versions. Totally lol in PHP 5 and 7. We still have legacy PHP code thats not yet rewritten in a saner language. And we constantly encounter lolphps. Please see the result in PHP 5 or 7.<|eoopr|><|sor|>Yeah, it's a runtime type "warning", which is usually fatal anyway unless you're doing something stupid like running WordPress. Standard behavior until it was turned into a proper error in PHP8.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | sproingie | hjkg0vv | <|soss|><|sot|>Get class: Just a lol<|eot|><|sost|>Consider this example:
class A { }
class Foo {
public static function bar($x) {
echo get_class($x), "\n";
}
}
Foo::bar(new A());
Foo::bar(null);
Its just broken.<|eost|><|sor|>https://3v4l.org/5Epdj
ENOLOL ... other than that OP can't seem to write functions outside of a class. _Sacre bleu_, `get_class(null)` is a type error?<|eor|><|soopr|>Its not an error in earlier php versions. Totally lol in PHP 5 and 7. We still have legacy PHP code thats not yet rewritten in a saner language. And we constantly encounter lolphps. Please see the result in PHP 5 or 7.<|eoopr|><|sor|>Yeah, it's a runtime type "warning", which is usually fatal anyway unless you're doing something stupid like running WordPress. Standard behavior until it was turned into a proper error in PHP8.<|eor|><|soopr|>https://3v4l.org/F18jo#v7.0.0
Anyway, we found out the null caused a bug that was very hard to pinpoint. Took us a long time (the PHP codebase is quite large and not really maintained) we are in the works of rewriting away from PHP, just because no one really wants to work with PHP, and its riddled with weird stuff like this.<|eoopr|><|sor|>The documented behavior of `get_class()` without arguments is to return the enclosing class. So when it received null, it decided that was close enough to an empty arglist. Classic "always keep running even when given nonsensical data" behavior of old PHP. Which yep, is the mother of at least half of all the lolphp's out there.
I'm definitely no defender of PHP, but this is more a historical thing that got fixed early in 7.x. historilol? Current practice is `get_debug_class($whatever)` for messages or `::class` suffix or `__CLASS__`, depending (`$instance::class` works as of php8).
BTW just out of curiosity, what language are you porting to?<|eor|><|eoss|><|endoftext|> | 6 |