I think we should change the "Function Declarations" in the Coding standards page, so it advises people to use type hinting, when declaring functions that have arrays as arguments.

See more on: http://drupal.org/node/318016

The text could say:

"When the function takes an array as an argument, use type hinting."

And as an example we could use

function my_func(array $foo, $bar) {

}

Comments

jbrown’s picture

Title:Revise the section about "Function Declarations" in the Conding standards page.» Add type hinting to function declaration coding standards
arianek’s picture

Issue tags:-Type Hinting+developer

tags

jhodgdon’s picture

Project:Documentation» Drupal core
Version:» 8.x-dev
Component:Correction/Clarification» documentation
Assigned:johsw» Unassigned
Issue tags:-developer+coding standards

Normally we discuss coding standards in the Drupal Core issue queue, so moving there.

YesCT’s picture

I was looking around the coding standards and also doc standards, and could not find a reference to type hinting. But I thought we did type hinting except for strings.

YesCT’s picture

from conversation with @chx in irc:

We do not type hint primitive types. you can't scalar hint with php
We always hint if we can -- arrays and objects.
But if it can be NULL, we do not type hint because php is ... wont let us.

I've found adding type hints to patches sometimes exposes where the comments in the doc block @param was wrong. That sometimes it whatever or NULL, or it's mixed type, etc.

So type hinting seems to be a good thing.

jhodgdon’s picture

Title:Add type hinting to function declaration coding standards» [policy] Add type hinting to function declaration coding standards

we've been making titles like this for coding standards issues...

jhodgdon’s picture

Project:Drupal core» Drupal Technical Working Group
Version:8.0.x-dev»
Component:documentation» Documentation
Issue summary:View changes

Coding standards decisions are now supposed to be made by the TWG