Closed (won't fix)
Project:
Coder
Version:
6.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Jun 2008 at 16:16 UTC
Updated:
6 Sep 2012 at 03:18 UTC
Is there any way that Coder can catch things like the missing quotes in drupal_get_form(mymodule_settings_page)? Yes, I know it was a stupid mistake. I thought we had visited this issue once upon a time.
Comments
Comment #1
douggreen commentedThis could actually be a valid line if you had a
define()for mymodule_settings_page. I think that the discussion we had once upon a time was about the strings (and defines) as it related to some other rule. However, it is a standard for defines to be upper case. So in this case, I think we could catch it with a rule that looks for'regex' => 'drupal_get_form\([a-z_]+\s*[,\)]', 'not' => 'drupal_get_form\([a-z]+\s*\(',... regex's are untested.Comment #2
dman commentedWell, the general case problem is for ALL function calls or unquoted strings anywhere unexpected to raise warnings, I don't see what's special about drupal_get_form. So that means paranoia everywhere.
So this becomes a PHP parsing thing. I guess log level notice may show some of that.
Or, what I do is use a proper IDE that does syntax highlighting and helps locate issues like that. I use Eclipse which subtly indicates when I'm using an undefined constant or variable.
Comment #3
nancydruI think dman is right, there is nothing special about drupal_get_form. That just happens to be where I messed up this time. It may or may not have been logged; I didn't look (so spank me). My syntax highlighting was also insufficient for me to catch it.
Comment #4
douggreen commented@dman, good point, as it sounds like the consensus is that this is a pretty special case, I'm marking as "won't fix."
Comment #5
nancydruPardon me for re-opening this, but I believe the issue is not the drupal_get_form, but unquoted strings. That problem does need to be fixed. I thought it was, once upon a time.
Comment #6
dman commentedUnquoted stings are legal in PHP. Although they just get cast to literal strings ... which is almost never what you want.
But constants for example are fine.
I think that the coder module is going to have a hard time telling the difference between
Or do you think it's possible to come up with an expression that can detect unexpected unquoted stings - that are NOT function names, constants, variables or PHP keywords - better than the PHP parser itself can?
... etc. Yikes.
:-(
It's really a PHP syntax tokenizer job. I think the parser does raise notices if the volume is turned right up.
Comment #7
nancydruHere's the previous issue: http://drupal.org/node/180226. While it was about array references and performance, someone pointed out that while PHP allows unquoted strings, it also considers them "wrong." I haven't done any kind of benchmark on this like I did on the other issue, but it is still wrong, and undoubtedly quite slow due to error handling.
Comment #8
douggreen commented@dman, if we wanted to work with this, I think that we could rely on the standard that defined constants are UPPERCASE.
@NancyDru, But I think that the number of use-cases to check will be very hard to do.
Comment #9
dman commented@dougreen, yes, if nothing else, non-upper constants are bad drupal-style anyway, and already raise warnings.
That previous thread makes sense, as using unquoted array keys is a known (although discouraged) practice.
Also it would have still worked as expected, and does come down to a style and best-practice choice. Including efficiency of course.
Unquoted strings as in the OP example are much more rare ... in many languages anyway, and are more probably just code mistakes than stylistic choice.
In that discussion many of my misgivings are also addressed.
However, there's a difference in code style (discouraging a deprecated practice) and actual syntax checking broken code.
I also think that the regexp patterns needed to assure no false positives (if even possible) would be horrible. :-/
If someone want to demo a proof-of-concept for the general case, good luck, but it scares me.
Comment #10
nancydruI absolutely accept that my case was just my being brain-dead at the time I typed that code.
Drupal's coding standards are as much, if not more, about coding style rather than broken code, so I don't see this as totally outside Coder's purview. However, I understand if the checking is too difficult. At least the issue is understood.
Comment #11
AlexisWilke commentedNote that having Coder find those errors is great, using E_NOTICE on your development system helps too... That is, if you at least once, run that line of code...
So I don't think it is too important that Coder successfully checks those. Instead, make sure to add to your documentation something about the E_NOTICE probably not being turned ON by default. And maybe a few other things such as the Core function that catch errors must be changed to show all the E_NOTICE errors too!
For more info, I strongly advise that you look into this one:
#761780: Plenty of E_ALL notices in modules developed on installation with Drupal tarball
And it is difficult to use E_NOTICE when you have tons and tons of modules because half of them will generate ("legal") notices!
Thank you.
Alexis
Comment #12
douggreen commentedClosing old issue seems to have lost interest, these problems seem to be caught in other ways ???