Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
base system
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 Nov 2006 at 02:08 UTC
Updated:
6 Feb 2007 at 19:30 UTC
I had started a run of patches to make Drupal 5 E_ALL compliant, and did the attached patch. And then wept in the corner for an hour and a half.
Next release, let's do this right. Let's commit this to 6.x-dev day one of the code thaw and code this stuff right once and for all.
| Comment | File | Size | Author |
|---|---|---|---|
| view-notices.patch | 818 bytes | webchick |
Comments
Comment #1
webchickBtw, to clarify my intent here.
I don't advocate shipping Drupal 6.0 with watchdog spitting out errors for notices on production sites. I do, however, strongly advocate turning on E_ALL checking during the development cycle of 6.0, because then it avoids poor souls like me having to roll 1,000 patches at the end of the release cycle to pick them up. :P
If this option was turned on at the beginning of the code thaw, notices would be picked up at the time patches are rolled and not after the fact. For betas/RCs/releases, it could be switched back to ^ E_NOTICE.
Comment #2
Crell commented+1 Amen!
Comment #3
webchickI was asked the other day, "Why should we bother with E_ALL compliance?"
Here are some reasons:
I'm sure there are other reasons, and others can add to this thread. There really isn't a reason _not_ to enable this. I've heard others refer to "code bloat" but most of this is due to sticking issets() everywhere rather than fixing the problem at the cause: ensuring all forms, nodes, etc. have a standard set of properties with reasonable default values.
Comment #4
webchickhttp://drupal.org/node/100249 is a shining example of a bug that needn't have been a bug, if only we were properly initializing variables like coding to E_ALL standards would require. :)
Comment #5
lyricnz commentedI've submitted quite a few e_notice patches over the last couple of weeks, but get a bit frustrated when they get ignored. I *know* it makes the code a bit more ugly, with lots of: if(isset(xxx)) etc, and ?: logic. It's certainly embarassing when Drupal creates such a mess with e_notice enabled.
Comment #6
Crell commentedJust earlier tonight I was in #Drupal_Support and someone came in to ask "Why am I getting all of these extra errors when I moved a site from sandbox to dev server?" The reason was his dev box was set for E_ALL, and Drupal setting itself to E_ALL & !E_NOTICE internally doesn't work in my experience. You have to set it to an obscure number in the .htaccess file. I know because I had to figure out what the corresponding number is for our own dev box at work, which is also set to E_ALL. As soon as he dropped that line into his .htaccess it worked fine.
Setting a dev environment to "pendantic" is recommended in every language. In C/C++, you set your compiler to treat errors as warnings. In PHP, you set error reporting to E_ALL. Same idea.
E_ALL compliance in core means we're compatible with more possible server configurations.
As for making the code uglier, only if you do all your checking late. :-) At work we have default-value input filters for all input that takes a default, similar to variable_get() in Drupal. Internally it just does the usual ternary, plus some type checking, but the resulting code where it's used is quite clean. If you just throw isset()s around, then yes, the code gets ugly and harder to maintain. That's why you structure the code to not need such ugliness, which makes it easier to read as well as more robust. Score. :-)
Comment #7
Paul Natsuo Kishimoto commentedHuge +1
@lyricnz —
empty()is less ugly thanisset()to me, and more useful some cases. I completely agree that 'ugly' code is a small price to pay for being E_ALL compliant. Perhaps you can close your other patches, and repost them here?@webchick — is that an appropriate practice (ie. posting many small related patches to one issue, and having someone in charge of committing them)? Who's in charge?
Comment #8
webchickSide note: isset() is actually faster than empty(), since it's a native construct.
@Paul: The general preference is to break patches up so they fix single problems. So for example, "Fix all E_ALL errors in system.module." Rolling them all into one gargantuan patch means the patches are harder to review, inconsistencies they cause are less likely to be found, and the length of time to get the changes in is longer. So please DON'T post a mega patch to this issue: this issue is only about removing E_ALL suppression in core to help ensure that these errors are caught early (and lobbying for/against this change). Instead, post smaller, individual patches to the queue with the subject line: "E_ALL compliance: description of patch" so they are easily searchable.
As far as committing goes, there are only a handful of members who may commit patches to Drupal (Dries and Steven, plus killes on 4.7.x and drumm on 5.x). The rest of us work to get the patches in by rolling, reviewing, rallying behind, and testing them.
Comment #9
owen barton commented@webchick - isset() and empty() perform identically: http://www.php.lt/benchmark/phpbench.php
Also, !isset() is not the functionally the same as empty(), since an initialized empty string will return false for !isset() but true for empty(). Hence I think the main consideration should be what functionality is actually needed!
Comment #10
ergophobe commentedFirst, THANKS webchick for getting up on your high horse since I was just about to call mine in from pasture on this same issue.
Drupal 4.7 has been causing havoc on my shared server, hogging MYSQL resources, so I thought I would enable the devel module and do XDebug and do some profiling. As soon as I enabled devel, I got Notices by the hundreds. I straightened them out for the views.module and then it went right on to the next module, spitting out notices left and right. Frustrating since I totally agree with points 1-3 and normally I refuse to run any script that isn't E_ALL compliant because it's often a symptom of other underlying problems.
As for isset vs empty, use isset if simply checking that something is set, use empty if you want want to also know whether it is set and set/not set to a zero or zero-length string.
Comment #11
ChrisKennedy commentedI have a preliminary patch to remove all the E_ALL notices I could find while installing: http://drupal.org/node/103250
Comment #12
kkaefer commented+1 on this. It's probably the only way to enfore E_ALL compliance. And there *are* issues caused by sloppy coding (for example http://drupal.org/node/48178).
Comment #13
sime+1
Big benefits, and something that gets easier with time, and continues to improve our coding skills.
Looking at the patch though, to manually turn off E_ALL, the developer has to hack common.inc?? Would it be kosher for a variable to be set in settings.php? The problem is using contrib modules under a deadline, or where the maintainer is not responsive to E_ALL compliance patches.
Comment #14
chx commentedYes this will lead to eventual minor code bloat and yet this is a must to upkeep the high quality of Drupal code. In general, we do not hack just because it'd be smaller, we cherish quality code instead. The price to pay here will be very small so +1.
Comment #15
Crell commentedsime: Making the error level compatibility of Drupal configurable is a very bad idea. You could develop something under a very loose setting (because you didn't want to be bothered when just playing around with something), then forget to tighten it again before uploading. Bam, you just uploaded code that will break for someone with E_ALL & !E_NOTICE (Drupal's current level), to say nothing of proper E_ALL.
By setting Core to E_ALL and leaving it there, it means that developers building modules will get ugly messages thrown in their face while developing until they make their code E_ALL compliant. That means there's no excuse for not writing E_ALL compliant modules, whereas right now it's actually harder to write E_ALL modules because you can't enable E_ALL error reporting without making Core flip out completely.
(Part of me wants to go as far as saying use E_ALL | E_STRICT on PHP 5, but there would be a performance hit for checking the version, most of the E_STRICT stuff is on classes which we don't use anyway, and I don't want to bog down this discussion as happens to too many small-but-good ideas.)
+1 to E_ALL in common.inc, and let module authors do the right thing.
Dries, can we get some weigh-in from you please? :-)
Comment #16
kkaefer commentedContrib maintainers will have to become responsive to E_ALL notices because they are now displayed on every single page.
Comment #17
webchickBumping the priority of this to critical... there seems to be lots of consensus here, and the earlier this is committed to HEAD the better.
Comment #18
sime@Crell
Understood, but as long as we recognize that hacking core will be necessary if we want to use some modules. There are two other situations where our control is not absolute:
1) People developing modules on servers that don't allow php.ini / htaccess overrides. They might be blissfully unaware of the problems others face with their code in an E_ALL environment.
2) Slack maintainers will also learn that if Drupal sets E_ALL, that they can set it back again within their modules.
Sorry if I've got some of my technical details wrong (at least I don't think I have). It's just the phrase "you shouldn't hack core" that rings in my ear. I would like us to avoid forcing this situation upon unsuspecting folk.
Comment #19
Crell commentedsime:
To point one, it's no different than we have now. Many many production servers are set to not display errors or warnings at all. If you're developing on one of those, then you could miss a warning (say, doing foreach() on a string instead of an array) and upload broken code now. You'll still be blissfully unaware that you have problems, but once it gets into CVS, things break. Developing under E_ALL has been part of standard good PHP development practices since, um, I think there's been an E_ALL, and the equivalent "treat warnings as errors" switch for gcc has been recommended good practice for as long as I remember.
To point two, again, it's no different than now. A module author could disable errors completely just by putting
error_reporting(E_NONE)as the first line of a function in his module. I don't know of any that do so. Were they to do so now or do so with an E_ALL default, in either case it's a very stupid thing to do. :-)Really, I see this as parallel to requiring that the HTML that core generates be XHTML Strict compliant and, where possible, semantically clean. It sets a high standard of correctness that helps ensure core is as widely-compatible and forward-compatible as possible. Module authors are encouraged to follow suit, or sometimes things don't work right when theming. Our PHP code should be held to no less of a standard.
Hacking core should NOT be necessary to use some modules just because we set to E_ALL. If a module requires core to be hacked to change the error reporting level, then that's a bug that should be filed against the module, just as much as a module that generates badly formed HTML should be treated as buggy and fixed.
Dries, Steven, can we please get some commentary from you here?
Comment #20
dries commentedCommitted to CVS HEAD. Thanks.
Comment #21
(not verified) commented