Posted by webchick on November 9, 2008 at 12:37am
We should figure out and document a standard for this, then roll a patch to make it consistent.
Please see: http://drupal.org/node/331951
We should figure out and document a standard for this, then roll a patch to make it consistent.
Please see: http://drupal.org/node/331951
Comments
-1 for yet another space
If we continue to add spaces (string concatenation rules), coding for Drupal will become whitespace-nightmare, IMHO.
By tying the cast to the variable, casts are identified quicker.
<?php$value = t('This is just an @example.', array('@example' => (string)$weird_variable);
$value = (array)$value;
$value = create_awesomeness((array)$value, (int)$string);
?>
Compare this to:
<?php$value = t('This is just an @example.', array('@example' => (string) $weird_variable);
$value = (array) $value;
$value = create_awesomeness((array) $value, (int) $string);
?>
Visually, it's much more clear what exactly happens in all cases without the space.
Daniel F. Kudwien
unleashed mind
Daniel F. Kudwien
netzstrategen
Agreed on this -1
I would not compare casting variable with any other syntax construction with an already defined conding standard pattern.
I'm used to it, to not include any addicional space between the type and the variable, as if it was something close to the meaning of the variable itself.
Anyway, I would be fine with anything that's decided best for Drupal coding standards.
I prefer it with the space -
I prefer it with the space - I find it a lot more readable and it's easier on the eye. For me it matches other non-functions like
foreach ($foo as $bar)return $foo;With the space, because that's what the docs state
The PHP docs on casting variables appears to almost always use a space (I could only find one instance, for binaries, where no space was used). As such, that's what PHP coders will expect to see and do; thus, the space should be per the official PHP documentation. One can't suggest that Drupal is a "whitespace nightmare" when all it does is follow the existing official inference.
A previous poster's argument of "tying the cast to the variable" doesn't hold a lot of water for me, logically - I could almost imagine their rationale enforcing a "foreach($array as $item)" equivalent to more closely tie the foreach to the thing it iterates over. Note, though, that I actually DO prefer the typecasting right up against the variable, but I defer to official sources, not my personal inclinations. My personal rationale is, roughly, that a typecast operates just like a function - you "pass" it something, and it "returns" something (often, something "else"). We don't use function arguments like
$a = drupal_strtolower( $b ), so we shouldn't use typecasting "arguments" like that either.Morbus's argument is pretty compelling...
If no one else can do better, I think we can call it a standard with the space.