more and more minor :

$obj = new StdClass();

triggers "do not use mixed case (camelCase), use lower case and _"

CommentFileSizeAuthor
#10 coder-stdClass.diff725 byteswebchick

Comments

douggreen’s picture

Looking at code-style.pl again, it looks like I misinterpreted the rule (I previously read the error message and didn't really look at the regex). Is SomethingCapitalized OK, but somethingCapital not?

elsif (/([a-z])([A-Z])/) {
    $msg = "no mixed case function or variable names, use lower case and _";
  }
yched’s picture

I think SomethingCapitalized is not OK either. It's probably more "StdClass" being an exception, since it's a PHP-defined keyword.

douggreen’s picture

then shouldn't the Drupal coding standard be 'new stdclass();' - all lower case. I don't think php cares... I just tested on a php4 and php5 systems.

yched’s picture

Well, StdClass is PHP default syntax.
Even if typing stdclass instead happens to work, I'm not sure we can recommend coders to twist regular PHP syntax because it fits Drupal coding style better...

The best thing IMO probably be to set the string "StdClass" as a valid exception to the camelCase rule, I don't think there will be much others.

douggreen’s picture

Ok, I'll add an exception. I've seen it on php.net as stdClass and StdClass. stdClass seems to be the standard. Do you think we should ignore both?

yched’s picture

i was not aware of the "stdClass" form, but drupal core 5 currently contains both.
So I guess yes, we should accept both...

douggreen’s picture

Should be fixed in the latest version!

Thanks!

webchick’s picture

Actually, probably better to pick one (you said stdClass is the most common on php.net?), update the coding standards accordingly, update the script so it only checks for that one, and submit patches to fix the inconsistencies.

That might be out of scope of this module though. ;)

webchick’s picture

Ok, between the facts that:

  1. php.net calls it stdClass
  2. There are more instances of stdClass than StdClass in core (by like one :P)
  3. JavaScript is the closest model we have in Drupal, and it uses studlyCaps.

With Steven's ok, I've updated the coding standards to use "studlyCaps" on class names, and will roll a patch shortly. So if you could change it to only ok "stdClass" that would be cool. :)

webchick’s picture

Status: Active » Needs review
StatusFileSize
new725 bytes

Core patch committed: http://drupal.org/node/107015

Here's a patch for coder module to make it only exclude stdClass.

douggreen’s picture

Assigned: Unassigned » douggreen
Status: Needs review » Fixed

Thanks yched and webchick. I've checked in something that will flag StdClass, but not stdClass. I simplified the regex because we don't need to compare words that start as caps.

douggreen’s picture

Status: Fixed » Closed (fixed)
phung_uit’s picture

Issue summary: View changes