note 57141 added to functions.arguments

From: Date: Sun, 25 Sep 2005 05:55:17 +0000
Subject: note 57141 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-95735@lists.php.net to get a copy of this message
Given that we have two coding styles: # # Code (A) # funtion foo_a (&$var) { $var *= 2; return $var; } foo_a($a); # # Code (B) # function foo_b ($var) { $var *= 2; return $var; } foo_b(&$a); I personally wouldn't recommend (B) - I think it strange why php would support such a convention as it would have violated foo_b's design - its use would not do justice to its function prototype. And thinking about such use, I might have to think about copying all variables instead of working directly on them... Coding that respects function prototypes strictly would, I believe, result in code that is more intuitive to read. Of course, in php <=4, not being able to use default values with references, we can't do this that we can do in C: # # optional return-value parameters # int foo_c (int var, int *ret) { var *= 2; if (ret) *ret = var; return var; } foo_c(2, NULL); Of course, since variables are "free" anyway, we can always get away with it by using dummy variables... zlel ---- Manual Page -- http://www.php.net/manual/en/functions.arguments.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57141 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57141&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57141&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95735) next »