Someone wants to help me build a site!
-
So in my spare time, I've had a project thrust upon me that needs a site built. As a PHP guy, I figured, sure. I'll help. So they gave me FTP credentials to have a look. Of course, this "framework" is some of the shittiest code I've ever seen. Those of you who have had the displeasure of having to work with legacy PHP code will appreciate the following:
$ grep -r 'error_reporting(0)' | wc -l 26
Can someone please brexit my life for me right now? I'm not even being paid for this. :(
-
@toon said in Someone wants to help me build a site!:
So in my spare time, I've had a project thrust upon me that needs a site built. As a PHP guy, I figured, sure. I'll help. So they gave me FTP credentials to have a look. Of course, this "framework" is some of the shittiest code I've ever seen. Those of you who have had the displeasure of having to work with legacy PHP code will appreciate the following:
$ grep -r 'error_reporting(0)' | wc -l 26
Can someone please brexit my life for me right now? I'm not even being paid for this. :(
OK, I'm not a PHP dev, but just from context, is this essentially the equivalent of
on error resume next
in 26 different places in the site?
-
@masonwheeler said in Someone wants to help me build a site!:
is this essentially the equivalent of
on error resume next
in 26 different places in the site?Not really, it just tell PHP to not report any error. So at worst (like Fatal run-time errors) you will get a blank page, with no log to tell you what went wrong.
-
@TimeBandit said in Someone wants to help me build a site!:
@masonwheeler said in Someone wants to help me build a site!:
is this essentially the equivalent of
on error resume next
in 26 different places in the site?Not really, it just tell PHP to not report any error. So at worst (like Fatal run-time errors) you will get a blank page, with no log to tell you what went wrong.
Wow, way to go PHP. You've come up with something even worse than
on error resume next
!
-
@masonwheeler said in Someone wants to help me build a site!:
Wow, way to go PHP. You've come up with something even worse than
on error resume next
!Not really. For example, if you try to open a file that doesn't exist, it will die.
In VB (with 'on error resume next'), it will fail, then continue. So next you'll try to append something to the file (which will fail), then close it (which will also fails). Then the code assume everything went well.on error resume next should have never existed.
If I was @toon , I would remove all those and see what happen.
Better fix whatever error pops up and be done with it.
-
@TimeBandit I agree that in this case facing the messages is best. A lot of the messages will likely be Notice: Undefined index:
-
@toon how many
@
s are there?
-
@TimeBandit said in Someone wants to help me build a site!:
on error resume next should have never existed.
PHP's errors should have never existed either. Every single statement may or may not cause messages a user should never see to be written to STDOUT. Bonus points if that happens before the headers are sent. Oh, and the actual behavior of your code depends on an .ini setting and/or the current error reporting level set via
error_reporting()
and/or the presence of the@
operator, which is both the most idiotic operator ever and for some reason a performance problem and therefore shouldn't be used.The only reasonable way to deal with them is to convert them into exceptions:
function exception_error_handler($severity, $message, $file, $line) { if (!(error_reporting() & $severity)) { // This error code is not included in error_reporting return; } throw new ErrorException($message, 0, $severity, $file, $line); } set_error_handler("exception_error_handler");
(Source: http://php.net/manual/en/class.errorexception.php#errorexception.examples)
-
@asdf Of course, that doesn't help you with those wonderful E_STRICT notices, which bypass the user-defined error handler. Because fuck you, that's why.
-
@TimeBandit said in Someone wants to help me build a site!:
In VB (with 'on error resume next'), it will fail, then continue. So next you'll try to append something to the file (which will fail), then close it (which will also fails). Then the code assume everything went well.
Just like C if you dont check the return value of every fucking thing.
That's what disappointed me with got, the lack of exceptions.
-
@asdf said in Someone wants to help me build a site!:
the
@
operator, which is both the most idiotic operator ever and for some reason a performance problem and therefore shouldn't be usedThat's… “special”.
-
@fbmac said in Someone wants to help me build a site!:
Just like C if you dont check the return value of every fucking thing.
Small rant: AAARRGRGHRGHGHGHGHGH! You are so right. And the most common reason not to use exceptions is "exception safety is hard".
You're right. Exception safety is hard. You know what else is hard - every other form of error recovery. Equally hard, in fact, because to correctly check ever C error, correctly release resources and safely propagate the error to the point where it can be handled is EXACTLY THE SAME PROBLEM AS EXCEPTION SAFETY. Literally the same problem.
Only in C (and no Go) you have the added bonus that you have to do it by hand, every single time, in every single function that could conceivably have an error (and that means you can't return a sensible type from most functions, you must return an error code and pass pointers around to store the result in).
So when people complain about complex non-local returns and complex code paths with exceptions they mean - "Exception handling gives me problems that I simply don't get in C, because in C its easier to not give a shit about handling errors in complex code".
-
the @ operator, which is both the most idiotic operator ever and for some reason a performance problem and therefore shouldn't be used
That's… “special”.
Basically, a silenced statement like the following
@foo($bar);
is treated exactly like
$level = error_reporting(0); foo($bar); error_reporting($level);
Those calls to error_reporting are pretty expensive, since they read the error-reporting-related INI settings. See the actual implementation on Github.
-
@asdf said in Someone wants to help me build a site!:
Those calls to error_reporting are pretty expensive
That's doubly “special”. Not only is PHP on the short bus, but so are its developers.
-
@asdf said in Someone wants to help me build a site!:
PHP's errors should have never existed either.
PHP is an error. It was built as a couple CGI programs to maintain a Personal Home Page.
@asdf said in Someone wants to help me build a site!:
@asdf Because fuck you, that's why.
That's PHP's favorite phrase !
-
@gwowen said in Someone wants to help me build a site!:
And the most common reason not to use exceptions is "exception safety is hard".
It's hard for the 3 guys who design the language. It's easy for the 50,000,000 guys who use it.
Those priorities are pretty out-of-whack.
-
@blakeyrat said in Someone wants to help me build a site!:
It's hard for the 3 guys who design the language.
Especially if they're all morons. Which as it's PHP is what the real problem is.
-
@bb36e I found 25 instances, excluding legitimate uses such as doc comments and stuff. I also decided to exclude Smarty, because I happen to know that those guys use the @ operator deliberately as a way of writing code that's dirty, but optimized for speed. For instance, if in benchmarking, they find that checking if a file exists and then getting the mtime, is slower than just getting the mtime with an
@
, then they'll go for the@
.
-
@TimeBandit yeah, I did in fact remove them first thing, I was getting white screens with no clue why. Quickly set
error_reporting
toE_ERROR | E_WARNING
though. Choose your battles and such...
-
@toon said in Someone wants to help me build a site!:
For instance, if in benchmarking, they find that checking if a file exists and then getting the mtime, is slower than just getting the mtime with an @, then they'll go for the @.
To be fair, that's possibly the right thing to do for other reasons too. There's a race condition between the test whether the file exists and what the mtime is, and that's avoided by instead just handling the error that occurs when the file doesn't exist. Doing the existence check first is an anti-pattern since it doesn't actually make your code any safer; the actual failure modes are identical.
-
Fun fact, part of what they're doing in the realms beyond PHP 7 is actually moving away from this bullshit warning-to-STDOUT behaviour and emitting all the things as ErrorExceptions.
-
@blakeyrat said in Someone wants to help me build a site!:
It's easy for the 50,000,000 guys who use it.
not in c++, where the world was divided into exception aware and unaware code and you get memory leaks when you mix both
-
@candlejack1 said in Someone wants to help me build a site!:
not in c++, where the world was divided into exception aware and unaware code and you get memory leaks when you mix both
That's because C++ has been a fustercluck for a long time. Maybe getting better now, but there's a massive overhang of problematic code to deal with and having to rebuild all that stuff is A Ridiculous Suggestion that won't ever happen. (Seriously, hardly anyone in the history of ever has thought that rewriting tens of billions of lines of code is a good plan. At that scale, bodging around the problems becomes the order of the day.)