count() and sizeof() are synonymous in functionality, the latter being an alias of the former. In Drupal's code base count() is used 631 times and sizeof() only 10 times. For consistency I propose we kill of those ten and then update the coding standards to discourage using sizeof().

Including a patch to fix the ten sizeof() uses.

Comments

mikeryan’s picture

Status: Active » Needs review
kscheirer’s picture

Status: Needs review » Needs work

The last submitted patch, drupal-consistently-use-count-instead-of-sizeof-alias.patch, failed testing.

dcam’s picture

Status: Needs work » Needs review
StatusFileSize
new8.24 KB

I rerolled the patch in the OP and added a few more changes where sizeof() was used in Symfony and Doctrine tests.

droplet’s picture

Status: Needs review » Needs work

- code style problem
- don't hack 3rd part (eg. vendor)

dcam’s picture

Status: Needs work » Needs review
StatusFileSize
new4.12 KB

Yeah, I noticed the code style problems too. I didn't know if patches should be kept on task and separate issues should be opened for formatting or if those problems should be fixed where they're found. The whole file, core/lib/Drupal/Component/Archiver/ArchiveTar.php, is riddled with style errors.

As for the 3rd party code changes, I knew better. I don't know why I second-guessed myself.

droplet’s picture

ArchiveTar is a modified 3rd party script. #1414508: update system.tar.inc to latest Archive_Tar (Pear)

dcam’s picture

In that case should it also be excluded?

longwave’s picture

Status: Needs review » Needs work

Correct, we should not change ArchiveTar.php as part of this issue.

ryan.ryan’s picture

Patch applied cleanly, replacements were made in 8 locations. Looks good.

dcam’s picture

Status: Needs work » Needs review
StatusFileSize
new2.21 KB

Removed ArchiveTar.php changes.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed these are the only three lines in modules/ using sizeof, and we should not change any others.

tobiassjosten’s picture

Good that you amended the patch (RTBC indeed). But I don't see the urgency that you wouldn't allow me to finish what I started?

dries’s picture

Priority: Normal » Minor
Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.