Author Topic: Fuck you PHP!  (Read 18260 times)

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Fuck you PHP!
« on: October 28, 2015, 01:00:08 PM »
I love finding more examples of PHP's consistent inconsistencies!

Two from work that we ran into:
Code: [Select]
php > set_error_handler(function($errno, $errstr) { print_r([$errno, $errstr]); });
php > $f->foo;
Array
(
    [0] => 8
    [1] => Trying to get property of non-object
)
php > $f->get('foo');

Fatal error: Call to a member function get() on null in php shell code on line 1

We ran into that one where for some reason a variable was null and I had recently change it from directly accessing a property to using the getter method.  This caused some users to see a non-fully rendered page because of the error.  And we didn't get an email about it because it doesn't fucking call the error handler!

Another one that I can't blame solely on PHP but was still annoying.  One of our programmers was doing `floatval(number_format($foo, 2))` to round instead of just doing `round()` and for some reason I didn't catch it in review.  But, that produces a nice error if the number is 1000 or more

Code: [Select]
php > $price = "1012.19";
php > echo number_format($price, 2);
1,012.19
php > echo floatval(number_format($price, 2));
1
php >

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Fuck you PHP!
« Reply #1 on: October 28, 2015, 02:28:19 PM »
aw, I think they add character.  Its like a cute little language.

I love trying to remember if a function is one-word or has an underline in it.  Like isset() or is_null()
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #2 on: November 17, 2016, 07:07:52 PM »
Another fun one we found:


php 
print_r((array) false);
Array
(
    [
0] =>
)
php print_r((array) null);
Array
(
)
php >


Seriously, FU PHP

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14337
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Fuck you PHP!
« Reply #3 on: November 18, 2016, 09:33:25 AM »
Sometimes I enjoy that I use Java in my 9-5.  Sometimes.  Certainly not all the times.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Fuck you PHP!
« Reply #4 on: November 18, 2016, 10:52:53 AM »
I'm sure it makes sense at some level.

like false returns a boolen 0 and null mean nothing.  I'm sure someone would argue that that is expected behavior.

"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #5 on: November 18, 2016, 01:43:21 PM »
Ewww Java.  We are transitioning to Python (our new software is Python based) and I love it.  You know what Python does in those cases?  Throws an exception because False and None (aka null) aren't iterable.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14337
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Fuck you PHP!
« Reply #6 on: November 18, 2016, 01:52:12 PM »
Java ain't bad.  It does things better than PHP in several cases.

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #7 on: November 18, 2016, 02:33:52 PM »
That's a pretty low bar :P

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3539
  • Karma: +46/-18
Re: Fuck you PHP!
« Reply #8 on: November 18, 2016, 03:13:37 PM »
@ober, move to coding in Groovy and you'll probably enjoy Java more. It's basically Java without semi-colons, and a few really nice syntax sugar bits.

I've really begun to love Python the more and more I play with it and learn about it. I wish I could switch to it for my day job.
This signature intentionally left blank.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Fuck you PHP!
« Reply #9 on: November 18, 2016, 03:18:54 PM »
what kind of app/software are you guys working on now adays anyway with all your java and python tomfoolery.

I live in PHP because everything for me is web apps and web sites. Not much heavy lifting stuff going on or rendering anything that's not being sent to a web browser.
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14337
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Fuck you PHP!
« Reply #10 on: November 18, 2016, 03:34:06 PM »
@tgm What do you have against semicolons?  :)  I really don't mind Java.  Especially now that we're jumping up to Java 8.  6 was a little more painful.  Next step is to start bringing more external libraries in.  We'll get there.  We move kinda slow because we're in a regulated industry and we have a massive codebase.

@micah - My 9-5 stuff is a SaaS web platform in the clinical trial industry.  Java as the backend, JSTL/JSP as the front end.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3539
  • Karma: +46/-18
Re: Fuck you PHP!
« Reply #11 on: November 18, 2016, 06:59:47 PM »
The root of many evils is a misplaced semi-colon.
This signature intentionally left blank.

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #12 on: November 19, 2016, 02:03:42 AM »
what kind of app/software are you guys working on now adays anyway with all your java and python tomfoolery.

I live in PHP because everything for me is web apps and web sites. Not much heavy lifting stuff going on or rendering anything that's not being sent to a web browser.

The Python app acts as a RESTful API to the front end which will eventually replace our legacy system.  Additionally, we have it running as an intermediary between our legacy system and our cXML vendors.  And it is working as an intermediary between our new SIS vendor and our legacy system.  For the front end we are looking at using Angular 2 as a JS framework and essentially building a JS application that uses the REST backend provided by Python.

We started doing the split backend / frontend road last year before we pivoted our long term approach and are just now getting back to it.  But what we did discover is that it rocks!  Everything is cleanly separated and the APIs tend to do smaller operations that are specific.  And you can totally change the front end without the backend code getting involved.

We also started using jade to build the HTML for the front end and that was pretty awesome (once you got used to it).  Building HTML was super fast and you didn't have to worry about missing closing tags.

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #13 on: November 23, 2016, 03:55:13 PM »
So this one isn't a PHP issue but it was written into our legacy system which is written in PHP.  In the system there is a "There are XYZ others online" which is suppose to give you a count of how many others users have been active within a certain amount of time.  We have a table with a datetime column called LastActive that gets update with each page hit.  So the query does a count with the condition `WHERE NOW() - LastActive < (55 * 60)`.  So immediate thought is "whats the units of that?  Looks like 55 minutes".  Last night we did some maintenance and were checking to make sure the system was quiet and the counter was showing a very different number from our own database queries.  Turns out subtracting two datetimes like the query does is completely worthless.  Here is the output that proved it to me:

Code: [Select]
+---------------------+---------------------+--------------------+
| LastActive          | NOW()               | NOW() - LastActive |
+---------------------+---------------------+--------------------+
| 2016-11-22 21:59:59 | 2016-11-22 22:25:40 |               6581 |
| 2016-11-22 22:00:00 | 2016-11-22 22:25:40 |               2540 |
+---------------------+---------------------+--------------------+

So one second difference in LastActive but thousands different in the result.

Well, I figured out why.

Take `2016-11-22 21:59:59` and `2016-11-22 22:25:40` and remove all non-numeric characters. from each.  You know have `20161122215959` and `20161122222540` which you now do the math on.  Giving you 6581.

Even before I figure that out I ended up changing the query to the much more sane `WHERE LastActive >= NOW() - INTERVAL 15 MINUTE`

Mike

  • Jackass In Charge
  • Posts: 11270
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Fuck you PHP!
« Reply #14 on: June 28, 2018, 06:38:32 PM »
Yet more PHP hate:


php 
> echo (int) '124hello845';
124


Seriously, fuck you PHP.