subreddit
stringclasses 7
values | author
stringlengths 3
20
| id
stringlengths 5
7
| content
stringlengths 67
30.4k
| score
int64 0
140k
|
---|---|---|---|---|
lolphp | DarkMio | 7xk8ga | <|sols|><|sot|>Parsing a date string without a day will default the day to 1 - obviously.<|eot|><|sol|>https://bugs.php.net/bug.php?id=69661<|eol|><|eols|><|endoftext|> | 9 |
lolphp | eztab | du9ab6s | <|sols|><|sot|>Parsing a date string without a day will default the day to 1 - obviously.<|eot|><|sol|>https://bugs.php.net/bug.php?id=69661<|eol|><|sor|>This does seem like the only logical behavior.
I would expect this. Pretty sure it is the same in other programming languages.<|eor|><|eols|><|endoftext|> | 27 |
lolphp | BadFurDay | du9c3ba | <|sols|><|sot|>Parsing a date string without a day will default the day to 1 - obviously.<|eot|><|sol|>https://bugs.php.net/bug.php?id=69661<|eol|><|sor|>This does seem like the only logical behavior.
I would expect this. Pretty sure it is the same in other programming languages.<|eor|><|sor|>Welcome to /r/lolphp<|eor|><|eols|><|endoftext|> | 16 |
lolphp | djxfade | du9z6li | <|sols|><|sot|>Parsing a date string without a day will default the day to 1 - obviously.<|eot|><|sol|>https://bugs.php.net/bug.php?id=69661<|eol|><|sor|>This does seem like the only logical behavior.
I would expect this. Pretty sure it is the same in other programming languages.<|eor|><|sor|>I would prefer if it just threw an Exception<|eor|><|eols|><|endoftext|> | 11 |
lolphp | Crashmatusow | du9mvqb | <|sols|><|sot|>Parsing a date string without a day will default the day to 1 - obviously.<|eot|><|sol|>https://bugs.php.net/bug.php?id=69661<|eol|><|sor|>This does seem like the only logical behavior.
I would expect this. Pretty sure it is the same in other programming languages.<|eor|><|sor|>Pretty sure sql ... oracle, at least, does exactly this<|eor|><|eols|><|endoftext|> | 6 |
lolphp | kr094 | 63zgjn | <|sols|><|sot|>The docs for array_search tell you to use array_keys to return >1 matching key. I never knew about search_value<|eot|><|sol|>http://php.net/manual/en/function.array-search.php#refsect1-function.array-search-returnvalues<|eol|><|eols|><|endoftext|> | 8 |
lolphp | MMauro94 | 5yf4at | <|sols|><|sot|>Type hinting works very well...<|eot|><|sol|>https://3v4l.org/PXt64<|eol|><|eols|><|endoftext|> | 10 |
lolphp | mort96 | depi6hz | <|sols|><|sot|>Type hinting works very well...<|eot|><|sol|>https://3v4l.org/PXt64<|eol|><|sor|>Dont do `var_dump` then<|eor|><|sor|>.. but this has nothing to do with var_dump??
It has the exact same issue when using echo: https://3v4l.org/6EeW5. The problem is that PHP 7.0+ and HHVM doesn't throw an error when you're trying to call a function with the wrong types, not that var_dump is doing something wrong.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | themusicgod1 | 4cuz2d | <|sols|><|sot|>yolo crypto<|eot|><|sol|>https://github.com/paragonie/yolocrypto<|eol|><|eols|><|endoftext|> | 9 |
lolphp | carlos_vini | d1lqbs9 | <|sols|><|sot|>yolo crypto<|eot|><|sol|>https://github.com/paragonie/yolocrypto<|eol|><|sor|>It's much more fun when README doesn't tell you it's insecure.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | carlos_vini | 3x44or | <|soss|><|sot|>Declaration of createFromFormat should be DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] ), or maybe not....<|eot|><|sost|>http://php.net/manual/en/datetime.createfromformat.php
Nice, it says the signature is:
public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )
Let's try to extend it:
https://3v4l.org/HTuio
Warning: Declaration of My_DateTime::createFromFormat($format, $time, DateTimeZone $timezone = NULL) should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/HTuio on line 9
Oh, it seems it wants a simple object, let's try to use it this way:
https://3v4l.org/3g0S3
Warning: DateTime::createFromFormat() expects parameter 3 to be DateTimeZone, object given in /in/3g0S3 on line 3
And i'm not even using the scalar type hints for "string" which i know wouldn't work.
DOMDocument works:
https://3v4l.org/u0Kvn
So i guess you need to try every possible combination and if PHP complains you just try again until it works.<|eost|><|eoss|><|endoftext|> | 7 |
lolphp | ltldvl | 3td3hk | <|sols|><|sot|>Bcmath, accepted number format<|eot|><|sol|>https://3v4l.org/MEq9X<|eol|><|eols|><|endoftext|> | 7 |
lolphp | ltldvl | cx54wmc | <|sols|><|sot|>Bcmath, accepted number format<|eot|><|sol|>https://3v4l.org/MEq9X<|eol|><|soopr|>An example when this might bite you, is for example, adding two numbers together, where one might be float. If float gets scientific representation when casted to string the result will we incorrect. Therefore, special care must be taken when calling bc* functions, if argument is float, it should me manually casted to string using sprintf function with %F type specifier.<|eoopr|><|eols|><|endoftext|> | 11 |
lolphp | the_alias_of_andrea | cx5m5xr | <|sols|><|sot|>Bcmath, accepted number format<|eot|><|sol|>https://3v4l.org/MEq9X<|eol|><|sor|>Bcmath lets you use arbitrary bases, so I would guess this is probably due to ambiguity about the base of the exponent and confusion between 'e' (mantissa/exponent separator) and 'e' (quintadecimal and higher digit).
Anyway, bcmath isn't a PHP-specific thing (granted only PHP seems to use it much), so if this is a problem (I'm not sure it is), it's a problem for anything using it. The real lolphp is that the only thing close to a real decimal library in PHP's bundled extensions is a slow arbitrary-base arbitrary-precision backend for `bc` that works directly on text :)<|eor|><|eols|><|endoftext|> | 9 |
lolphp | the_alias_of_andrea | cx5q5zm | <|sols|><|sot|>Bcmath, accepted number format<|eot|><|sol|>https://3v4l.org/MEq9X<|eol|><|sor|>Bcmath lets you use arbitrary bases, so I would guess this is probably due to ambiguity about the base of the exponent and confusion between 'e' (mantissa/exponent separator) and 'e' (quintadecimal and higher digit).
Anyway, bcmath isn't a PHP-specific thing (granted only PHP seems to use it much), so if this is a problem (I'm not sure it is), it's a problem for anything using it. The real lolphp is that the only thing close to a real decimal library in PHP's bundled extensions is a slow arbitrary-base arbitrary-precision backend for `bc` that works directly on text :)<|eor|><|sor|>In that case, you'd expect some kind of error or warning, telling you that your number that works everywhere else in PHP doesn't work here.<|eor|><|sor|>Maybe in the manual. But it's not a library for working with PHP-style numeric strings: it's a library for working with ASCII numbers of arbitrary base and precision.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | MeLoN_DO | 2u48wr | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|eols|><|endoftext|> | 8 |
lolphp | mr-strange | co4yrtk | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>That's perfectly normal in the crazy world of date/time APIs. Can't blame PHP for that one.<|eor|><|eols|><|endoftext|> | 23 |
lolphp | _vec_ | co5smsb | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>[deleted]<|eor|><|sor|>[deleted]<|eor|><|sor|>...except for America which uses Sunday as the first day, despite the rest of our calendar conventions having European Christian roots. Which goes well with our nonsensical standard of writing dates in `mm/dd/YY` format. Because we like making our units as confusing as possible, apparently.<|eor|><|eols|><|endoftext|> | 17 |
lolphp | Wouter10123 | co5nmd7 | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>[deleted]<|eor|><|sor|>[deleted]<|eor|><|sor|>And thus placing half the week*end* right at the beginning of the week. That's some logic for ya. <|eor|><|eols|><|endoftext|> | 9 |
lolphp | MeLoN_DO | co52h4k | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>That's perfectly normal in the crazy world of date/time APIs. Can't blame PHP for that one.<|eor|><|soopr|>I understand it is not PHPs fault that Intl/ICU is weird, but that is still madness. The day identifier shouldnt be locale dependant.<|eoopr|><|sor|>What freaks me out is that the days of the week go from 1..7, rather than 0..6. Now that is a touch of PHP weirdness.<|eor|><|soopr|>That may be weird, by it is ISO, so I can allow that.<|eoopr|><|eols|><|endoftext|> | 9 |
lolphp | MeLoN_DO | co4ykky | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|soopr|>* `IntlDateFormatter::parse` is Locale dependant
* `IntlCalendar::DOW_*` is not ISO-8601.
* `DateTime::createFromFormat` and `strtotime` do not support day of week indices (`DateTime::format` and `date` supports it)<|eoopr|><|eols|><|endoftext|> | 8 |
lolphp | OneWingedShark | co6vrme | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>That's perfectly normal in the crazy world of date/time APIs. Can't blame PHP for that one.<|eor|><|soopr|>I understand it is not PHPs fault that Intl/ICU is weird, but that is still madness. The day identifier shouldnt be locale dependant.<|eoopr|><|sor|>What freaks me out is that the days of the week go from 1..7, rather than 0..6. Now that is a touch of PHP weirdness.<|eor|><|sor|>> What freaks me out is that the days of the week go from 1..7
Not weird.
People don't number their days starting w/ zero, but w/ one.<|eor|><|sor|>It is weird. With computers you count intervals, not values, so when you haven't left the starting gate, how many intervals have you crossed?<|eor|><|sor|>> It is weird. With computers you count intervals, not values, so when you haven't left the starting gate, how many intervals have you crossed?
No, computers don't naturally count intervals (though [you *can*](https://www.lri.fr/~melquion/doc/03-rnc5-expose.pdf), and [some do natively](http://grouper.ieee.org/groups/1788/Material/KirchnerKulisch-HardwareSupport.pdf)) -- this is obvious to anyone who's had even the most elementary introduction to type theory, as a type is defined as:
> a classification identifying one of various types of data, as floating-point, integer, or Boolean, stating ***the possible values for that type, the operations that can be done on that type,*** and the way the values of that type are stored.
(The way the values are stored is more advanced, the intro-level definition will be the bold-italic portion: "valid values and the operations".)
I suspect that your comment stems from using only languages which employ the C-style [0-based index] arrays where the index of an element is the offset... were you exposed to *Pascal* or *Ada* where the starting index can be `1`, or `2`, or `'a'` or `True` you would be less inclined to make that assertion.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | mr-strange | co51l4v | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>That's perfectly normal in the crazy world of date/time APIs. Can't blame PHP for that one.<|eor|><|soopr|>I understand it is not PHPs fault that Intl/ICU is weird, but that is still madness. The day identifier shouldnt be locale dependant.<|eoopr|><|sor|>What freaks me out is that the days of the week go from 1..7, rather than 0..6. Now that is a touch of PHP weirdness.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | OneWingedShark | co58idp | <|sols|><|sot|>The first day of the week is dependant on your Locale, thats good But the number associated with each day is too ???<|eot|><|sol|>http://3v4l.org/bO80c<|eol|><|sor|>That's perfectly normal in the crazy world of date/time APIs. Can't blame PHP for that one.<|eor|><|soopr|>I understand it is not PHPs fault that Intl/ICU is weird, but that is still madness. The day identifier shouldnt be locale dependant.<|eoopr|><|sor|>What freaks me out is that the days of the week go from 1..7, rather than 0..6. Now that is a touch of PHP weirdness.<|eor|><|sor|>> What freaks me out is that the days of the week go from 1..7
Not weird.
People don't number their days starting w/ zero, but w/ one.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | jtgarrison | 1zkbp5 | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|eoss|><|endoftext|> | 7 |
lolphp | _vec_ | cfumtz6 | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|sor|>> You don't need a vps, or shell access.
It's not that hard to find a host that supports more than PHP out of the box. [Heroku](https://www.heroku.com/) is easier than any FTP/cPanel setup I've ever used, and I've used quite a few. If you don't like them, [there](https://developers.google.com/appengine/) [are](https://www.engineyard.com/) [other](http://www.joyent.com/) [options](http://aws.amazon.com/elasticbeanstalk/).
> Everyone here likes making fun of php so much, what do you use in your personal/professional projects?
Ruby, but that's mostly personal preference. Most of this applies equally well to Python or Node.
> If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular.
You're right that this perception is why PHP got popular, but it hasn't been true for a while. Given equivalent levels of skill, I would put good money that someone could build a typical site faster in [sinatra](http://www.sinatrarb.com/) or [express](http://expressjs.com/) than in PHP.
> I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...
Yes you do, you're just a lot more used to it in PHP. Using the filesystem as a routing table isn't actually any easier than writing out route definitions, and it's a hell of a lot less flexible. And templating is either [builtin](http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/ERB.html) or [trivially simple to setup](http://robdodson.me/blog/2012/05/31/how-to-use-ejs-in-express/) in languages with a real module system.
If you're looking to start somewhere, just give sinatra an honest try. I think you'll be pleasantly surprised.<|eor|><|eoss|><|endoftext|> | 16 |
lolphp | cies010 | cfufft2 | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|sor|>I'm using Haskell (harder to learn then Ruby, but worth every drop of sweat), with Yesod (fast and correct web framework that has loads of convenience build in) and Fay (compiles a subset of Haskell to JS for browser consumption).
I'm in love.
You can try Haskel+Yesod from a free browser IDE...
http://www.youtube.com/watch?v=ZHSBwlm5C8U
Awesome.
<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | tinkermake | cfv7mh6 | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|sor|>> but it's just so easy to host php.
as is asp.net, node, and nearly every other backend web targetted language. This was true in the early 2000s, with amazon, azure, etc it is far from true now
> You don't need a vps, or shell access.
You may not need it for pure PHP, but going beyond a trivial wordpress site, you better believe you need it, and another language. Thing is majority nowdays is babyfed by hosts, so people believe it's just a part of the OS and/or language
>Everyone here likes making fun of php so much, what do you use in >your personal/professional projects?
C# mainly, because it has everything I need. Java if it has a library I don't want to port. C++ if i'm feeling masochistic
> If I just need to knock out a quick project, then it's hard to beat php, > which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...
ASP.NET MVC5 with about 5 clicks, you have a full site, with account handling, API, fb/google logins, and more. Just add your own logic on top, and modify as needed.
Node.js from what I know has same exact stuff through NPM<|eor|><|eoss|><|endoftext|> | 9 |
lolphp | catcradle5 | cfusf01 | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|sor|>Python:
* Bottle
* Flask
Ruby:
* Sinatra
* Padrino
* Cuba
You don't have to deal with very much when using any of these microframeworks. You get access to a much, much better language in either case, plus a light framework that's clean and consistent on top of that.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | _vec_ | cfv0ogi | <|soss|><|sot|>PHP Alternatives<|eot|><|sost|>I love the idea of using a different language for web programming, but it's just so easy to host php. You don't need a vps, or shell access. Everyone here likes making fun of php so much, what do you use in your personal/professional projects? If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular. I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...<|eost|><|sor|>> You don't need a vps, or shell access.
It's not that hard to find a host that supports more than PHP out of the box. [Heroku](https://www.heroku.com/) is easier than any FTP/cPanel setup I've ever used, and I've used quite a few. If you don't like them, [there](https://developers.google.com/appengine/) [are](https://www.engineyard.com/) [other](http://www.joyent.com/) [options](http://aws.amazon.com/elasticbeanstalk/).
> Everyone here likes making fun of php so much, what do you use in your personal/professional projects?
Ruby, but that's mostly personal preference. Most of this applies equally well to Python or Node.
> If I just need to knock out a quick project, then it's hard to beat php, which is why it got so popular.
You're right that this perception is why PHP got popular, but it hasn't been true for a while. Given equivalent levels of skill, I would put good money that someone could build a typical site faster in [sinatra](http://www.sinatrarb.com/) or [express](http://expressjs.com/) than in PHP.
> I don't have to deal with routing, templating, boiler plate code (or at least not a whole lot), etc...
Yes you do, you're just a lot more used to it in PHP. Using the filesystem as a routing table isn't actually any easier than writing out route definitions, and it's a hell of a lot less flexible. And templating is either [builtin](http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/ERB.html) or [trivially simple to setup](http://robdodson.me/blog/2012/05/31/how-to-use-ejs-in-express/) in languages with a real module system.
If you're looking to start somewhere, just give sinatra an honest try. I think you'll be pleasantly surprised.<|eor|><|sor|>Oh god and then you have to deal with mod_rewrite where sometimes you just don't know why a certain rule wasn't invoked.
Especially when you have tons of very general rules (if a file is asked for, look for file.php, replace _ with - for SEO purposes, if a folder is not found look for the file in the base folder, failing that go to a different file and ask it to display a user's profile, etc.)
I'll take any sane routing alternative than looking up boolean algebra in wolfram alpha because I want Rule 1 AND (Rule 2 OR Rule 3) but I can't write that in their syntax so I have to use the disjunctive normal form of my rules
PHP is easy. It is not simple.<|eor|><|sor|>> > Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.
>
> -- Brian Moore
>
> bem@news.cmc.net
That's from apache's [official documentation](http://httpd.apache.org/docs/2.0/rewrite/) on `mod_rewrite`.<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | tcsavage | 1zjgwq | <|sols|><|sot|>This caught me out the other day: "NULL" != NULL but "NULL" == 0<|eot|><|sol|>https://eval.in/111361<|eol|><|eols|><|endoftext|> | 6 |
lolphp | lisp-case | cfv3wwl | <|sols|><|sot|>This caught me out the other day: "NULL" != NULL but "NULL" == 0<|eot|><|sol|>https://eval.in/111361<|eol|><|sor|>You've buried the lead.
"NULL" == 0 // this is true
0 == NULL // this is true
"NULL" == NULL // this is false
That last line? *That's* the punchline. It means that `==` doesn't form an [equivalence relation](https://en.wikipedia.org/wiki/Equivalence_relation) (because it's not [transitive](https://en.wikipedia.org/wiki/Transitive_relation)). And that's *horrible*. If equality worked like this in mathematics, math would be broken. In this case, PHP is broken.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | catcradle5 | cfuscu9 | <|sols|><|sot|>This caught me out the other day: "NULL" != NULL but "NULL" == 0<|eot|><|sol|>https://eval.in/111361<|eol|><|sor|>OP, this is because all strings not starting with digits `== 0`. With that context it's not *that* strange.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | tdammers | cfufp15 | <|sols|><|sot|>This caught me out the other day: "NULL" != NULL but "NULL" == 0<|eot|><|sol|>https://eval.in/111361<|eol|><|sor|>Sweet `$deity`, are we still not done bashing the `==` operator?
Short version: friends don't let friends use `==`.
Long version: `==` is OK to use if and only if 1. you are intimately familiar with its coercion rules (which I openly admit are absolutely bat-shit insane), and 2. those rules are exactly what you need/want, or you know the types of your inputs and the resulting behavior is what you need (that's "know" there, not "expect" or "assume" or "have good reason to believe" or "took an educated guess" or "saw it work once"). Of course working under such conditions is ridiculous in and by itself, but hey, this is PHP we're talking about.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | terrorobe | 13yg7j | <|sols|><|sot|>"Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy." - You can guess what came to my mind.<|eot|><|sol|>http://en.wikipedia.org/wiki/Turing_tarpit<|eol|><|eols|><|endoftext|> | 8 |
lolphp | i-am-am-nice-really | j0jac | <|soss|><|sot|>msqli - the whole thing<|eot|><|sost|>WHY for the love of DOG
Object oriented style
object mysqli_result::fetch_object ([ string $class_name [, array $params ]] )
Procedural style
object mysqli_fetch_object ( mysqli_result $result [, string $class_name [, array $params ]] )<|eost|><|eoss|><|endoftext|> | 10 |
lolphp | ealf | gjib3 | <|soss|><|sot|>PHP Fatal error: func_get_args(): Can't be used as a function parameter<|eot|><|sost|>This tells me a bit more than I'd like to know about how function calls are implemented...<|eost|><|eoss|><|endoftext|> | 9 |
lolphp | ealf | c1p3wtz | <|soss|><|sot|>PHP Fatal error: func_get_args(): Can't be used as a function parameter<|eot|><|sost|>This tells me a bit more than I'd like to know about how function calls are implemented...<|eost|><|soopr|>Bonus Guess-the-Output:
call_user_func('func_get_args', 42)<|eoopr|><|eoss|><|endoftext|> | 5 |
lolphp | mozillalives | ewoy9 | <|sols|><|sot|>is_a() deprecated? true and false<|eot|><|sol|>http://us3.php.net/manual/en/function.is-a.php<|eol|><|eols|><|endoftext|> | 8 |
lolphp | shitcanz | cvlfni | <|sols|><|sot|>PHP array design bares fruit<|eot|><|sol|>https://repl.it/repls/FatherlyRotatingMenus<|eol|><|eols|><|endoftext|> | 7 |
lolphp | shitcanz | ey4xmec | <|sols|><|sot|>PHP array design bares fruit<|eot|><|sol|>https://repl.it/repls/FatherlyRotatingMenus<|eol|><|sor|>Sorry, I fail to see what's the problem here.
Maybe the second list is an object instead of an array ?<|eor|><|soopr|>The second list derived from the first is transformed to an object upon json decoding. This is because PHP really has no array, its just hash maps under the hood, and because of how badly array functions work you must do additional work to really get an array back from the filter operation. This is pure lolphp.<|eoopr|><|sor|>Well, PHP is based on C, which doesn't have associative arrays.
In your first line, you have a non-associative array, so json_encode creates an array.
You then use array_filter, which keeps the keys, so you transform you numeric array to an associative one.
json_encode transforms associative arrays to objects as shown in the documentation. If this bothers you to much, you can replace the leading and ending {} with []...
But this is true with other languages too : even JS casts associative arrays to objects : https://stackoverflow.com/questions/4425289/javascript-associative-array-to-json
so **Javascript** object notation casts associative arrays to actual *objects* in Javascript ? And that's lolphp ?<|eor|><|soopr|>WAT? Python, Ruby for example are both built with C. Both have arrays/lists that work like a list.<|eoopr|><|eols|><|endoftext|> | 8 |
lolphp | shitcanz | ey4x7k3 | <|sols|><|sot|>PHP array design bares fruit<|eot|><|sol|>https://repl.it/repls/FatherlyRotatingMenus<|eol|><|sor|>Sorry, I fail to see what's the problem here.
Maybe the second list is an object instead of an array ?<|eor|><|soopr|>The second list derived from the first is transformed to an object upon json decoding. This is because PHP really has no array, its just hash maps under the hood, and because of how badly array functions work you must do additional work to really get an array back from the filter operation. This is pure lolphp.<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | shitcanz | ey4y254 | <|sols|><|sot|>PHP array design bares fruit<|eot|><|sol|>https://repl.it/repls/FatherlyRotatingMenus<|eol|><|sor|>Sorry, I fail to see what's the problem here.
Maybe the second list is an object instead of an array ?<|eor|><|soopr|>The second list derived from the first is transformed to an object upon json decoding. This is because PHP really has no array, its just hash maps under the hood, and because of how badly array functions work you must do additional work to really get an array back from the filter operation. This is pure lolphp.<|eoopr|><|sor|>Well, PHP is based on C, which doesn't have associative arrays.
In your first line, you have a non-associative array, so json_encode creates an array.
You then use array_filter, which keeps the keys, so you transform you numeric array to an associative one.
json_encode transforms associative arrays to objects as shown in the documentation. If this bothers you to much, you can replace the leading and ending {} with []...
But this is true with other languages too : even JS casts associative arrays to objects : https://stackoverflow.com/questions/4425289/javascript-associative-array-to-json
so **Javascript** object notation casts associative arrays to actual *objects* in Javascript ? And that's lolphp ?<|eor|><|soopr|>WAT? Python, Ruby for example are both built with C. Both have arrays/lists that work like a list.<|eoopr|><|sor|>As stated in [JSON reference](https://www.json.org/) and on [W3 Resources](https://www.w3resource.com/JSON/structures.php) :
> JSON supports two widely used (amongst programming languages) data structures.
> A collection of name/value pairs. Different programming languages support this data structure in different names. Like object, record, struct, dictionary, hash table, keyed list, or associative array.
> An ordered list of values. In various programming languages, it is called as array, vector, list, or sequence.
If you have a "value/pair" (associative array), this means you have to use an object to store it (as shown in the different examples).
PHP is following the reference for JSON.
EDIT : and by the way, the [json_decode](https://www.php.net/manual/fr/function.json-decode.php) function has a **JSON_OBJECT_AS_ARRAY** flag, which specifically transforms objects to PHP associative arrays.<|eor|><|soopr|>No. This has nothing to do with JSON. This has all to do with how poor the PHP array design is. The culprit is how bad array_filter really does its thing.
Heres a sample of what you must do as a PHP user to actually get what you wanted in the first place.
https://repl.it/repls/HorribleWeeReality<|eoopr|><|eols|><|endoftext|> | 6 |
lolphp | MazeChaZer | 8ha51c | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|eols|><|endoftext|> | 5 |
lolphp | farsightxr20 | dyi9cqy | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|sor|>I mean, you asked for this behavior by passing "true" as the second argument. Omit that and things work as expected.<|eor|><|eols|><|endoftext|> | 23 |
lolphp | andsens | dyib6bf | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|soopr|>To be honest, this is probably a smaller lolphp, but the fact that they mixed lists and hash maps really grinds my gears. Also, this is just one little example of the many problems I had because of this.<|eoopr|><|sor|>> To be honest, this is probably a smaller lolphp
It really isn't though. Take a look at the various array functions documentation and note how much of their weirdness stems from lists that can have holes in them, indexes that may or may not be strings, sorted but not really sorted dictionaries, all of that needs to be accounted for, and it makes for a horrible experience.<|eor|><|eols|><|endoftext|> | 15 |
lolphp | SaraMG | dyjbkjm | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|sor|>is_array((array)(new stdClass)) === true
OMG, SCANDAL!!!!<|eor|><|eols|><|endoftext|> | 14 |
lolphp | AyrA_ch | dyija7m | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|sor|>I mean, you asked for this behavior by passing "true" as the second argument. Omit that and things work as expected.<|eor|><|soopr|>So as soon as I pass true JSON serialization doesn't work correctly? I know very well what the second parameter does, that's the point of this post -.-<|eoopr|><|sor|>> So as soon as I pass true JSON serialization doesn't work correctly?
No, as soon as you pass true you request an array. Obviously you are going to lose information if the data type is ambiguous. You have to use a custom key to remove the ambiguity: https://3v4l.org/pLds2<|eor|><|eols|><|endoftext|> | 13 |
lolphp | farsightxr20 | dyievs0 | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|sor|>I mean, you asked for this behavior by passing "true" as the second argument. Omit that and things work as expected.<|eor|><|soopr|>So as soon as I pass true JSON serialization doesn't work correctly? I know very well what the second parameter does, that's the point of this post -.-<|eoopr|><|sor|>My point is that they at least foresaw this being an issue, and made the default behavior sensible in light of that.<|eor|><|eols|><|endoftext|> | 12 |
lolphp | Freeky | dyie3il | <|sols|><|sot|>Sure, just use one data structure for both lists and hash maps, what could go wrong?<|eot|><|sol|>https://3v4l.org/R9J4u<|eol|><|soopr|>To be honest, this is probably a smaller lolphp, but the fact that they mixed lists and hash maps really grinds my gears. Also, this is just one little example of the many problems I had because of this.<|eoopr|><|sor|>> this is probably a smaller lolphp
"Smaller" reminded me of [this classic](https://nikic.github.io/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html).<|eor|><|eols|><|endoftext|> | 7 |
lolphp | daxim | 5ym904 | <|sols|><|sot|>PHP syntax is version and context dependent<|eot|><|sol|>http://blogs.perl.org/users/ron_savage/2017/03/off-topic-php-syntax-is-version-context-dependent.html<|eol|><|eols|><|endoftext|> | 7 |
lolphp | nikic | derdcht | <|sols|><|sot|>PHP syntax is version and context dependent<|eot|><|sol|>http://blogs.perl.org/users/ron_savage/2017/03/off-topic-php-syntax-is-version-context-dependent.html<|eol|><|sor|>Oh my god! Are you saying newer language versions allow more syntax?! Who would've thought...<|eor|><|eols|><|endoftext|> | 22 |
lolphp | okamy | der78uw | <|sols|><|sot|>PHP syntax is version and context dependent<|eot|><|sol|>http://blogs.perl.org/users/ron_savage/2017/03/off-topic-php-syntax-is-version-context-dependent.html<|eol|><|sor|>This behaviour is explained in php 5.6 changelog, see constant expression. http://php.net/manual/en/migration56.new-features.php <|eor|><|eols|><|endoftext|> | 18 |
lolphp | bj_christianson | deratje | <|sols|><|sot|>PHP syntax is version and context dependent<|eot|><|sol|>http://blogs.perl.org/users/ron_savage/2017/03/off-topic-php-syntax-is-version-context-dependent.html<|eol|><|sor|>This behaviour is explained in php 5.6 changelog, see constant expression. http://php.net/manual/en/migration56.new-features.php <|eor|><|sor|>Yeah. This is a nonbreaking change in a minor version update. Its not a problem. Its just a fix so that PHP can properly treat the result of an operation on a series of constants as a constant value itself.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | duskwuff | derjlgq | <|sols|><|sot|>PHP syntax is version and context dependent<|eot|><|sol|>http://blogs.perl.org/users/ron_savage/2017/03/off-topic-php-syntax-is-version-context-dependent.html<|eol|><|sor|>You need to declare strict_type for PHP70 and PHP71 to enable type checking<|eor|><|sor|>This has nothing to do with type checking.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | cbraga | 48ud9m | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|eols|><|endoftext|> | 7 |
lolphp | Liorithiel | d0mnswu | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|sor|>Not lolphp. This kind of compiler is pretty common in programming languages. Javascript has several (e.g. [Traceur](https://en.wikipedia.org/wiki/JavaScript#Version_history), [babel.io](https://babeljs.io/)), even early C++ compilers were [just translating into C](https://en.wikipedia.org/wiki/Cfront).<|eor|><|eols|><|endoftext|> | 15 |
lolphp | masklinn | d0r811f | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|sor|>Not lolphp. This kind of compiler is pretty common in programming languages. Javascript has several (e.g. [Traceur](https://en.wikipedia.org/wiki/JavaScript#Version_history), [babel.io](https://babeljs.io/)), even early C++ compilers were [just translating into C](https://en.wikipedia.org/wiki/Cfront).<|eor|><|sor|>It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
Compilation to a completely different language is a pretty different bucket of fish, compiling to object code directly or via C doesn't make much difference (the latter case just tends to be simpler as you don't need to develop and port your codegen to all platforms, GHC can still compile Haskell via C though it's not the default backend).
The point here is that if there is a PHP7 interpreter and you control the server, you can just use that if that's what you want, there's no need for a compiler from 7 to 5.6.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | allthediamonds | d133hxy | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|sor|>Not lolphp. This kind of compiler is pretty common in programming languages. Javascript has several (e.g. [Traceur](https://en.wikipedia.org/wiki/JavaScript#Version_history), [babel.io](https://babeljs.io/)), even early C++ compilers were [just translating into C](https://en.wikipedia.org/wiki/Cfront).<|eor|><|sor|>It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
Compilation to a completely different language is a pretty different bucket of fish, compiling to object code directly or via C doesn't make much difference (the latter case just tends to be simpler as you don't need to develop and port your codegen to all platforms, GHC can still compile Haskell via C though it's not the default backend).
The point here is that if there is a PHP7 interpreter and you control the server, you can just use that if that's what you want, there's no need for a compiler from 7 to 5.6.<|eor|><|sor|>> It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
You can't make all web hosts update their PHP versions either.<|eor|><|sor|>It's 2016. Stop using shared hosting already. It's a terrible idea at a technical level, it basically guarantees you'll get hacked in minutes by virtue of an obsolete stack you can't upgrade, and it's way too expensive.<|eor|><|eols|><|endoftext|> | 7 |
lolphp | nej_simon | d0tokwv | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|sor|>Not lolphp. This kind of compiler is pretty common in programming languages. Javascript has several (e.g. [Traceur](https://en.wikipedia.org/wiki/JavaScript#Version_history), [babel.io](https://babeljs.io/)), even early C++ compilers were [just translating into C](https://en.wikipedia.org/wiki/Cfront).<|eor|><|sor|>It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
Compilation to a completely different language is a pretty different bucket of fish, compiling to object code directly or via C doesn't make much difference (the latter case just tends to be simpler as you don't need to develop and port your codegen to all platforms, GHC can still compile Haskell via C though it's not the default backend).
The point here is that if there is a PHP7 interpreter and you control the server, you can just use that if that's what you want, there's no need for a compiler from 7 to 5.6.<|eor|><|sor|>> It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
You can't make all web hosts update their PHP versions either.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | nej_simon | d0uj7lr | <|sols|><|sot|>Thanks to the PHP 7 to PHP 5.6 Transpiler no one needs to bother with updating their servers. Isn't open source wonderful? ^_^<|eot|><|sol|>https://github.com/jaytaph/Transphpile<|eol|><|sor|>Not lolphp. This kind of compiler is pretty common in programming languages. Javascript has several (e.g. [Traceur](https://en.wikipedia.org/wiki/JavaScript#Version_history), [babel.io](https://babeljs.io/)), even early C++ compilers were [just translating into C](https://en.wikipedia.org/wiki/Cfront).<|eor|><|sor|>It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
Compilation to a completely different language is a pretty different bucket of fish, compiling to object code directly or via C doesn't make much difference (the latter case just tends to be simpler as you don't need to develop and port your codegen to all platforms, GHC can still compile Haskell via C though it's not the default backend).
The point here is that if there is a PHP7 interpreter and you control the server, you can just use that if that's what you want, there's no need for a compiler from 7 to 5.6.<|eor|><|sor|>> It's common in Javascript because as a developer you can't magically make all browsers in the wild implement the new features you're interested in.
You can't make all web hosts update their PHP versions either.<|eor|><|sor|>You can pick your web host. Unless you're using free hosting you can also generally compile a "personal" version of whatever you need, be it PHP or something else.<|eor|><|sor|>**If** you control the hosting, that is. Maybe your client has hosting already set up and you have little control over it? Or maybe youre writing new code for an existing site? Migrating to PHP 7 and possibly a new host is going to be a lot more effort than transpiling some code. And then there is the case when youre writing code for others to use, such as a plugin or theme to some CMS. Requiring PHP 7 will only make it available to the few percents that have upgraded so far. Transpiling may make perfect sense in some cases.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | polish_niceguy | 21ct7x | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|eols|><|endoftext|> | 8 |
lolphp | wung | cgbt3m2 | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>Correct: Why not. The empty string is a valid string. This is a good feature.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | Drainedsoul | cgbwbfl | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>I hate to come to PHP's defense, but this is exceptionally sane behaviour.<|eor|><|eols|><|endoftext|> | 14 |
lolphp | graingert | cgbsopr | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>You can do this with python:
u0_a154@hammerhead:/ $ python
Python 2.7.2 (default, Mar 4 2014, 22:56:02)
[GCC 4.6 20120106 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> main = __import__("__main__")
>>> main
>>> setattr(main,u'',u'lolpython')
>>> getattr(main,u'')
u'lolpython'
>>><|eor|><|eols|><|endoftext|> | 12 |
lolphp | ealf | cgdk3n4 | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>I hate to come to PHP's defense, but this is exceptionally sane behaviour.<|eor|><|sor|>Well, if it was consistent. If you have an object (which is the only way to get a dictionary where you can use strings as keys without having them magically turns into integers during some phases of the moon), this
$x->{""} = 1;
is a *fatal*. Not an exception, mind you.
Which then leaks into other features, like `json_decode('{"_empty_":1,"":2}')`...<|eor|><|eols|><|endoftext|> | 10 |
lolphp | wung | cgbu7s4 | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>Correct: Why not. The empty string is a valid string. This is a good feature.<|eor|><|soopr|>Any reasonable use case?<|eoopr|><|sor|>The use case is just as reasonable as an non-empty string. Of course, it will be horrible to read, having the empty string as constant, but meh.
Constants are defined as a map from string to value. Everything being a valid string thus is a valid constant. Depending on your language, even null may be a valid name. There is no reason to forbid doing so, either.<|eor|><|sor|>Actually, what you may even learn from this is, that regarding the empty string as an invalid string/null/none is bad: The empty string is a valid string. If you need an optional string, use an optional<string>. If your name of something is the empty string, as the user defined it to be so, let it be an empty string.<|eor|><|eols|><|endoftext|> | 9 |
lolphp | wung | cgbu5p1 | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>Correct: Why not. The empty string is a valid string. This is a good feature.<|eor|><|soopr|>Any reasonable use case?<|eoopr|><|sor|>The use case is just as reasonable as an non-empty string. Of course, it will be horrible to read, having the empty string as constant, but meh.
Constants are defined as a map from string to value. Everything being a valid string thus is a valid constant. Depending on your language, even null may be a valid name. There is no reason to forbid doing so, either.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | infinull | cgbwe10 | <|sols|><|sot|>Constant name can be an empty string. Because why not?<|eot|><|sol|>http://codepad.org/J6gYgrc3<|eol|><|sor|>You can do this with python:
u0_a154@hammerhead:/ $ python
Python 2.7.2 (default, Mar 4 2014, 22:56:02)
[GCC 4.6 20120106 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> main = __import__("__main__")
>>> main
>>> setattr(main,u'',u'lolpython')
>>> getattr(main,u'')
u'lolpython'
>>><|eor|><|sor|>that's not quite the same (you're doing attributes, not variables, python doesn't have constants so global variables are as close as you get), but this is closer (IMO)
>>> globals()[''] = 'foobar'
>>> globals()['']
'foobar'
It's likely you could do something even more devious with descriptors (@property) for constantness (or as close as you can get in python)
>>> class Foo(object):
... @property
... def foo(self): return 'foobar'
>>> setattr(Foo, '', Foo.foo)
>>> f = Foo()
>>> getattr(f, '')
'foobar'
>>> setattr(f, '', 'barfoo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
<|eor|><|eols|><|endoftext|> | 6 |
lolphp | vytah | zrljx | <|soss|><|sot|>Guess the output: var_dump(1.0/0.0);<|eot|><|sost|> PHP Warning: Division by zero in - on line 1
bool(false)<|eost|><|eoss|><|endoftext|> | 5 |
lolphp | vytah | c6778up | <|soss|><|sot|>Guess the output: var_dump(1.0/0.0);<|eot|><|sost|> PHP Warning: Division by zero in - on line 1
bool(false)<|eost|><|sor|>How is this weird? I'd expect a division by zero error.<|eor|><|soopr|>But would you expect `1.0/0.0 === false` ?<|eoopr|><|eoss|><|endoftext|> | 11 |
lolphp | poizan42 | c6797qy | <|soss|><|sot|>Guess the output: var_dump(1.0/0.0);<|eot|><|sost|> PHP Warning: Division by zero in - on line 1
bool(false)<|eost|><|sor|>How is this weird? I'd expect a division by zero error.<|eor|><|sor|>I'd expect either Inf or an error - no a warning and false...<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | matjoeman | c676jvs | <|soss|><|sot|>Guess the output: var_dump(1.0/0.0);<|eot|><|sost|> PHP Warning: Division by zero in - on line 1
bool(false)<|eost|><|sor|>How is this weird? I'd expect a division by zero error.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | poizan42 | u06u6 | <|soss|><|sot|>Not a php wtf, but what the hell has happened to the css here?<|eot|><|sost|>Created by nobody, no moderators, every username invisible?
- or more specifically this odd css rule:
.author { display: none }
dafuq?<|eost|><|eoss|><|endoftext|> | 9 |
lolphp | hahainternet | c4r7cyg | <|soss|><|sot|>Not a php wtf, but what the hell has happened to the css here?<|eot|><|sost|>Created by nobody, no moderators, every username invisible?
- or more specifically this odd css rule:
.author { display: none }
dafuq?<|eost|><|sor|>I think the point is to ignore the user and focus on PHP's faults, less discussion, more lolling.<|eor|><|eoss|><|endoftext|> | 17 |
lolphp | ealf | c4rqc8e | <|soss|><|sot|>Not a php wtf, but what the hell has happened to the css here?<|eot|><|sost|>Created by nobody, no moderators, every username invisible?
- or more specifically this odd css rule:
.author { display: none }
dafuq?<|eost|><|sor|>This is a support group for people who use PHP against their will or better judgement. Everyone is welcome, but not everyone is proud to be here. The no-names (css-)rule helps prevent awkwardness when we run into eachother in the outside world.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | suprfsat | c510foi | <|soss|><|sot|>Not a php wtf, but what the hell has happened to the css here?<|eot|><|sost|>Created by nobody, no moderators, every username invisible?
- or more specifically this odd css rule:
.author { display: none }
dafuq?<|eost|><|sor|>I think the point is to ignore the user and focus on PHP's faults, less discussion, more lolling.<|eor|><|sor|>It goes with the theme of The blind leading the blind.<|eor|><|eoss|><|endoftext|> | 8 |
lolphp | samhorwitz | qcic9 | <|sols|><|sot|>Okay so I get these are deprecated timezone strings and whatever, but seriously PHP? You have EST and MST, but not CST and PST? But you do have all four in DST form?<|eot|><|sol|>http://www.php.net/manual/en/timezones.others.php<|eol|><|eols|><|endoftext|> | 7 |
lolphp | Rhomboid | c3wi4f7 | <|sols|><|sot|>Okay so I get these are deprecated timezone strings and whatever, but seriously PHP? You have EST and MST, but not CST and PST? But you do have all four in DST form?<|eot|><|sol|>http://www.php.net/manual/en/timezones.others.php<|eol|><|sor|>CST could mean any of:
- (US) Central Standard Time (UTC-6:00)
- Australian Central Standard Time (UTC+9:30), sometimes spelled ACST but not always
- China Standard Time (UTC+8:00)
PST can mean any of:
- (US) Pacific Standard Time (UTC-8:00)
- Pakistan Standard Time (UTC+5:00)
- Philippine Standard Time (UTC+8:00)
The DST forms of these are not ambiguous, which is probably why they're there when CST and PST are not. EST is also ambiguous with the Australian version so I don't know why it makes the cut when CST doesn't.
But really, none of this matters. You can't go about referring to time zones by an abbreviation, it just doesn't work; it's too error prone. The real lolphp is that **any** of these are supported.
<|eor|><|eols|><|endoftext|> | 12 |
lolphp | ealf | hbryk | <|soss|><|sot|>class X { function f($v) { var_dump($$v); } } $x = new X(); $x->f('this');<|eot|><|sost|><|eost|><|eoss|><|endoftext|> | 7 |
lolphp | ealf | c1u5pok | <|soss|><|sot|>class X { function f($v) { var_dump($$v); } } $x = new X(); $x->f('this');<|eot|><|sost|><|eost|><|soopr|>Buggy perf hack; if `$this` isn't referenced (statically), it's never added to the symbol table. Adding
$this;
or even
if(0) $this;
makes it reappear. `compact()` runs into the same problem.<|eoopr|><|eoss|><|endoftext|> | 5 |
lolphp | rweir | gv3k2 | <|sols|><|sot|>xmlrpc code injection [old but classic]<|eot|><|sol|>http://jerub.livejournal.com/68408.html<|eol|><|eols|><|endoftext|> | 6 |
lolphp | ealf | ejdds | <|sols|><|sot|>PHP doesn't need 'finally' because dropping the exception on the floor "is absolutely equivalent"<|eot|><|sol|>http://bugs.php.net/bug.php?id=32100<|eol|><|eols|><|endoftext|> | 8 |
lolphp | ealf | dtooa | <|soss|><|sot|>There is no super, only static calls that preserve $this<|eot|><|sost|> class A {
function foo() {
if ($this instanceof UnrelatedClass) echo "WTF?";
return $this;
}
}
class Subclass extends A {
function foo() {
return parent::foo();
return A::foo(); // equivalent
}
}
class UnrelatedClass {
function meh() {
return A::foo(); // yep
}
}
$x = new Subclass();
$x->foo(); /* returns $x */
$y = new UnrelatedClass();
$y->meh(); /* returns $y */
<|eost|><|eoss|><|endoftext|> | 7 |
lolphp | Takeoded | 4fn88m | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|eols|><|endoftext|> | 5 |
lolphp | tdammers | d2ab1il | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use `~0`.<|eor|><|soopr|>doesn't make a difference in this code though.<|eoopr|><|sor|>Ah. In that case, it's probably one of those situations where PHP doesn't buy into the idea of useful and consistent error behavior, and the recommended remedy is to just not do the thing you're doing, because clearly you shouldn't be indexing into null, so if you do, it's your own stupid fault.<|eor|><|eols|><|endoftext|> | 21 |
lolphp | tdammers | d2a986p | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use `~0`.<|eor|><|eols|><|endoftext|> | 16 |
lolphp | chimyx | d2bjla9 | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>[Well, it *becomes* an array](https://3v4l.org/RgeLu)<|eor|><|eols|><|endoftext|> | 7 |
lolphp | rinyre | d2agcme | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>Take this a step further with variable variables: https://3v4l.org/49udB
There's no means I can find by which to reference $$a directly, then, as one might typically use variable variables.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Yamitenshi | d2tr5yz | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use `~0`.<|eor|><|soopr|>doesn't make a difference in this code though.<|eoopr|><|sor|>A null variable is like a non existent variable, but not quite. It exists, yet it does not. So you can do whatever the hell you want with it.
https://3v4l.org/rMJh4
[Yeah.](http://i.imgur.com/iTYySIV.png)<|eor|><|sor|>I honestly don't know why people are tripping up over this - think of `null` in PHP as you would of `void` in C, or `undefined` in JavaScript. The variable is there, but it *holds no value, and has no type*. It's a reference to a not-yet-initialized variable, and assigning a value to it initializes the variable with the type you give it - you can do whatever you want with it in the same way that you can do everything you want with a newly-defined variable.
There's a reason `isset()` returns false when you're passing it something set to `null`.
I'll be the first to admin PHP has definite flaws and quirks that should never have been there in the first place. This is not one of them.<|eor|><|sor|>The main issue here, for me, are the shenanigans with typing. NULL == FALSE == 0. So, an [empty](http://php.net/manual/en/function.empty.php) variable is NULL, FALSE, 0, and non-existent at the same time. Which is it?
And why the fuck an non-existent variable can be empty?! It doesn't exists, and can't be anything! Also, [isset](http://php.net/manual/en/function.isset.php) doesn't consider a null variable as set (so, does it exists or not?). But wait! If that variable is false, it will be considered set. However, null is equal to false... So which one is it?
The triple = BS is really tiring.<|eor|><|sor|>> NULL == FALSE == 0
Yes, this is a weakly typed language. In the same vein, "yes" == true, "no" == true, but "yes" != "no".
> an empty variable is NULL, FALSE, 0, and non-existent at the same time
No, an empty variable is one that is either not defined or evaluates to false. `empty($var)` is nothing more than shorthand for `!isset($var) || !$var`.
> isset doesn't consider a null variable as set (so, does it exists or not?)
It *exists*, but is not *set* to a value. `int foo;` in C does something very similar.
> But wait! If that variable is false, it will be considered set. However, null is equal to false
Yes, equal, but not identical. Weak typing, remember?
> The triple = BS is really tiring
It's a necessity in a weakly typed language if you don't want to do `$a == $b && typeof($a) == typeof($b)` every time. This is not "lolphp", this is weak typing. *Everything you've raised is more or less inherent to weak typing*.
Again, PHP has definite flaws and clear indications of bad design. This is not one of them.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | Takeoded | d2a9m2m | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>E_ALL means "report many kinds of errors, but not all". If you want "actually literally all kinds of errors, then in my experience your best bet is to use `~0`.<|eor|><|soopr|>doesn't make a difference in this code though.<|eoopr|><|eols|><|endoftext|> | 5 |
lolphp | foobar5678 | d2at1yq | <|sols|><|sot|>can somebody explain this shit?<|eot|><|sol|>https://3v4l.org/2QoD6<|eol|><|sor|>PHP lets you implicitly create arrays if there's no such variable or it is set to `null`. This is arguably quite useful, it's more convenient than manually creating each dimension yourself.<|eor|><|sor|>But how do you even know if a variable is "really" set? Because apparently PHP has 3 states: set, notset, and null.
https://3v4l.org/EYUif
If it's not set, then you get a notice because it's not set
If it's set to null, then you don't get errors for it not being set, but isset() still returns FALSE
Nothin wrong with implicit variable creation, but I don't want my code littered with notices.<|eor|><|eols|><|endoftext|> | 5 |
lolphp | shitbangs | 2cu90d | <|sols|><|sot|>Was trying to implement ArrayAccess, then this happened<|eot|><|sol|>http://imgur.com/2woBLlF<|eol|><|eols|><|endoftext|> | 7 |
lolphp | shitbangs | cjj2vie | <|sols|><|sot|>Was trying to implement ArrayAccess, then this happened<|eot|><|sol|>http://imgur.com/2woBLlF<|eol|><|soopr|>Without reading the source, this is what seems to be happening:
Array offsets are converted to integer if they're considered numeric, while object property specifiers are always converted to string. So the first line could've been:
$x = (object)["0" => false];
This does exactly the same thing, and the object is created with a numbered property. In the second line, the property specifier is converted to a string and that property doesn't yet exist so it's added to the object. If you do
echo count($x);
The output will be 2. So how *do* you access a numbered property? Welp, *you don't* and *it's a [WONTFIX](https://bugs.php.net/bug.php?id=45959)*.<|eoopr|><|eols|><|endoftext|> | 10 |
lolphp | jrh3k5 | cjj3kzi | <|sols|><|sot|>Was trying to implement ArrayAccess, then this happened<|eot|><|sol|>http://imgur.com/2woBLlF<|eol|><|soopr|>Without reading the source, this is what seems to be happening:
Array offsets are converted to integer if they're considered numeric, while object property specifiers are always converted to string. So the first line could've been:
$x = (object)["0" => false];
This does exactly the same thing, and the object is created with a numbered property. In the second line, the property specifier is converted to a string and that property doesn't yet exist so it's added to the object. If you do
echo count($x);
The output will be 2. So how *do* you access a numbered property? Welp, *you don't* and *it's a [WONTFIX](https://bugs.php.net/bug.php?id=45959)*.<|eoopr|><|sor|>> Fixing that implies a perfomance decrease, hence the better seems be keep it as an known issue, but documented.
Beautiful.<|eor|><|eols|><|endoftext|> | 8 |
lolphp | OneWingedShark | cjj4i73 | <|sols|><|sot|>Was trying to implement ArrayAccess, then this happened<|eot|><|sol|>http://imgur.com/2woBLlF<|eol|><|soopr|>Without reading the source, this is what seems to be happening:
Array offsets are converted to integer if they're considered numeric, while object property specifiers are always converted to string. So the first line could've been:
$x = (object)["0" => false];
This does exactly the same thing, and the object is created with a numbered property. In the second line, the property specifier is converted to a string and that property doesn't yet exist so it's added to the object. If you do
echo count($x);
The output will be 2. So how *do* you access a numbered property? Welp, *you don't* and *it's a [WONTFIX](https://bugs.php.net/bug.php?id=45959)*.<|eoopr|><|sor|>> Fixing that implies a perfomance decrease, hence the better seems be keep it as an known issue, but documented.
Beautiful.<|eor|><|sor|>>> Fixing that implies a perfomance decrease, hence the better seems be keep it as an known issue, but documented.
>
>
> Beautiful.
You know what else implies a performance decrease? Iteration.
I therefore propose the following fix to the `foreach`-loop: all statements inside the loop's scope are executed exactly once. This has the benefit of (a) altering the performance from **O(n)** to **O(1)**, _and_ (b) finally solving the [penultimate-item duplication](http://www.reddit.com/r/lolphp/comments/23oe47/L/ch0fuln) bug.
Seriously, stuff like these wontfix bugs make me wonder why anyone would see PHP as a viable solution in the business world.<|eor|><|eols|><|endoftext|> | 6 |
lolphp | aleczapka | 1bxjfk | <|soss|><|sot|>Hmm.. shouldn't is_array() check for instanceof ArrayAccess ?<|eot|><|sost|>I find it kinda odd that is_array() does not check for instance of ArrayAccess. If you introduce collection like object in your code, you gotta recheck all of in_array() usage and change it to:
if (is_array($input) || $input instanceof \ArrayAccess) {
And since the purpose of the ArrayAccess interface is '_to provide accessing objects as arrays_' , shouldn't is_array() return true?
I know that my $input in that case is object, that's why is_array() returns false, but isn't that kinda 'logical' error?
The only reason I am using is_array() on an array/variable, is cause there is no other way to tell if I can run array related functions on it, aka if it fulfills the contract of ArrayAccess so I can access it as an array.
The information that actually it is an object or not, is secondary/irrelevant at this point to me.
_Edit_: forgot to add context, here it is:
if (is_array($input) || $input instanceof \ArrayAccess) {
array_walk_recursive($input, [$this,'sanitizeInputToken']);
return $input;
}
Please note guys, I am not looking on how to solve this particular 'problem'.
A wrapper method comes to mind or what not. I am just puzzled by PHP behaviour in that case.
Anyways thanks all for posting!<|eost|><|eoss|><|endoftext|> | 6 |
lolphp | martindines | c9b3put | <|soss|><|sot|>Hmm.. shouldn't is_array() check for instanceof ArrayAccess ?<|eot|><|sost|>I find it kinda odd that is_array() does not check for instance of ArrayAccess. If you introduce collection like object in your code, you gotta recheck all of in_array() usage and change it to:
if (is_array($input) || $input instanceof \ArrayAccess) {
And since the purpose of the ArrayAccess interface is '_to provide accessing objects as arrays_' , shouldn't is_array() return true?
I know that my $input in that case is object, that's why is_array() returns false, but isn't that kinda 'logical' error?
The only reason I am using is_array() on an array/variable, is cause there is no other way to tell if I can run array related functions on it, aka if it fulfills the contract of ArrayAccess so I can access it as an array.
The information that actually it is an object or not, is secondary/irrelevant at this point to me.
_Edit_: forgot to add context, here it is:
if (is_array($input) || $input instanceof \ArrayAccess) {
array_walk_recursive($input, [$this,'sanitizeInputToken']);
return $input;
}
Please note guys, I am not looking on how to solve this particular 'problem'.
A wrapper method comes to mind or what not. I am just puzzled by PHP behaviour in that case.
Anyways thanks all for posting!<|eost|><|sor|>I've come across this before and, however inconvenient, it is logical.
is_array checks specifically for *type.* Similar to is_string & __toString.
If is_array was to accept decorated objects as you described then testing for true arrays would be even more hacky; !is_object? Wat.
Without knowing how you are trying to use is_array its hard to provide a decent solution. I would probably create a utility is_iterable or is_traversable .. you get the idea.<|eor|><|eoss|><|endoftext|> | 10 |
lolphp | ioctl79 | c9bel45 | <|soss|><|sot|>Hmm.. shouldn't is_array() check for instanceof ArrayAccess ?<|eot|><|sost|>I find it kinda odd that is_array() does not check for instance of ArrayAccess. If you introduce collection like object in your code, you gotta recheck all of in_array() usage and change it to:
if (is_array($input) || $input instanceof \ArrayAccess) {
And since the purpose of the ArrayAccess interface is '_to provide accessing objects as arrays_' , shouldn't is_array() return true?
I know that my $input in that case is object, that's why is_array() returns false, but isn't that kinda 'logical' error?
The only reason I am using is_array() on an array/variable, is cause there is no other way to tell if I can run array related functions on it, aka if it fulfills the contract of ArrayAccess so I can access it as an array.
The information that actually it is an object or not, is secondary/irrelevant at this point to me.
_Edit_: forgot to add context, here it is:
if (is_array($input) || $input instanceof \ArrayAccess) {
array_walk_recursive($input, [$this,'sanitizeInputToken']);
return $input;
}
Please note guys, I am not looking on how to solve this particular 'problem'.
A wrapper method comes to mind or what not. I am just puzzled by PHP behaviour in that case.
Anyways thanks all for posting!<|eost|><|sor|>Arrays have a lot of properties that ArrayAccess objects are not required to implement (iteration, for example). As such, it makes a lot more sense to turn this around, and make "array() instanceof ArrayAccess" evaluate as true. That way, you can typehint function parameters as "something I can use [] on", without caring whether it is an object, or an array. Ditto for "Iterable".<|eor|><|eoss|><|endoftext|> | 6 |
lolphp | huf | n4pur | <|soss|><|sot|>guess what var_dump(unset($a)); outputs...<|eot|><|sost|><|eost|><|eoss|><|endoftext|> | 6 |