note 63236 added to function.func-num-args

From: Date: Thu, 16 Mar 2006 19:24:03 +0000
Subject: note 63236 added to function.func-num-args
Groups: php.notes 
Request: Send a blank email to php-notes+get-105942@lists.php.net to get a copy of this message
This function comes in extremely handy in OO Classes. My focus is currently PHP 4, but this technique probably works just as well in PHP 5. Class foo { // constructor, other methods, etc function somedata($somedata = '') { if (func_num_args() > 0) { $this->somedata = $somedata; } return $this->somedata; } } This allows for a default value to be set, while not requiring the parameter. (Yes, I'm aware that it only warns when you do, but I think this is a little cleaner) ---- Server IP: 64.71.164.2 Probable Submitter: 205.238.253.151 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.func-num-args.php Edit -- http://master.php.net/note/edit/63236 Del: integrated -- http://master.php.net/note/delete/63236/integrated Del: useless -- http://master.php.net/note/delete/63236/useless Del: bad code -- http://master.php.net/note/delete/63236/bad+code Del: spam -- http://master.php.net/note/delete/63236/spam Del: non-english -- http://master.php.net/note/delete/63236/non-english Del: in docs -- http://master.php.net/note/delete/63236/in+docs Del: other reasons-- http://master.php.net/note/delete/63236 Reject -- http://master.php.net/note/reject/63236 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105942) next »