d-_-b
d-_-b

Reputation: 6773

PHP: white space between function name and parenthesis

I'm wondering if this is legal:

<?php

is_null
(
    $var
);

Or perhaps this:

<?php
$items = array
(
    "Details" => array('controller' => 'event', 'action' => 'readall', 'tab' => 'details'),
    "Calendar" => array('controller' => 'event', 'action' => 'readall', 'tab' => 'calendar')
);

Or will some interpreters choke?

I know the popular mixed style of classes and functions have the opening curly brace on a new line and control structures, such as "if", on the same line. However, I like all one or the other. Newline or no newline. It would be nice to extend the concept to function calls and their parenthesis as well. This is the reason for my question.

Upvotes: 6

Views: 3027

Answers (3)

GolezTrol
GolezTrol

Reputation: 116200

That is very legal. And there aren't many interpreters after all. :) I put parentheses on the next line too if I got a large amount of parameters or a large array declaration.

Upvotes: 2

user70568
user70568

Reputation:

It's legal. the interpreter should just ignore any white space it finds.

Upvotes: 2

Dan Grossman
Dan Grossman

Reputation: 52372

Whitespace doesn't matter. The only time I'm aware that the interpreter cares about whitespace is when exiting HEREDOC syntax. Other than that, you can have as many spaces or newlines as you want.

Upvotes: 1

Related Questions